Added some new classes
This commit is contained in:
@@ -60,7 +60,7 @@ class Player(GameObject):
|
||||
|
||||
if(event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE):
|
||||
#Fiiirrreee in the hole
|
||||
print("Feuer!")
|
||||
#print("Feuer!")
|
||||
self.fire(self.screen)
|
||||
|
||||
def move(self, x=0, y=0):
|
||||
@@ -115,7 +115,7 @@ class Player2(Player):
|
||||
|
||||
if(event.type == pygame.KEYDOWN and event.key == pygame.K_t):
|
||||
#Fiiirrreee in the hole
|
||||
print("Feuer!")
|
||||
#print("Feuer!")
|
||||
self.fire(self.screen)
|
||||
|
||||
def firecontrol(self, screen):
|
||||
@@ -133,10 +133,13 @@ class Enemy(GameObject):
|
||||
super().__init__(name, pos_x, pos_y, width, height, image)
|
||||
self.screen = screen
|
||||
self.movespeed = 10
|
||||
self.weapon:Weapons = None
|
||||
|
||||
def fire(self, screen):
|
||||
#print("Schieße!!!!")
|
||||
shot = Projectile("Enemy", self.pos_x+(self.width/2),self.pos_y+self.height,5,10, screen, 2)
|
||||
#shot = Projectile("Enemy", self.pos_x+(self.width/2),self.pos_y+self.height,5,10, screen, 2)
|
||||
self.weapon.fire()
|
||||
|
||||
|
||||
def firecontrol(self, screen):
|
||||
if(len(Projectile.shots) > 0):
|
||||
@@ -153,6 +156,11 @@ class Enemy(GameObject):
|
||||
if(y != 0):
|
||||
self.pos_y += y
|
||||
|
||||
def give_weapon(self, weapon):
|
||||
self.weapon = weapon
|
||||
|
||||
def get_weapon(self):
|
||||
return self.weapon
|
||||
|
||||
def movementqueue_run(self):
|
||||
pass
|
||||
@@ -181,24 +189,23 @@ class Projectile(GameObject):
|
||||
if(self.pos_y >= self.screen.get_size()[1]):
|
||||
pass
|
||||
|
||||
class Weapons(object):
|
||||
def __init__(self) -> None:
|
||||
self.type = None
|
||||
self.damage = 0
|
||||
self.firerate = 0
|
||||
self.duration = 0
|
||||
class Weapons(GameObject):
|
||||
def __init__(self, name, pos_x, pos_y, width, height, damage, firerate, duration, screen, image=None) -> None:
|
||||
super().__init__(name, pos_x, pos_y, width, height, image)
|
||||
#self.type = type
|
||||
self.damage = damage
|
||||
self.firerate = firerate
|
||||
self.duration = duration
|
||||
self.sprite = ""
|
||||
self.mountingpos = list()
|
||||
pass
|
||||
|
||||
def fire(self):
|
||||
print(F"Feuere: {self.name}")
|
||||
|
||||
class Item(GameObject):
|
||||
def __init__(self, name, pos_x, pos_y, width, height, image=None) -> None:
|
||||
super().__init__(name, pos_x, pos_y, width, height, image)
|
||||
|
||||
class item_extra_life(Item):
|
||||
def __init__(self, name, pos_x, pos_y, width, height, image=None) -> None:
|
||||
super().__init__(name, pos_x, pos_y, width, height, image)
|
||||
|
||||
class Weapons(GameObject):
|
||||
def __init__(self, name, pos_x, pos_y, width, height, image=None) -> None:
|
||||
super().__init__(name, pos_x, pos_y, width, height, image)
|
||||
@@ -5,10 +5,4 @@
|
||||
import GameObject
|
||||
import pygame
|
||||
|
||||
class Projectilehandler(object):
|
||||
def __init__(self) -> None:
|
||||
self.projectiles = list()
|
||||
pass
|
||||
|
||||
def add_projectile(self, source):
|
||||
pass
|
||||
#weapons = dict()
|
||||
21
logger.py
Normal file
21
logger.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import time
|
||||
|
||||
class log(object):
|
||||
def __init__(self, logfile:str) -> None:
|
||||
__logfile = logfile
|
||||
__filehandle = None
|
||||
|
||||
try:
|
||||
self.__filehandle = open(self.logfile, "w")
|
||||
except FileExistsError:
|
||||
print("Datei existiert bereits...")
|
||||
|
||||
except:
|
||||
print("Something went wrong!")
|
||||
|
||||
def writeln(self, text:str):
|
||||
self.__filehandle.writelines(F"{time.strftime("%H:%M:%S")}: {text}")
|
||||
|
||||
def __del__(self):
|
||||
self.writeln("Log closed!")
|
||||
self.__filehandle.close()
|
||||
36
test.py
36
test.py
@@ -1,17 +1,24 @@
|
||||
import pygame
|
||||
import Game
|
||||
import game
|
||||
import logger
|
||||
import weapons
|
||||
import GameObject
|
||||
import Utils
|
||||
import time
|
||||
import random
|
||||
import subprocess
|
||||
|
||||
|
||||
pygame.init()
|
||||
pygame.display.set_caption("TESTFENSTER")
|
||||
pygame.mouse.set_visible(True)
|
||||
#pygame.key.set_repeat(1, 30)
|
||||
screen = pygame.display.set_mode((1024,768)) #TODO Add fullscreen mode
|
||||
|
||||
log = logger.log("logg.txt")
|
||||
|
||||
logfile = open("log.txt", "w")
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
WEISS = (255,255,255)
|
||||
@@ -19,14 +26,19 @@ SCHWARZ = (0,0,0)
|
||||
GRUEN = (0,255,0)
|
||||
ROT = (255,0,0)
|
||||
|
||||
logfile.write(F"{time.strftime("%H:%M:%S")} Loading game...\n")
|
||||
log.writeln("TEST")
|
||||
|
||||
logfile.write(F"{time.strftime("%H:%M:%S")} Loading images...\n")
|
||||
image_enemy = Utils.load_image("Rastergrafik.png")
|
||||
testimage = Utils.load_image("Rastergrafik.png")
|
||||
|
||||
logfile.write(F"{time.strftime("%H:%M:%S")} Setup fonts...\n")
|
||||
font1 = pygame.font.Font("/usr/share/fonts/TTF/Inconsolata-UltraExpandedExtraBold.ttf", 30)
|
||||
font2 = pygame.font.Font("/usr/share/fonts/TTF/Inconsolata-UltraExpandedExtraBold.ttf", 12)
|
||||
|
||||
logfile.write(F"{time.strftime("%H:%M:%S")} Get git revision hash...\n")
|
||||
short_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip()
|
||||
hash_label = font2.render(F"git-hash: {short_hash}", 1, ROT)
|
||||
logfile.write(F"{time.strftime("%H:%M:%S")} Git-Hash: {short_hash}")
|
||||
|
||||
#testimage.set_colorkey((255,0,255), pygame.RLEACCELOK)
|
||||
|
||||
@@ -39,10 +51,13 @@ i = 0
|
||||
startpos_x = 50
|
||||
startpos_y = 30
|
||||
for enemys in range(80):
|
||||
tmp_weapon = weapons.Laserblaster("Laserblaster", startpos_x, startpos_y, 5, 10, screen, testimage)
|
||||
tmp = GameObject.Enemy(F"Enemy-{i}", startpos_x,startpos_y,35,35, screen, testimage)
|
||||
tmp.give_weapon(tmp_weapon)
|
||||
if(startpos_x >= (screen.get_size()[0]-150)):
|
||||
startpos_y += 50
|
||||
startpos_x = 0
|
||||
print(tmp.get_weapon())
|
||||
spawned_enemys.append(tmp)
|
||||
startpos_x += 50
|
||||
|
||||
@@ -60,6 +75,7 @@ while(gamestate):
|
||||
|
||||
for event in pygame.event.get():
|
||||
if(event.type == pygame.QUIT):
|
||||
logfile.close()
|
||||
gamestate = False
|
||||
player1.handle_input(event)
|
||||
player2.handle_input(event)
|
||||
@@ -98,8 +114,8 @@ while(gamestate):
|
||||
player1.firecontrol(screen)
|
||||
player2.firecontrol(screen)
|
||||
|
||||
print("Spieler1 Lifes: ", player1.lifes)
|
||||
print("Spieler2 Lifes: ", player2.lifes)
|
||||
#print("Spieler1 Lifes: ", player1.lifes)
|
||||
#print("Spieler2 Lifes: ", player2.lifes)
|
||||
|
||||
#TODO If Playerposition are on the same x-axis then gamble hit by 50% chance
|
||||
|
||||
@@ -124,8 +140,8 @@ while(gamestate):
|
||||
del spawned_enemys[index]
|
||||
index = GameObject.Projectile.shots.index(projectiles)
|
||||
del GameObject.Projectile.shots[index]
|
||||
print(F"Player-Points: {player1.points}")
|
||||
print(F"Player-Points: {player2.points}")
|
||||
#print(F"Player-Points: {player1.points}")
|
||||
#print(F"Player-Points: {player2.points}")
|
||||
if(projectile.name == "Player"):
|
||||
player1.kills += 1
|
||||
|
||||
@@ -163,12 +179,12 @@ while(gamestate):
|
||||
seconds = milliseconds / 1000
|
||||
now = time.time_ns()
|
||||
|
||||
print("Playerkills 1:", player1.kills)
|
||||
print("Playerkills 2:", player2.kills)
|
||||
#print("Playerkills 1:", player1.kills)
|
||||
#print("Playerkills 2:", player2.kills)
|
||||
|
||||
player1.render(screen)
|
||||
player2.render(screen)
|
||||
print(int(seconds))
|
||||
#print(int(seconds), "\r")
|
||||
|
||||
rand = random.randint(0, 100)
|
||||
for enemy in spawned_enemys:
|
||||
|
||||
10
weapons.py
Normal file
10
weapons.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import GameObject
|
||||
|
||||
class Laserblaster(GameObject.Weapons):
|
||||
def __init__(self, name, pos_x, pos_y, width, height, screen, image=None) -> None:
|
||||
super().__init__(name, pos_x, pos_y, width, height, 10, 2, 0, image)
|
||||
self.screen = screen
|
||||
self.image = image
|
||||
|
||||
def fire(self):
|
||||
self.projectile = GameObject.Projectile("Enemy", self.pos_x, self.pos_y, 5, 10, self.screen, 2, self.image)
|
||||
Reference in New Issue
Block a user