ammo counter
This commit is contained in:
parent
a9e1dd70d0
commit
eb68edfb03
2 changed files with 60 additions and 4 deletions
|
|
@ -9,6 +9,7 @@ class Player:
|
|||
self.rect = pygame.Rect(x, y, PLAYER_SIZE, PLAYER_SIZE)
|
||||
self.dir = "up"
|
||||
self.image = image
|
||||
self.ammo = 5 # Startwert für Munition
|
||||
|
||||
def move(self, keys, map_w, map_h):
|
||||
if not self.alive:
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@ from settings import PLAYER_SIZE, MAP_PATH, WIDTH, HEIGHT, MINIMAP_MARGIN
|
|||
|
||||
DEBUG = False
|
||||
|
||||
MAX_AMMO = 5
|
||||
|
||||
|
||||
trinkbrunnen_positions = np.load('trinkbrunnen_pixel_positions.npy')
|
||||
# Nach dem Laden der Positionen:
|
||||
used_brunnen = [False] * len(trinkbrunnen_positions)
|
||||
pygame.init()
|
||||
# logo_img = pygame.image.load("images/logo.png")
|
||||
# pygame.display.set_icon(logo_img)
|
||||
|
|
@ -19,6 +25,9 @@ pygame.display.set_caption("Wasser der Regierung")
|
|||
logo_img = pygame.image.load("images/Wasser_der_Regierung.PNG")
|
||||
pygame.display.set_icon(logo_img)
|
||||
|
||||
|
||||
|
||||
|
||||
def load_map(path):
|
||||
try:
|
||||
arr = rasterio.open(path).read(1)
|
||||
|
|
@ -32,12 +41,22 @@ def load_map(path):
|
|||
print(f"Map load error: {e}")
|
||||
return None, WIDTH, HEIGHT
|
||||
|
||||
|
||||
map_surface, MAP_W, MAP_H = load_map(MAP_PATH)
|
||||
|
||||
|
||||
DIST_FACTOR = 2.0 # 2.0 = doppelte Entfernung, 1.0 = Standard
|
||||
# Karte vergrößern
|
||||
scaled_map = pygame.transform.smoothscale(map_surface, (int(MAP_W * DIST_FACTOR), int(MAP_H * DIST_FACTOR)))
|
||||
WIN.blit(scaled_map, (0, 0))
|
||||
|
||||
MINIMAP_WIDTH = 200
|
||||
MINIMAP_HEIGHT = int(MAP_H / MAP_W * MINIMAP_WIDTH)
|
||||
|
||||
|
||||
def draw_minimap(win, map_surface, player, enemies, bottles):
|
||||
mini = pygame.transform.smoothscale(map_surface, (MINIMAP_WIDTH, MINIMAP_HEIGHT))
|
||||
|
||||
win.blit(mini, (WIDTH - MINIMAP_WIDTH - MINIMAP_MARGIN, MINIMAP_MARGIN))
|
||||
|
||||
def map2mini(x, y):
|
||||
|
|
@ -53,6 +72,7 @@ def draw_minimap(win, map_surface, player, enemies, bottles):
|
|||
for bottle in bottles:
|
||||
pygame.draw.circle(win, (0, 180, 255), map2mini(bottle.x, bottle.y), 3)
|
||||
|
||||
|
||||
def show_win_screen(win):
|
||||
win.fill((40, 180, 80))
|
||||
font = pygame.font.SysFont(None, 72)
|
||||
|
|
@ -61,6 +81,7 @@ def show_win_screen(win):
|
|||
pygame.display.update()
|
||||
pygame.time.wait(5000)
|
||||
|
||||
|
||||
def show_lose_screen(win):
|
||||
win.fill((180, 40, 40))
|
||||
font = pygame.font.SysFont(None, 72)
|
||||
|
|
@ -77,7 +98,9 @@ def main():
|
|||
human_img = load_img(HUMAN_IMG_PATH, (PLAYER_SIZE, PLAYER_SIZE))
|
||||
|
||||
player = Player(MAP_W // 2, MAP_H // 2, player_img)
|
||||
enemies = [Enemy(random.randint(0, MAP_W - PLAYER_SIZE), random.randint(0, MAP_H - PLAYER_SIZE), enemy_img, human_img, i == 0) for i in range(20)]
|
||||
enemies = [
|
||||
Enemy(random.randint(0, MAP_W - PLAYER_SIZE), random.randint(0, MAP_H - PLAYER_SIZE), enemy_img, human_img,
|
||||
i == 0) for i in range(20)]
|
||||
bottles = []
|
||||
minimap_visible = True
|
||||
clock = pygame.time.Clock()
|
||||
|
|
@ -89,7 +112,13 @@ def main():
|
|||
running = False
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_SPACE:
|
||||
bottles.append(TapWater(player.x, player.y, player.dir))
|
||||
|
||||
if player.ammo > 0:
|
||||
bottles.append(TapWater(player.x, player.y, player.dir))
|
||||
player.ammo -= 1
|
||||
else:
|
||||
print("Keine Munition!")
|
||||
|
||||
if event.key == pygame.K_m:
|
||||
minimap_visible = not minimap_visible
|
||||
keys = pygame.key.get_pressed()
|
||||
|
|
@ -106,10 +135,13 @@ def main():
|
|||
bottles = [b for b in bottles if 0 <= b.x <= MAP_W and 0 <= b.y <= MAP_H]
|
||||
ox = max(0, min(player.x + PLAYER_SIZE // 2 - WIDTH // 2, MAP_W - WIDTH))
|
||||
oy = max(0, min(player.y + PLAYER_SIZE // 2 - HEIGHT // 2, MAP_H - HEIGHT))
|
||||
if map_surface:
|
||||
WIN.blit(map_surface, (0, 0), area=pygame.Rect(ox, oy, WIDTH, HEIGHT))
|
||||
if scaled_map:
|
||||
WIN.blit(scaled_map, (0, 0), area=pygame.Rect(ox, oy, WIDTH, HEIGHT))
|
||||
else:
|
||||
WIN.fill((255, 255, 255))
|
||||
|
||||
for px, py in trinkbrunnen_positions:
|
||||
pygame.draw.circle(WIN, (0, 0, 0), (px - ox, py - oy), 4)
|
||||
player.draw(WIN, ox, oy)
|
||||
for bottle in bottles:
|
||||
bottle.draw(WIN, ox, oy)
|
||||
|
|
@ -117,7 +149,29 @@ def main():
|
|||
enemy.draw(WIN, ox, oy)
|
||||
if minimap_visible:
|
||||
draw_minimap(WIN, map_surface, player, enemies, bottles)
|
||||
|
||||
player_rect = pygame.Rect(player.x, player.y, PLAYER_SIZE, PLAYER_SIZE)
|
||||
|
||||
|
||||
# Beim Auffüllen:
|
||||
for i, (px, py) in enumerate(trinkbrunnen_positions):
|
||||
brunnen_rect = pygame.Rect(px, py, 20, 20)
|
||||
if player_rect.colliderect(brunnen_rect) and not used_brunnen[i] and player.ammo < MAX_AMMO:
|
||||
player.ammo += 3
|
||||
used_brunnen[i] = True # Brunnen blockieren
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
font = pygame.font.SysFont(None, 32)
|
||||
ammo_text = font.render(f"Wasser: {player.ammo}", True, (0, 0, 255))
|
||||
WIN.blit(ammo_text, (20, 20))
|
||||
|
||||
|
||||
|
||||
pygame.display.update()
|
||||
|
||||
if not player.alive:
|
||||
show_lose_screen(WIN)
|
||||
running = False
|
||||
|
|
@ -127,5 +181,6 @@ def main():
|
|||
pygame.quit()
|
||||
sys.exit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue