Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #**************************************************************************
- # IMPORTS
- #**************************************************************************
- import pygame
- from pygame.locals import *
- import os
- import sys
- import math
- from math import sqrt
- import time
- import random
- from random import randint
- #**************************************************************************
- # COLORS
- #**************************************************************************
- """
- FIREBRICK = (178, 34, 34)
- SEASHELL = (255, 245, 238)
- ROYAL_BLUE = (65, 105, 225)
- WHITE_SMOKE = (245, 245, 245)
- WHITE = (255, 255, 255)
- PURPLE = (186, 85, 211)
- PAPAYA_WHIP = (255, 239, 213)
- BISQUE_2 = (238, 213, 183)
- BISQUE_3 = (205, 183, 158)
- BISQUE_4 = (139, 125, 107)
- HONEY_DEW = (131, 139, 131)
- """
- BLACK = (0, 0, 0)
- DIM_GRAY = (105, 105, 105)
- DEEP_RED = (165, 42, 42)
- DARK_ORANGE = (255, 140, 0)
- LIME_GREEN = (50, 205, 50)
- #*************************************************************************
- # SYSTEM SETTINGS
- #*************************************************************************
- pygame.init()
- #Screen Dimensions
- SCREEN_WIDTH = 800
- SCREEN_HEIGHT = 500
- PLAYABLE_SCREEN_WIDTH = SCREEN_WIDTH - 100
- PLAYABLE_SCREEN_HEIGHT = SCREEN_HEIGHT - 100
- screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
- #background_image = 'res' + os.sep + 'images' + os.sep + 'bg-level-1-1-1.jpg'
- #pygame.image.load(os.path.join("res","images","bg-level-1-1-1.jpg")).convert()
- #bg = pygame.image.load("bg-level-1-1-1.jpg").convert()
- #screen.blit(pygame.Surface, [0, 0])
- clock = pygame.time.Clock()
- Score = 0
- font_hero_name = pygame.font.SysFont("monospace", 15)
- """
- **************************************************************************
- SPRITE GROUPS
- **************************************************************************
- """
- heroes_list = pygame.sprite.Group()
- enemy_list = pygame.sprite.Group()
- near_hero_list = pygame.sprite.Group()
- all_sprites_list = pygame.sprite.Group()
- """
- **************************************************************************
- CREATING THE HERO CLASS
- Values: NAME, SPEED, LEVEL, HP, STAMINA, FEAR
- Format: player = Hero(str, int, int, int, int, int)
- Example:
- heroBoonrit = Hero("Boonrit", 30, 1, 10000, 50, 20)
- **************************************************************************
- """
- class Hero(pygame.sprite.Sprite):
- def __init__(self, name, level, speed, hp, stamina, fear, blocking, jumping_cooldown, attacking_cooldown, held_cooldown, knockdown_cooldown, stun_cooldown, jumping_countdown, attacking_countdown, held_countdown, knockdown_countdown, stun_countdown, grabbed_cooldown, grabbed_countdown):
- super().__init__()
- self.image = pygame.Surface([30,20])
- #self.image.fill(color)
- self.rect = self.image.get_rect()
- self.surf = pygame.Surface((30,20))
- self.name = name
- self.speed = speed
- self.level = level
- self.hp = hp
- self.stamina = stamina
- self.fear = fear
- self.blocking = blocking
- self.jumping_cooldown = jumping_cooldown
- self.jumping_countdown = jumping_countdown
- self.attacking_cooldown = attacking_cooldown
- self.attacking_countdown = attacking_countdown
- self.held_cooldown = held_cooldown
- self.held_countdown = held_countdown
- self.knockdown_cooldown = knockdown_cooldown
- self.knockdown_countdown = knockdown_countdown
- self.stun_cooldown = stun_cooldown
- self.stun_countdown = stun_countdown
- blocking = False
- jumping_cooldown = False
- jumping_coutndown = 0
- attacking_cooldown = False
- attacking_countdown = 0
- held_cooldown = False
- held_countdown = 0
- knockdown_cooldown = False
- knockdown_countdown = 0
- stun_cooldown = False
- stun_countdown = 0
- def update(self, pressed_keys):
- if self.jumping_cooldown == True:
- if self.jumping_countdown <= 0:
- self.jumping_cooldown == False
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-3.png'))
- elif self.jumping_countdown <= 20:
- self.rect.y += 3
- else:
- self.rect.y -= 3
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-2.png'))
- if self.attacking_cooldown == True:
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-attack-1.png'))
- self.attacking_countdown -= 1
- if self.attacking_countdown <= 0:
- self.attacking_countdown = 0
- self.attacking_cooldown = False
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-3.png'))
- if self.stun_cooldown == True:
- self.stun_countdown -= 1
- if self.held_cooldown == True:
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-held-stun.png'))
- elif self.jumping_cooldown == True:
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-jumping-stun.png'))
- elif self.knockdown_cooldown == True:
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-knockdown-stun.png'))
- else:
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-stun.png'))
- if self.stun_countdown < 0:
- self.stun_countdown = 0
- self.stun_cooldown = False
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-3.png'))
- if self.held_cooldown == True:
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-held.png'))
- self.held_countdown -= 1
- if self.held_countdown <= 0:
- self.held_countdown = 0
- self.held_cooldown == False
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-3.png'))
- if self.blocking == True:
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-block.png'))
- # Jumping
- #self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-jump.png'))
- # If hero isn't blocking, attacking or being stunned, then s(he) is able to move
- if self.blocking == False and self.attacking_cooldown == False and self.stun_cooldown == False and self.held_cooldown == False:
- if pressed_keys[K_LEFT]:
- self.rect.move_ip(-heroBoonrit.speed, 0)
- if pressed_keys[K_RIGHT]:
- self.rect.move_ip(heroBoonrit.speed, 0)
- if pressed_keys[K_UP]:
- self.rect.move_ip(0, -heroBoonrit.speed)
- if pressed_keys[K_DOWN]:
- self.rect.move_ip(0, heroBoonrit.speed)
- if pressed_keys[K_d]:
- self.attacking_cooldown = True
- self.attacking_countdown = 20
- if pressed_keys[K_s]:
- self.jumping_cooldown = True
- self.jumping_countdown = 40
- if pressed_keys[K_a]:
- self.blocking = True
- # Stop the player from moving too far off the screen
- # Health
- if self.hp <= 0:
- self.kill()
- elif self.hp <= 20:
- #self.image.fill(DEEP_RED)
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-1.png'))
- elif self.hp <= 60:
- #self.image.fill(DARK_ORANGE)
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-2.png'))
- elif self.hp <= 90:
- #self.image.fill(LIME_GREEN)
- self.image = pygame.image.load(os.path.join('res','img','chars','boonrit-3.png'))
- else:
- pass
- # Active character
- ac = ["Boonrit", "Hugo", "Joy", "Victoria", "Kelly"]
- """
- **************************************************************************
- CREATING THE ENEMY
- Values: COLOR, SPEED, LEVEL, HP, STAMINA, FEAR
- Format: Shit_Clown = Enemy(str, int, int, int, int, int)
- Example:
- Shit_Clown = Enemy("Shit Clown",30,1,10000,50,20)
- **************************************************************************
- """
- class Enemy(pygame.sprite.Sprite):
- def __init__(self, name, level, speed, hp, stamina, fear, blocking_cooldown, jumping_cooldown, attacking_cooldown, held_cooldown, knockdown_cooldown, stun_cooldown, jumping_countdown, attacking_countdown, held_countdown, knockdown_countdown, stun_countdown, grabbing_cooldown, grabbing_countdown, blocking_countdown):
- super().__init__()
- self.image = pygame.image.load(os.path.join('res','img','chars','shit_clown-3.png'))
- #self.image = pygame.Surface([30,20])
- #self.image.fill(color)
- self.rect = self.image.get_rect()
- self.surf = pygame.Surface((30,20))
- self.name = name
- self.speed = speed
- self.level = level
- self.hp = hp
- self.stamina = stamina
- self.fear = fear
- self.blocking_cooldown = blocking_cooldown
- self.jumping_cooldown = jumping_cooldown
- self.jumping_countdown = jumping_countdown
- self.attacking_cooldown = attacking_cooldown
- self.attacking_countdown = attacking_countdown
- self.held_cooldown = held_cooldown
- self.held_countdown = held_countdown
- self.knockdown_cooldown = knockdown_cooldown
- self.knockdown_countdown = knockdown_countdown
- self.stun_cooldown = stun_cooldown
- self.stun_countdown = stun_countdown
- self.grabbing_cooldown = grabbing_cooldown
- self.grabbing_countdown = grabbing_countdown
- self.blocking_countdown = blocking_countdown
- blocking_cooldown = False
- jumping_cooldown = False
- jumping_coutndown = 0
- attacking_cooldown = False
- attacking_countdown = 0
- held_cooldown = False
- held_countdown = 0
- knockdown_cooldown = False
- knockdown_countdown = 0
- stun_cooldown = False
- stun_countdown = 0
- grabbing_cooldown = False
- grabbing_countdown = 0
- blocking_countdown = 0
- def update(self):
- #if blocking_cooldown == False and held_cooldown == False and knockdown_cooldown == False and stun_cooldown == False and grabbing_cooldown == False:
- # Flip the coin.
- #coin_flip = random.randrange(1,4)
- #if coin_flip == 1:
- #timer -= 1
- #self.rect.move_ip(0, 0)
- #if timer <= 0
- #elif coinFlip == 2:
- #self.rect.move_ip(-1, 0)
- #else:
- #self.rect.move_ip(1, 0)
- #if self.attacking_cooldown == True:
- #self.attacking_countdown -= 1
- #if self.attacking_countdown <= 0:
- #self.attacking_countdown = 0
- #self.attacking_cooldown = False
- if self.hp <= 0:
- self.kill()
- elif self.hp <= 20:
- self.image.fill(DEEP_RED)
- elif self.hp <= 60:
- self.image.fill(DARK_ORANGE)
- elif self.hp <= 90:
- self.image.fill(LIME_GREEN)
- else:
- pass
- # stateIDLE will be the behaviour of the enemy when they are not aware of the hero.
- def stateIDLE():
- pass
- # stateIDLE will be the behaviour of the enemy when they are aware of the hero.
- def stateAWARE():
- pass
- # stateIDLE will be the behaviour of the enemy when they are aggressive.
- def stateAGGRESSIVE():
- pass
- # stateIDLE will be the behaviour of the enemy when they fleeing from the hero.
- def stateFLEE():
- pass
- """
- **************************************************************************
- SPAWNING THE HERO
- Outdate Values: name, speed, level, hp, stamina, fear, blocking, jumping_cooldown, attacking_cooldown, held_cooldown, knockdown_cooldown, jumping_countdown, attacking_countdown, held_countdown, knockdown_countdown
- **************************************************************************
- """
- # Boonrit, Male, Thailand
- heroBoonrit = Hero("Boonrit",1,3,10000,50,20,False,False,False,False,False,False,False,0,0,0,0,0,0)
- #Name
- #Level
- #Speed
- #HP
- #Stamina
- #Fear
- #Blocking
- #Jumping Cooldown
- #Attacking Cooldown
- #Held Cooldown
- #Knockdown Cooldown
- #Stun Cooldown
- #Grabbed Cooldown
- #Jumping Countdown
- #Attacking Countdown
- #Held Countdown
- #Knockdown Countdown
- #Stun Countdown
- #Grabbed Countdown
- heroBoonrit.image = pygame.image.load(os.path.join('res','img','chars','boonrit-3.png')).convert()
- heroBoonrit.rect.x = 400
- heroBoonrit.rect.y = 400
- heroes_list.add(heroBoonrit)
- all_sprites_list.add(heroBoonrit)
- """
- **************************************************************************
- SPAWNING ENEMIES
- Values: name, level, speed, hp, stamina, fear, blocking_cooldown, jumping_cooldown, attacking_cooldown, held_cooldown, knockdown_cooldown, stun_cooldown, jumping_countdown, attacking_countdown, held_countdown, knockdown_countdown, stun_countdown, grabbing_cooldown, grabbing_countdown, blocking_countdown
- **************************************************************************
- """
- # Spawn 3 Shit Clowns
- #def __init__(self, name, level, speed, hp, stamina, fear, blocking_cooldown, jumping_cooldown, attacking_cooldown, held_cooldown, knockdown_cooldown, stun_cooldown, jumping_countdown, attacking_countdown, held_countdown, knockdown_countdown, stun_countdown, grabbing_cooldown, grabbing_countdown, blocking_countdown):
- for i in range(1):
- enemyShit_Clown = Enemy("Shit Clown", 1, 4, 1000, 10, 90, False, False, False, False, False, False, 0, 0, 0, 0, 0, True, 60, 0)
- enemyShit_Clown.image = pygame.image.load(os.path.join('res','img','chars','shit_clown-3.png')).convert()
- enemyShit_Clown.rect.x = 300 #random.randrange(300, 400)
- enemyShit_Clown.rect.y = 300 #random.randrange(200, 400)
- enemy_list.add(enemyShit_Clown)
- all_sprites_list.add(enemyShit_Clown)
- # Spawn 2 Jack Scrappers
- for i in range(0):
- enemyJack_Scrapper = Enemy("Jack Scrapper "+str(i), 1, 4, 2000, 15, 85, False, False, False, False, False, False, 0, 0, 0, 0, 0, 0, 0)
- enemyJack_Scrapper.image = pygame.image.load(os.path.join('res','img','chars','jack_scrapper-3.png')).convert()
- enemyJack_Scrapper.rect.x = 100 #random.randrange(600, 700)
- enemyJack_Scrapper.rect.y = 100 #random.randrange(200, 400)
- enemy_list.add(enemyJack_Scrapper)
- all_sprites_list.add(enemyJack_Scrapper)
- """
- **************************************************************************
- MAIN GAME LOOP
- **************************************************************************
- """
- #screen.blit(heroBoonrit.surf, (30,20))
- running = True
- while running:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- screen.fill(BLACK)
- pygame.draw.rect(screen, DIM_GRAY, (100, 20, 250, 30))
- pygame.draw.rect(screen, DIM_GRAY, (100, 55, 250, 5))
- #pygame.font.Font.render("Boonrit")
- pressed_keys = pygame.key.get_pressed()
- heroBoonrit.update(pressed_keys)
- enemy_list.update()
- near_hero_list.update()
- contact = pygame.sprite.spritecollide(heroBoonrit, enemy_list, False)
- for villan in contact:
- for villan in enemy_list:
- if villan.grabbing_cooldown:
- heroBoonrit.held_cooldown = True
- heroBoonrit.rect.y = villan.rect.y
- heroBoonrit.rect.x = (villan.rect.x + 30)
- heroBoonrit.held_countdown = villan.grabbing_countdown
- villan.grabbing_countdown -= 1
- heroBoonrit.held_countdown -= 1
- if villan.grabbing_countdown <= 0:
- villan.grabbing_countdown = 0
- heroBoonrit.held_countdown = 0
- villan.grabbing_cooldown = False
- heroBoonrit.held_cooldown = False
- heroBoonrit.rect.x += 30
- elif villan.attacking_cooldown:
- if heroBoonrit.blocking != True:
- heroBoonrit.hp -= 100
- else:
- heroBoonrit.hp -= 10
- if heroBoonrit.attacking_cooldown:
- for villan in enemy_list:
- for villan in contact:
- if villan.blocking_cooldown != True:
- villan.hp -= 100
- else:
- villan.hp -= 10
- #for villan in enemy_list:
- #if (abs(villan.rect.x) - abs(heroBoonrit.rect.x) <= 10) and (abs(villan.rect.y) - abs(heroBoonrit.rect.y) <= 10):
- #near_hero_list.add(villan)
- #if (abs(villan.rect.x) - abs(heroBoonrit.rect.x) > 100) and (abs(villan.rect.y) - abs(heroBoonrit.rect.y) > 10):
- #near_hero_list.remove(villan)
- #if math.sqrt(((villan.rect.x - heroBoonrit.rect.x) **2) + ((villan.rect.x - heroBoonrit.rect.x) **2)) <= 10 and math.sqrt(((villan.rect.y - heroBoonrit.rect.y) **2) + ((villan.rect.y - heroBoonrit.rect.y) **2)) <= 100:
- #near_hero_list.add(villan)
- #if math.sqrt(((villan.rect.x - heroBoonrit.rect.x) **2) + ((villan.rect.x - heroBoonrit.rect.x) **2)) > 10 and math.sqrt(((villan.rect.y - heroBoonrit.rect.y) **2) + ((villan.rect.y - heroBoonrit.rect.y) **2)) > 100:
- #near_hero_list.add(villan)
- #contact = pygame.sprite.spritecollide(heroBoonrit, enemy_list, False)
- #if heroBoonrit.attacking_cooldown:
- #for villan in contact:
- #if villan.blocking != True:
- #villan.hp -= 100
- #else:
- #villan.hp -= 10
- #screen.blit(bg, (0, 0))
- all_sprites_list.draw(screen)
- pygame.display.flip()
- clock.tick(60)
- #*************************************************************************
- # DIAGNOSTICS
- #*************************************************************************
- #print("|Boonrit HP| ", heroBoonrit.hp)
- print("||Shit Clown|| Grabbing = ", enemyShit_Clown.grabbing_cooldown, " Countdown = ", enemyShit_Clown.grabbing_countdown, "||Boonrit|| Grabbed = ", heroBoonrit.held_cooldown, " Countdown = ", heroBoonrit.held_countdown)
- #print("|Clown HP| ", enemyShit_Clown.hp, "|Boonrit HP| ", heroBoonrit.hp, enemyShit_Clown.grabbing_cooldown, heroBoonrit.held_cooldown)
- #print(" |Score| ", Score)
- #print(" |J| ", heroBoonrit.jumping_cooldown)
- #print(" |A| ", heroBoonrit.attacking_cooldown)
- #print(heroBoonrit.attacking_countdown)
- #print(" |H| " , heroBoonrit.held_cooldown)
- #print(" |K| ", heroBoonrit.knockdown_cooldown)
- #print(" |S| ", heroBoonrit.stun_cooldown)
- #print("|Clown HP| ", enemyShit_Clown.hp)
- #print(enemyShit_Clown.image.get_rect())
- #print(enemyShit_Clown.rect)
- #print(heroBoonrit.rect)
- #print(contact)
- #print(enemy_list)
- #print(all_sprites_list)
- #print(heroes_list)
- #for i in enemy_list:
- # print(i.name, "Grabbing: ", i.grabbing_cooldown)
- #for i in near_hero_list:
- # print(i.name, "Grabbing: ", i.grabbing_cooldown)
- #for i in enemy_list:
- #print("|Delta X| ", (abs(villan.rect.x) - abs(heroBoonrit.rect.x) <= 100), "|Delta Y| ", (abs(villan.rect.y) - abs(heroBoonrit.rect.y) <= 10))
- #for i in near_hero_list:
- #print(i.name)
- #print(heroBoonrit.image.get_rect())
- pygame.QUIT
- """
- #See if the player has collided with anything
- #enemy_hit_list = pygame.sprite.spritecollide(player, enemy_list, True)
- #for enemy in enemy_hit_list:
- # player.hp -= 10
- # print(player.hp)
- # #Stun the player
- # player_stun = 3
- # pygame.mixer.Sound('res\audio\oof.wav').play()
- # while player_stun > 0:
- # player_stun -= 1
- # pygame.time.delay(300)
- """
Advertisement
Add Comment
Please, Sign In to add comment