Added new classes
Edited player.get_damage() function
This commit is contained in:
@@ -41,7 +41,7 @@ class GameObject(object):
|
|||||||
class Player(GameObject):
|
class Player(GameObject):
|
||||||
def __init__(self, name, screen, pos_x, pos_y, width, height, image=None) -> None:
|
def __init__(self, name, screen, pos_x, pos_y, width, height, image=None) -> None:
|
||||||
super().__init__(name, pos_x, pos_y, width, height, image)
|
super().__init__(name, pos_x, pos_y, width, height, image)
|
||||||
self._speed = 10
|
self._speed = 8
|
||||||
self.screen:pygame.Surface = screen
|
self.screen:pygame.Surface = screen
|
||||||
self.points = 0
|
self.points = 0
|
||||||
self._health = 100
|
self._health = 100
|
||||||
@@ -71,6 +71,10 @@ class Player(GameObject):
|
|||||||
return self._health
|
return self._health
|
||||||
|
|
||||||
def get_damage(self, damage:int):
|
def get_damage(self, damage:int):
|
||||||
|
|
||||||
|
if((self._health - damage) <= 0):
|
||||||
|
self._health = 0
|
||||||
|
else:
|
||||||
self._health -= damage
|
self._health -= damage
|
||||||
|
|
||||||
def move(self, x=0, y=0):
|
def move(self, x=0, y=0):
|
||||||
@@ -89,7 +93,7 @@ class Player(GameObject):
|
|||||||
def fire(self, screen):
|
def fire(self, screen):
|
||||||
projectile_width = 6
|
projectile_width = 6
|
||||||
projectile_height = 10
|
projectile_height = 10
|
||||||
shot = Projectile(self.name, self.pos_x+(self.width/2)-(projectile_width/2), self.pos_y-projectile_height, projectile_width, projectile_height, screen, 10)
|
shot = Projectile(self.name, self.pos_x+(self.width/2)-(projectile_width/2), self.pos_y-projectile_height, projectile_width, projectile_height, screen, 8)
|
||||||
|
|
||||||
def firecontrol(self, screen):
|
def firecontrol(self, screen):
|
||||||
if(len(Projectile.shots) > 0):
|
if(len(Projectile.shots) > 0):
|
||||||
|
|||||||
38
interface.py
Normal file
38
interface.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
class UIelement(object):
|
||||||
|
def __init__(self, screen, name, posx, posy) -> None:
|
||||||
|
self.screen = screen
|
||||||
|
self.name = name
|
||||||
|
self.posx = posx
|
||||||
|
self.posy = posy
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Healthbar(UIelement):
|
||||||
|
def __init__(self, screen, name, posx, posy, width, height,playerhealth) -> None:
|
||||||
|
super().__init__(screen, name, posx, posy)
|
||||||
|
self.width = width
|
||||||
|
self.height = height
|
||||||
|
self.max_width = width
|
||||||
|
self.max_health = playerhealth
|
||||||
|
self.health = playerhealth
|
||||||
|
|
||||||
|
def update(self, playerheatlh):
|
||||||
|
grundwert = self.max_health
|
||||||
|
prozentwert = playerheatlh
|
||||||
|
prozent = (playerheatlh/grundwert)
|
||||||
|
print(prozent)
|
||||||
|
print(prozentwert)
|
||||||
|
print(playerheatlh)
|
||||||
|
|
||||||
|
#Update until playerhealth not zero
|
||||||
|
if(self.health > 0):
|
||||||
|
res = self.max_width*prozent
|
||||||
|
self.health = res
|
||||||
|
elif self.health < 0:
|
||||||
|
self.health = 0
|
||||||
|
|
||||||
|
def render(self, screen):
|
||||||
|
pygame.draw.rect(screen, (255,0,0), (self.posx, self.posy, self.health, self.height))
|
||||||
|
pass
|
||||||
8
test.py
8
test.py
@@ -2,6 +2,7 @@ import pygame
|
|||||||
import game
|
import game
|
||||||
import logger
|
import logger
|
||||||
import weapons
|
import weapons
|
||||||
|
import interface
|
||||||
import GameObject
|
import GameObject
|
||||||
import Utils
|
import Utils
|
||||||
import time
|
import time
|
||||||
@@ -49,6 +50,8 @@ log.writeln(F"Git-Hash: {short_hash}")
|
|||||||
player1 = GameObject.Player("Player", screen,(screen.get_size()[0]/2)-17, screen.get_size()[1]-100, 35, 35, testimage)
|
player1 = GameObject.Player("Player", screen,(screen.get_size()[0]/2)-17, screen.get_size()[1]-100, 35, 35, testimage)
|
||||||
player2 = GameObject.Player2("Player2", screen,(screen.get_size()[0]/2)-17, screen.get_size()[1]-100, 35, 35, testimage)
|
player2 = GameObject.Player2("Player2", screen,(screen.get_size()[0]/2)-17, screen.get_size()[1]-100, 35, 35, testimage)
|
||||||
|
|
||||||
|
healthbar1 = interface.Healthbar(screen, "Player1", 25, screen.get_size()[1]-80, 300, 10, player1.get_health())
|
||||||
|
|
||||||
game.loadlevels()
|
game.loadlevels()
|
||||||
|
|
||||||
spawned_enemys = list()
|
spawned_enemys = list()
|
||||||
@@ -127,7 +130,8 @@ while(gamestate):
|
|||||||
#print("Treffer")
|
#print("Treffer")
|
||||||
#pos_x = mouse_pos[0]
|
#pos_x = mouse_pos[0]
|
||||||
#pos_y = mouse_pos[1]
|
#pos_y = mouse_pos[1]
|
||||||
|
healthbar1.update(player1.get_health())
|
||||||
|
healthbar1.render(screen)
|
||||||
player1.firecontrol(screen)
|
player1.firecontrol(screen)
|
||||||
player2.firecontrol(screen)
|
player2.firecontrol(screen)
|
||||||
|
|
||||||
@@ -235,5 +239,5 @@ while(gamestate):
|
|||||||
|
|
||||||
#if(mouse_pos <= (image.topleft+image.size) and mouse_pos >= image.topleft):
|
#if(mouse_pos <= (image.topleft+image.size) and mouse_pos >= image.topleft):
|
||||||
# print("HIIIIITTT!!!!")
|
# print("HIIIIITTT!!!!")
|
||||||
clock.tick(90)
|
clock.tick(60)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
Reference in New Issue
Block a user