import pygame import math import random import time import sys pygame.init() SCREEN_WIDTH = 800 SCREEN_HEIGHT = int(SCREEN_WIDTH * 0.8) 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 = 60 PPOS = 0 PD = 0 BPOS = 0 MPOS = 0 PLAYERALIVE = True DISTANCEFR = 0 #all of the variables 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 banditsight = False start = False lvl1 = False lvl2 = False lvl3 = False invent = False b = (1, 1) #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)) def inven(): img = pygame.image.load('imgs/inventory/stuff/0.png') img = pygame.transform.scale(img,(800, 640)) if invent == True: screen.blit(img, b) def boundery(): pygame.draw.line(screen, RED, (300, 200), (500, 200)) pygame.draw.line(screen, RED, (300, 400), (500, 400)) #fill the screen def draw_bg(): screen.fill(GREEN) rect = pygame.draw.rect(screen, RED,(rect_y, rect_x, rect_width, rect_height)) pygame.display.update(rect) #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.index = 0 for i in range(3): img = pygame.image.load(f'imgs/player/idle/{i}.png') img = pygame.transform.scale(img,(80, 130)) self.animation_list.append(img) self.image = self.animation_list[self.index] self.rect = self.image.get_rect() self.rect.center = (x, y) PPOS = self.rect.center PPOSX = self.rect.x PPOSY = self.rect.y def move(self, moving_left, moving_right, moving_up, moving_down): dx = 0 dy = 0 if moving_left: dx = -5 if moving_right: dx = 5 if moving_up: dy = -5 if moving_down: dy = 5 if damage: Phealth - 7 self.rect.x += dx self.rect.y += dy def draw(self): screen.blit(self.image, self.rect) 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'imgs/enemies/Merc/musket/0.png') self.image = pygame.transform.scale(img,(80, 130)) self.rect = img.get_rect() self.rect.center = (x, y) def draw(self): screen.blit(self.image, self.rect) 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'imgs/enemies/bandit/s&s/0.png') self.image = pygame.transform.scale(img,(80, 130)) self.rect = img.get_rect() self.rect.center = (x, y) def draw(self): screen.blit(self.image, self.rect) player = Player(400, 400, 320) merc = Merc(500, 500, 130) bandit = Bandit(300, 300, 275) #main loop run = True while run: #FPS clock.tick(FPS) #the background if start == True: draw_bg() player.draw() player.move(moving_left, moving_right, moving_up, moving_down) merc.draw() bandit.draw() inven() boundery() else: draw_text("press space to play", font, TEXT_COL, 160, 250) #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 if event.key == pygame.K_d: moving_right = True if event.key == pygame.K_w: moving_up = True if event.key == pygame.K_s: moving_down = 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 #the keys released if event.type == pygame.KEYUP: if event.key == pygame.K_a: moving_left = False if event.key == pygame.K_d: moving_right = False if event.key == pygame.K_w: moving_up = False if event.key == pygame.K_s: moving_down = 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 pygame.display.update() pygame.quit()