import pygame from pygame import mixer import math import random import time import sys mixer.init() pygame.init() SCREEN_WIDTH = 800 SCREEN_HEIGHT = 640 screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) pygame.display.set_caption('giggity goo') RED = (255, 0, 0) GREEN = (144, 201, 120) IDK = (176, 198, 207) clock = pygame.time.Clock() FPS = 80 PPOS = 0 bullet = pygame.image.load('bublet.png') PD = 0 BPOS = 0 MPOS = 0 PLAYERALIVE = True #all of the variables pygame.mixer.music.load('boss.ogg') pygame.mixer.music.set_volume(0.3) boss_fx = pygame.mixer.Sound('boss.ogg') boss_fx.set_volume(0.5) font = pygame.font.SysFont("arialblack", 40) TEXT_COL = (255, 255, 255) Phealth = 125 moving_left = False moving_right = False moving_up = False moving_down = False dash = False rect_width = Phealth rect_height = 60 rect_x = 550 rect_y = 75 damage = False start = False lvl1 = False lvl2 = False lvl3 = False invent = False b = (1, 1) atk = 0 melee = True gun = False attack_left = False attack_right = False BLACK = (0, 0, 0) shoot_left = False shoot_right = False #menus def draw_text(text, font, text_col, x, y): img = font.render(text, True, text_col) screen.fill(IDK) screen.blit(img,(x, y)) #inventory sprite def inven(): img = pygame.image.load('ver 1/imgs/inventory/stuff/0.png') img = pygame.transform.scale(img,(800, 640)) if invent == True: screen.blit(img, b) #not likely to be used def boundery(): pygame.draw.line(screen, RED, (300, 200), (500, 200)) pygame.draw.line(screen, RED, (300, 400), (500, 400)) pygame.draw.line(screen, RED, (300, 400), (300, 200)) pygame.draw.line(screen, RED, (500, 200), (500, 400)) #fill the screen def draw_bg(): screen.fill(GREEN) #get the health bar def hbar(): rect = pygame.draw.rect(screen, RED,(rect_y, rect_x, rect_width, rect_height)) #the code for the player(the size, the image, moving, displaying and all that) class Player(pygame.sprite.Sprite): def __init__(self,char_type, x, y): pygame.sprite.Sprite.__init__(self) self.char_type = char_type self.alive = True self.look = 0 self.direction = 0 self.animation_list = [] self.frame_index = 0 self.action = 0 self.update_time = pygame.time.get_ticks() temp_list = [] for i in range(2): img = pygame.image.load(f'ver 3/imgs/player/idle/{i}.png') img = pygame.transform.scale(img,(70, 120)) temp_list.append(img) self.animation_list.append(temp_list) temp_list = [] for i in range(6): img = pygame.image.load(f'ver 3/imgs/player/PMR/{i}.png') img = pygame.transform.scale(img,(70, 120)) temp_list.append(img) self.animation_list.append(temp_list) temp_list = [] for i in range(6): img = pygame.image.load(f'ver 3/imgs/player/PML/{i}.png') img = pygame.transform.scale(img,(70, 120)) temp_list.append(img) self.animation_list.append(temp_list) self.image = self.animation_list[self.action][self.frame_index] self.rect = self.image.get_rect( ) self.rect.x = x self.rect.y = y self.rect.center = (x, y) global PPOS PPOS = self.rect.center global PPOSX PPOSX = self.rect.x global PPOSY PPOSY = self.rect.y #gets the player moving def move(self, moving_left, moving_right, moving_up, moving_down): dx = 0 dy = 0 if moving_left: dx = -3 ML = True self.look = 1 if moving_right: dx = 3 MR = True self.look = 2 if moving_up: dy = -3 MU = True if moving_down: dy = 3 MD = True if damage: Phealth =- 7 x = self.rect.x y = self.rect.y if moving_left: x =- 3 if moving_right: x = 3 if moving_up: y =- 3 if moving_down: y = 3 self.rect.x += dx self.rect.y += dy #updates the animation def update_animation(self): #update animation ANIMATION_COOLDOWN = 100 #update image depending on current frame self.image = self.animation_list[self.action][self.frame_index] #check if enough time has passed since the last update if pygame.time.get_ticks() - self.update_time > ANIMATION_COOLDOWN: self.update_time = pygame.time.get_ticks() self.frame_index += 1 #if the animation has run out then reset to the start if self.frame_index >= len(self.animation_list[self.action]): self.frame_index = 0 # doin the attackin if attack_right: temp_list = [] for i in range(2): img = pygame.image.load(f'ver 3/imgs/player/PAR/{i}.png') img = pygame.transform.scale(img,(70, 120)) temp_list.append(img) self.animation_list.append(temp_list) if attack_left: temp_list = [] for i in range(2): img = pygame.image.load(f'ver 3/imgs/player/PAL/{i}.png') img = pygame.transform.scale(img,(70, 120)) temp_list.append(img) self.animation_list.append(temp_list) #updates the actions def update_action(self, new_action): #check if new action is different to previous one if new_action != self.action: self.action = new_action #update the animation settings self.frame_index = 0 self.update_time = pygame.time.get_ticks() #update the player x and y co ordinate def updateco(self): x = self.rect.x y = self.rect.y if moving_left: x =- 3 if moving_right: x = 3 if moving_up: y =- 3 if moving_down: y = 3 #draw player on the screen def draw(self): screen.blit(self.image, self.rect) #the main body for the end fight big joe class Joe(pygame.sprite.Sprite): def __init__(self,char_type, x, y): pygame.sprite.Sprite.__init__(self) self.char_type = char_type self.alive = True self.look = 0 self.direction = 0 img = pygame.image.load(f'ver 3/imgs/enemies/big joe/idle/0.png') self.image = pygame.transform.scale(img,(90, 140)) self.rect = img.get_rect() self.rect.center = (x, y) #draw big joe def draw(self): screen.blit(self.image, self.rect) #the main body for the mercenacry enemies class Merc(pygame.sprite.Sprite): def __init__(self,char_type, x, y): pygame.sprite.Sprite.__init__(self) self.char_type = char_type self.alive = True self.look = 0 self.direction = 0 img = pygame.image.load(f'ver 3/imgs/enemies/Merc/musket/idle/0.png') self.image = pygame.transform.scale(img,(70, 120)) self.rect = img.get_rect() self.rect.center = (x, y) #draw the mercenary def draw(self): screen.blit(self.image, self.rect) #the main body for the baandit enemies class Bandit(pygame.sprite.Sprite): def __init__(self,char_type, x, y): pygame.sprite.Sprite.__init__(self) self.char_type = char_type self.alive = True self.look = 0 self.direction = 0 img = pygame.image.load(f'ver 3/imgs/enemies/bandit/s&s/idle/0.png') self.image = pygame.transform.scale(img,(70, 120)) self.rect = img.get_rect() self.rect.center = (x, y) #draws the bandit and makes him move towards th eplayer def draw(self): screen.blit(self.image, self.rect) dx = 0 dy = 0 if lvl1 == True: if PPOSX < self.rect.x: dx =- 3 if self.rect.x == PPOSX: dx = 0 if PPOSX > self.rect.x: dx = 3 if self.rect.x == PPOSX: dx = 0 if PPOSY < self.rect.y: dy =- 3 if self.rect.x == PPOSY: dy = 0 if PPOSY > self.rect.y: dy = 3 if self.rect.y == PPOSY: dx = 0 self.rect.x += dx self.rect.y += dy #the main body for lvl changing class Lvls(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.image.load('ver 3/imgs/lvls/lvl1/0.png') self.rect = self.image.get_rect() #change da levels def change(self): if lvl1 == True: self.image = pygame.image.load('ver 3/imgs/lvls/lvl1/0.png') if lvl2 == True: self.image = pygame.image.load('ver 3/imgs/lvls/lvl2/0.png') if lvl3 == True: self.image = pygame.image.load('ver 3/imgs/lvls/lvl3/0.png') boss_fx.play() def draw(self): screen.blit(self.image, self.rect) class Bullet(pygame.sprite.Sprite): def __init__(self, x, y, direction): pygame.sprite.Sprite.__init__(self) self.speed = 10 self.image = bullet self.rect = self.image.get_rect() self.rect.center = (x, y) self.direction = direction bullet_group = pygame.sprite.Group() lvl = Lvls() player = Player(400, 80, 310) merc = Merc(400, 650, 310) bandit = Bandit(300, 600, 455) joe = Joe(600, 600, 240) #main loop run = True while run: #FPS clock.tick(FPS) #the background draw_text("press space to play", font, TEXT_COL, 160, 250) if start == True: draw_bg() player.update_animation() player.draw() player.move(moving_left, moving_right, moving_up, moving_down) bandit.draw() merc.draw() hbar() inven() joe.draw() if lvl1 == True: lvl.draw() player.draw() player.move(moving_left, moving_right, moving_up, moving_down) player.update_animation() inven() bandit.draw() start = False hbar() lvl.change() player.updateco() if lvl2 == True: lvl.draw() player.draw() player.move(moving_left, moving_right, moving_up, moving_down) player.update_animation() inven() hbar() merc.draw() start = False lvl1 = False lvl.change() player.updateco() if lvl3 == True: lvl.draw() player.draw() player.move(moving_left, moving_right, moving_up, moving_down) player.update_animation() inven() hbar() joe.draw() player.updateco() if shoot_left: bullet = Bullet(PPOSX, PPOSY, player.look) bullet_group.add(bullet) if moving_left: player.update_action(2)#run left else: player.update_action(1)#stop and stare if moving_right: player.update_action(1)# run right else: player.update_action(2)#stop and stare if not moving_left and not moving_right and not attack_right and not attack_left: player.update_action(0) player.move(moving_left, moving_right, moving_up, moving_down) #if off turn off for event in pygame.event.get(): #quit game if event.type == pygame.QUIT: run = False sys.exit() #the keys pressed if event.type == pygame.KEYDOWN: if event.key == pygame.K_a: moving_left = True ML = True if event.key == pygame.K_d: moving_right = True MR = True if event.key == pygame.K_w: moving_up = True MU = True if event.key == pygame.K_s: moving_down = True MD = True if event.key == pygame.K_f: dash = True if event.key == pygame.K_SPACE: start = True if event.key == pygame.K_ESCAPE: run = False if event.key == pygame.K_i: invent = True if event.key == pygame.K_o: lvl1 = True if event.key == pygame.K_p: lvl2 = True if event.key == pygame.K_l: lvl3 = True if event.key == pygame.K_h: damage = True if event.key == pygame.K_1: melee = True if event.key == pygame.K_2: gun = True if melee == True: gun = False if gun == True: melee = False if event.key == pygame.K_f: attack_left = True if event.key == pygame.K_g: attack_right = True #the keys released if event.type == pygame.KEYUP: if event.key == pygame.K_a: moving_left = False ML = False if event.key == pygame.K_d: moving_right = False MR = False if event.key == pygame.K_w: moving_up = False MU = False if event.key == pygame.K_s: moving_down = False MD = False if event.key == pygame.K_f: dash = False if event.key == pygame.K_SPACE: damage = False if event.key == pygame.K_i: invent = False if event.key == pygame.K_f: shoot_left = False if event.key == pygame.K_g: shoot_right = False if event.key == pygame.K_f: attack_left = False if event.key == pygame.K_g: attack_right = False pygame.display.update() mixer.music.stop() pygame.quit()