Added some new classes

This commit is contained in:
Christian
2024-08-16 11:40:14 +02:00
parent ae2e28cfca
commit 0bbe702f8a
8 changed files with 80 additions and 31 deletions

36
test.py
View File

@@ -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: