From f5537d0644b08ce19123ff8a95b5e37c731147b6 Mon Sep 17 00:00:00 2001 From: Yadciel Date: Tue, 25 Apr 2023 08:30:43 +0200 Subject: [PATCH] objects --- game.py | 22 +++++++++++++--------- background.py => object.py | 25 +++++++++---------------- resources/{Tank.png => Tank.jpg} | Bin resources/{Ziel.png => Ziel.jpg} | Bin 4 files changed, 22 insertions(+), 25 deletions(-) rename background.py => object.py (74%) rename resources/{Tank.png => Tank.jpg} (100%) rename resources/{Ziel.png => Ziel.jpg} (100%) diff --git a/game.py b/game.py index 9ff1401..1d4ec83 100644 --- a/game.py +++ b/game.py @@ -1,18 +1,19 @@ import pygame import player import helicopter -import background +import object import tilemap import sys + def start(): pygame.init() win = pygame.display.set_mode((800, 800)) player1 = player.Player(0, 0) enemy = helicopter.Helicopter(5, 5) - Erzmine = background.Erz() - Tanken = background.Tank() - Ziele = background.Ziel() + Erzmine = object.Erz(320, 20) + Tanken = object.Tank(50, 200) + Ziele = object.Ziel(320, 600) tile_set = pygame.image.load("resources/roads2W.png").convert_alpha() @@ -53,13 +54,16 @@ def start(): # debug ausgabe # --------------------------- - # debug_selfrect = font.render('self centerx: ' + str(player1.rect.centerx) + ' self centery: ' + str(player1.rect.centery), True, white) - # win.blit(debug_selfrect, (20, 40)) + debug_selfrect = font.render('self centerx: ' + str(player1.rect.centerx) + ' self centery: ' + str(player1.rect.centery), True, white) + win.blit(debug_selfrect, (20, 40)) - # debug_selfrect = font.render('dest x: ' + str(player1.dest_x) + ' dest y: ' + str(player1.dest_y), True, white) - # win.blit(debug_selfrect, (20, 60)) + debug_selfrect = font.render('dest x: ' + str(player1.dest_x) + ' dest y: ' + str(player1.dest_y), True, white) + win.blit(debug_selfrect, (20, 60)) # --------------------------- + if player1.rect.colliderect(Tanken.rect): + player1.Tank = 250 + Erzmine.update() Erzmine.draw(win) @@ -73,7 +77,7 @@ def start(): player1.draw(win) enemy.update(player1) - enemy.dest((player1.rect.centerx,player1.rect.centery)) + enemy.dest((player1.rect.centerx, player1.rect.centery)) enemy.draw(win) pygame.display.update() diff --git a/background.py b/object.py similarity index 74% rename from background.py rename to object.py index fccaaa5..4b968aa 100644 --- a/background.py +++ b/object.py @@ -3,45 +3,38 @@ import pygame # Farbe Weiß WHITE = (255, 255, 255) + class Erz(pygame.sprite.Sprite): - def __init__(self): + def __init__(self, x, y): super().__init__() self.image = pygame.image.load("resources/Erzmine.png").convert_alpha() self.rect = self.image.get_rect() - self.rect = 330, 20 - + self.rect = x, y def draw(self, win): groesse = pygame.transform.scale(self.image, (100, 100)) win.blit(groesse, self.rect) - class Tank(pygame.sprite.Sprite): - - def __init__(self): + def __init__(self, x, y): super().__init__() - self.image = pygame.image.load("resources/Tank.png").convert_alpha() + self.image = pygame.image.load("resources/Tank.jpg").convert_alpha() self.rect = self.image.get_rect() - self.rect = 30, 220 - + self.rect.center = x, y def draw(self, win): groesse = pygame.transform.scale(self.image, (100, 100)) win.blit(groesse, self.rect) - class Ziel(pygame.sprite.Sprite): - - def __init__(self): + def __init__(self, x, y): super().__init__() - self.image = pygame.image.load("resources/Ziel.png").convert_alpha() + self.image = pygame.image.load("resources/Ziel.jpg").convert_alpha() self.rect = self.image.get_rect() - self.rect = 330, 520 - + self.rect = x, y def draw(self, win): groesse = pygame.transform.scale(self.image, (100, 100)) win.blit(groesse, self.rect) - diff --git a/resources/Tank.png b/resources/Tank.jpg similarity index 100% rename from resources/Tank.png rename to resources/Tank.jpg diff --git a/resources/Ziel.png b/resources/Ziel.jpg similarity index 100% rename from resources/Ziel.png rename to resources/Ziel.jpg