Added animations class
Editet readme.md Some changes on mainfile
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,6 @@
|
||||
.venv/
|
||||
__pycache__/
|
||||
build/
|
||||
dist/
|
||||
test.spec
|
||||
log.txt
|
||||
|
||||
@@ -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"):
|
||||
|
||||
3
animations.py
Normal file
3
animations.py
Normal file
@@ -0,0 +1,3 @@
|
||||
class animation(object):
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
6
game.py
6
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
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
TODOS:
|
||||
|
||||
-Add ballistics calculation over time not pixel x framerate
|
||||
19
test.py
19
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()
|
||||
Reference in New Issue
Block a user