base_game complete

This commit is contained in:
Yadciel 2023-04-28 10:30:51 +02:00
parent ad2a0b8209
commit 12f8a02d64
4 changed files with 35 additions and 20 deletions

13
game.py
View File

@ -12,9 +12,9 @@ def start():
win = pygame.display.set_mode((800, 800)) win = pygame.display.set_mode((800, 800))
player1 = player.Player(500, 500) player1 = player.Player(500, 500)
enemy = helicopter.Helicopter(50, 50) enemy = helicopter.Helicopter(50, 50)
Erzmine = object.Erz(600, 100) Erzmine = object.Erz(600, 40)
Tanken = object.Tank(160, 200) Tanken = object.Tank(200, 220)
Ziele = object.Ziel(600, 900) Ziele = object.Ziel(600, 750)
GameOver = False GameOver = False
GO = game_over.GameOver() GO = game_over.GameOver()
@ -39,6 +39,13 @@ def start():
if player1.rect.colliderect(enemy.rect): if player1.rect.colliderect(enemy.rect):
GameOver = True GameOver = True
if player1.rect.colliderect(Erzmine.rect):
player1.Erz += 1
if player1.rect.colliderect(Ziele.rect):
if player1.Erz >= 1:
player1.Erz -= 1
if GameOver == False: if GameOver == False:
# Hintergrundfarbe # Hintergrundfarbe
win.fill(white) win.fill(white)

View File

@ -4,6 +4,7 @@ import rotor
from fahrzeug import Fahrzeug, get_angle from fahrzeug import Fahrzeug, get_angle
import time import time
class Helicopter(Fahrzeug, pygame.sprite.Sprite): class Helicopter(Fahrzeug, pygame.sprite.Sprite):
def __init__(self, x, y): def __init__(self, x, y):
super().__init__(x, y) super().__init__(x, y)
@ -64,10 +65,10 @@ class Helicopter(Fahrzeug, pygame.sprite.Sprite):
rotated_image = pygame.transform.rotate(self.image, self.angle) rotated_image = pygame.transform.rotate(self.image, self.angle)
rotated_rect = rotated_image.get_rect(center=self.rect.center) rotated_rect = rotated_image.get_rect(center=self.rect.center)
#debug, nicht anrühren # debug nicht anrühren
# self.angle += 1 # self.angle += 1
#pygame.draw.rect(win, (255, 0, 0), rotated_rect) pygame.draw.rect(win, (255, 0, 0), rotated_rect)
win.blit(rotated_image, rotated_rect) win.blit(rotated_image, rotated_rect)
self.rotor.draw(win)
self.rotor.draw(win)

View File

@ -8,37 +8,44 @@ class Erz(pygame.sprite.Sprite):
def __init__(self, x, y): def __init__(self, x, y):
super().__init__() super().__init__()
self.image = pygame.image.load("resources/Erzmine.png").convert_alpha() self.image = pygame.image.load("resources/Erzmine.png").convert_alpha()
self.rect = self.image.get_rect() self.scaled_image = pygame.transform.scale(self.image, (self.image.get_width() / 2, self.image.get_height() / 2))
self.rect = self.scaled_image.get_rect(center=(x, y))
self.rect.centerx = x self.rect.centerx = x
self.rect.centery = y self.rect.centery = y
def draw(self, win): def draw(self, win):
groesse = pygame.transform.scale(self.image, (100, 100)) pygame.draw.rect(win, (255, 0, 0), self.rect)
win.blit(groesse, self.rect) win.blit(self.scaled_image, self.rect)
class Tank(pygame.sprite.Sprite): class Tank(pygame.sprite.Sprite):
def __init__(self, x, y): def __init__(self, x, y):
super().__init__() super().__init__()
self.image = pygame.image.load("resources/Tank.jpg").convert_alpha() self.image = pygame.image.load("resources/Tank.jpg").convert_alpha()
self.scaled_image = pygame.transform.scale(self.image, (self.image.get_width() / 100, self.image.get_height() / 100)) self.scaled_image = pygame.transform.scale(self.image, (self.image.get_width() / 20, self.image.get_height() / 20))
self.rect = self.scaled_image.get_rect() self.rect = self.scaled_image.get_rect(center=(x, y))
self.rect.centerx = x self.rect.centerx = x
self.rect.centery = y self.rect.centery = y
def draw(self, win): def draw(self, win):
groesse = pygame.transform.scale(self.image, (100, 100)) pygame.draw.rect(win, (255, 0, 0), self.rect)
win.blit(groesse, self.rect) win.blit(self.scaled_image, self.rect)
class Ziel(pygame.sprite.Sprite): class Ziel(pygame.sprite.Sprite):
def __init__(self, x, y): def __init__(self, x, y):
super().__init__() super().__init__()
self.image = pygame.image.load("resources/Ziel.jpg").convert_alpha() self.image = pygame.image.load("resources/Ziel.jpg").convert_alpha()
self.rect = self.image.get_rect() self.scaled_image = pygame.transform.scale(self.image, (self.image.get_width() / 3, self.image.get_height() / 3))
self.rect = self.scaled_image.get_rect(center=(x, y))
self.rect.centerx = x self.rect.centerx = x
self.rect.centery = y self.rect.centery = y
def draw(self, win): def draw(self, win):
groesse = pygame.transform.scale(self.image, (100, 100)) pygame.draw.rect(win, (255, 0, 0), self.rect)
win.blit(groesse, self.rect) win.blit(self.scaled_image, self.rect)

View File

@ -24,7 +24,7 @@ class Player(Fahrzeug, pygame.sprite.Sprite):
#debug, nicht anrühren #debug, nicht anrühren
#self.angle += 1 #self.angle += 1
#pygame.draw.rect(win, (255, 0, 0), rotated_rect) pygame.draw.rect(win, (255, 0, 0), rotated_rect)
win.blit(rotated_image, rotated_rect) win.blit(rotated_image, rotated_rect)