base_game complete
This commit is contained in:
parent
ad2a0b8209
commit
12f8a02d64
13
game.py
13
game.py
@ -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)
|
||||||
|
@ -4,12 +4,13 @@ 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)
|
||||||
self.image = pygame.image.load("resources/helicopter.jpg").convert_alpha()
|
self.image = pygame.image.load("resources/helicopter.jpg").convert_alpha()
|
||||||
self.image = self.image.subsurface(44, 0, 44, 99)
|
self.image = self.image.subsurface(44, 0, 44, 99)
|
||||||
self.image = pygame.transform.scale(self.image, (self.image.get_width()*1.2, self.image.get_height()*1.2))
|
self.image = pygame.transform.scale(self.image, (self.image.get_width() * 1.2, self.image.get_height() * 1.2))
|
||||||
self.rect = self.image.get_rect(center=(x, y))
|
self.rect = self.image.get_rect(center=(x, y))
|
||||||
self.rect.centerx = x
|
self.rect.centerx = x
|
||||||
self.rect.centery = y
|
self.rect.centery = y
|
||||||
@ -56,7 +57,7 @@ class Helicopter(Fahrzeug, pygame.sprite.Sprite):
|
|||||||
if self.rect.centerx != self.dest_x or self.rect.centery != self.dest_y:
|
if self.rect.centerx != self.dest_x or self.rect.centery != self.dest_y:
|
||||||
if self.Tank > 0:
|
if self.Tank > 0:
|
||||||
self.Tank -= 0.1
|
self.Tank -= 0.1
|
||||||
self.angle = get_angle((self.rect.centerx, self.rect.centery), (self.dest_x, self.dest_y))-90
|
self.angle = get_angle((self.rect.centerx, self.rect.centery), (self.dest_x, self.dest_y)) - 90
|
||||||
|
|
||||||
self.rotor.update(self)
|
self.rotor.update(self)
|
||||||
|
|
||||||
@ -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)
|
||||||
|
27
object.py
27
object.py
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user