From 0065c3c033f2c0159776b9727fccce5a68ce203e Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 18 Aug 2024 20:00:25 +0200 Subject: [PATCH] Added animations class Editet readme.md Some changes on mainfile --- .gitignore | 2 ++ GameObject.py | 5 +++-- animations.py | 3 +++ game.py | 6 ++++-- readme.md | 1 + test.py | 19 ++++++++++--------- 6 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 animations.py diff --git a/.gitignore b/.gitignore index 909876d..bbce9ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .venv/ __pycache__/ +build/ +dist/ test.spec log.txt diff --git a/GameObject.py b/GameObject.py index f6fe01f..27b147f 100644 --- a/GameObject.py +++ b/GameObject.py @@ -42,11 +42,12 @@ class Player(GameObject): def __init__(self, name, screen, pos_x, pos_y, width, height, image=None) -> None: super().__init__(name, pos_x, pos_y, width, height, image) self._speed = 10 - self.screen = screen + self.screen:pygame.Surface = screen self.points = 0 self._health = 100 self.lifes = 2 self.kills = 0 + self._healthbar = pygame.rect.Rect((15, self.screen.get_size()[1]-50, 100, 20)) def handle_input(self, event:pygame.event.EventType): if(event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT): @@ -79,7 +80,7 @@ class Player(GameObject): self.pos_y += y def move(self, direction): - if(direction == "left"): + if(direction == "left"): self.pos_x -= self._speed if(direction == "right"): diff --git a/animations.py b/animations.py new file mode 100644 index 0000000..8e9c1fd --- /dev/null +++ b/animations.py @@ -0,0 +1,3 @@ +class animation(object): + def __init__(self) -> None: + pass \ No newline at end of file diff --git a/game.py b/game.py index bd8c24d..5000e46 100644 --- a/game.py +++ b/game.py @@ -1,8 +1,9 @@ ############################################################ -## Implements all Gamemechanics here! ## +## Implement all Gamemechanics here! ## ############################################################ import GameObject +import animations from levels import * import pygame import logger @@ -10,9 +11,10 @@ import logger #Leveldefinitions levels_list.append(first_level("First Level", (500,500), 10, 2)) - #Override def loadlevels(): for level in levels_list: + if(type(level) == "level"): + print("LEVEL") print(level) pass diff --git a/readme.md b/readme.md index e5bbbc3..bc97cdb 100644 --- a/readme.md +++ b/readme.md @@ -1,2 +1,3 @@ TODOS: + -Add ballistics calculation over time not pixel x framerate \ No newline at end of file diff --git a/test.py b/test.py index 39b254a..3f68c7a 100644 --- a/test.py +++ b/test.py @@ -19,8 +19,6 @@ WINDOWED_DEF_SIZE = (1024,768) window = pygame.display.set_mode((RENDERING_SIZE)) screen = pygame.Surface(RENDERING_SIZE) -#screen = pygame.display.set_mode((1024,768)) #TODO Add fullscreen mode - log = logger.log("log.txt") clock = pygame.time.Clock() @@ -72,11 +70,14 @@ for enemys in range(10): i += 1 gamestate = True -frametime =0 + milliseconds = pygame.time.get_ticks() +tmp_time = pygame.time.get_ticks()/1000 seconds = milliseconds/1000 +tmp_seconds = 0 + while(gamestate): screen.fill((8,31,61)) @@ -85,6 +86,7 @@ while(gamestate): del log gamestate = False if(event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): + pygame.display.set_mode((RENDERING_SIZE)) gamestate = False #Push F10 for fullscreen-mode if(event.type == pygame.KEYDOWN and event.key == pygame.K_F10): @@ -96,7 +98,7 @@ while(gamestate): player2.handle_input(event) if(player1.keymap["left"] == True and player1.pos_x > 0): - player1.move("left") + player1.move("left") #print("links") if(player1.keymap["right"] == True and player1.pos_x <= (screen.get_size()[0]-player1.width)): player1.move("right") @@ -111,6 +113,7 @@ while(gamestate): #image = screen.blit(testimage, (pos_x, pos_y)) mouse_pos = pygame.mouse.get_pos() + #print(int(pygame.time.get_ticks()/1000)) #print(mouse_pos) #print(image.topleft) #Gibt die Position einen Surfaces "obenlinks" aus @@ -196,8 +199,8 @@ while(gamestate): #print("Playerkills 1:", player1.kills) #print("Playerkills 2:", player2.kills) - print(F"Player 1 Health: {player1.get_health()}") - print(F"Player 2 Health: {player2.get_health()}") + #print(F"Player 1 Health: {player1.get_health()}") + #print(F"Player 2 Health: {player2.get_health()}") player1.render(screen) player2.render(screen) #print(int(seconds), "\r") @@ -225,7 +228,6 @@ while(gamestate): screen.blit(fps_label, (screen.get_size()[0]-fps_label.get_size()[0]-10, screen.get_size()[1]-25)) screen.blit(hash_label, (25, screen.get_size()[1] -25)) - frametime = clock.get_time() #Scales the mainsurface scaled_win = pygame.transform.smoothscale(screen, window.get_size()) #Blits the mainsurface to the mainwindow @@ -233,6 +235,5 @@ while(gamestate): #if(mouse_pos <= (image.topleft+image.size) and mouse_pos >= image.topleft): # print("HIIIIITTT!!!!") - frametime = 0 - clock.tick(60) + clock.tick(90) pygame.display.flip() \ No newline at end of file