Compare commits
No commits in common. "d5d2781f6325a0942e3fb3aefe59a1049e2293ba" and "55def84e5e603ae84728f205d0c7a9e3d0889ee3" have entirely different histories.
d5d2781f63
...
55def84e5e
2 changed files with 4 additions and 60 deletions
|
|
@ -9,7 +9,6 @@ class Player:
|
||||||
self.rect = pygame.Rect(x, y, PLAYER_SIZE, PLAYER_SIZE)
|
self.rect = pygame.Rect(x, y, PLAYER_SIZE, PLAYER_SIZE)
|
||||||
self.dir = "up"
|
self.dir = "up"
|
||||||
self.image = image
|
self.image = image
|
||||||
self.ammo = 5 # Startwert für Munition
|
|
||||||
|
|
||||||
def move(self, keys, map_w, map_h):
|
def move(self, keys, map_w, map_h):
|
||||||
if not self.alive:
|
if not self.alive:
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,6 @@ from settings import PLAYER_SIZE, MAP_PATH, WIDTH, HEIGHT, MINIMAP_MARGIN
|
||||||
|
|
||||||
DEBUG = False
|
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()
|
pygame.init()
|
||||||
# logo_img = pygame.image.load("images/logo.png")
|
# logo_img = pygame.image.load("images/logo.png")
|
||||||
# pygame.display.set_icon(logo_img)
|
# pygame.display.set_icon(logo_img)
|
||||||
|
|
@ -25,9 +19,6 @@ pygame.display.set_caption("Wasser der Regierung")
|
||||||
logo_img = pygame.image.load("images/Wasser_der_Regierung.PNG")
|
logo_img = pygame.image.load("images/Wasser_der_Regierung.PNG")
|
||||||
pygame.display.set_icon(logo_img)
|
pygame.display.set_icon(logo_img)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def load_map(path):
|
def load_map(path):
|
||||||
try:
|
try:
|
||||||
arr = rasterio.open(path).read(1)
|
arr = rasterio.open(path).read(1)
|
||||||
|
|
@ -41,22 +32,12 @@ def load_map(path):
|
||||||
print(f"Map load error: {e}")
|
print(f"Map load error: {e}")
|
||||||
return None, WIDTH, HEIGHT
|
return None, WIDTH, HEIGHT
|
||||||
|
|
||||||
|
|
||||||
map_surface, MAP_W, MAP_H = load_map(MAP_PATH)
|
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_WIDTH = 200
|
||||||
MINIMAP_HEIGHT = int(MAP_H / MAP_W * MINIMAP_WIDTH)
|
MINIMAP_HEIGHT = int(MAP_H / MAP_W * MINIMAP_WIDTH)
|
||||||
|
|
||||||
|
|
||||||
def draw_minimap(win, map_surface, player, enemies, bottles):
|
def draw_minimap(win, map_surface, player, enemies, bottles):
|
||||||
mini = pygame.transform.smoothscale(map_surface, (MINIMAP_WIDTH, MINIMAP_HEIGHT))
|
mini = pygame.transform.smoothscale(map_surface, (MINIMAP_WIDTH, MINIMAP_HEIGHT))
|
||||||
|
|
||||||
win.blit(mini, (WIDTH - MINIMAP_WIDTH - MINIMAP_MARGIN, MINIMAP_MARGIN))
|
win.blit(mini, (WIDTH - MINIMAP_WIDTH - MINIMAP_MARGIN, MINIMAP_MARGIN))
|
||||||
|
|
||||||
def map2mini(x, y):
|
def map2mini(x, y):
|
||||||
|
|
@ -72,7 +53,6 @@ def draw_minimap(win, map_surface, player, enemies, bottles):
|
||||||
for bottle in bottles:
|
for bottle in bottles:
|
||||||
pygame.draw.circle(win, (0, 180, 255), map2mini(bottle.x, bottle.y), 3)
|
pygame.draw.circle(win, (0, 180, 255), map2mini(bottle.x, bottle.y), 3)
|
||||||
|
|
||||||
|
|
||||||
def show_win_screen(win):
|
def show_win_screen(win):
|
||||||
win.fill((40, 180, 80))
|
win.fill((40, 180, 80))
|
||||||
font = pygame.font.SysFont(None, 72)
|
font = pygame.font.SysFont(None, 72)
|
||||||
|
|
@ -81,7 +61,6 @@ def show_win_screen(win):
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
pygame.time.wait(5000)
|
pygame.time.wait(5000)
|
||||||
|
|
||||||
|
|
||||||
def show_lose_screen(win):
|
def show_lose_screen(win):
|
||||||
win.fill((180, 40, 40))
|
win.fill((180, 40, 40))
|
||||||
font = pygame.font.SysFont(None, 72)
|
font = pygame.font.SysFont(None, 72)
|
||||||
|
|
@ -98,9 +77,7 @@ def main():
|
||||||
human_img = load_img(HUMAN_IMG_PATH, (PLAYER_SIZE, PLAYER_SIZE))
|
human_img = load_img(HUMAN_IMG_PATH, (PLAYER_SIZE, PLAYER_SIZE))
|
||||||
|
|
||||||
player = Player(MAP_W // 2, MAP_H // 2, player_img)
|
player = Player(MAP_W // 2, MAP_H // 2, player_img)
|
||||||
enemies = [
|
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)]
|
||||||
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 = []
|
bottles = []
|
||||||
minimap_visible = True
|
minimap_visible = True
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|
@ -112,13 +89,7 @@ def main():
|
||||||
running = False
|
running = False
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_SPACE:
|
if event.key == pygame.K_SPACE:
|
||||||
|
|
||||||
if player.ammo > 0:
|
|
||||||
bottles.append(TapWater(player.x, player.y, player.dir))
|
bottles.append(TapWater(player.x, player.y, player.dir))
|
||||||
player.ammo -= 1
|
|
||||||
else:
|
|
||||||
print("Keine Munition!")
|
|
||||||
|
|
||||||
if event.key == pygame.K_m:
|
if event.key == pygame.K_m:
|
||||||
minimap_visible = not minimap_visible
|
minimap_visible = not minimap_visible
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
|
|
@ -135,13 +106,10 @@ def main():
|
||||||
bottles = [b for b in bottles if 0 <= b.x <= MAP_W and 0 <= b.y <= MAP_H]
|
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))
|
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))
|
oy = max(0, min(player.y + PLAYER_SIZE // 2 - HEIGHT // 2, MAP_H - HEIGHT))
|
||||||
if scaled_map:
|
if map_surface:
|
||||||
WIN.blit(scaled_map, (0, 0), area=pygame.Rect(ox, oy, WIDTH, HEIGHT))
|
WIN.blit(map_surface, (0, 0), area=pygame.Rect(ox, oy, WIDTH, HEIGHT))
|
||||||
else:
|
else:
|
||||||
WIN.fill((255, 255, 255))
|
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)
|
player.draw(WIN, ox, oy)
|
||||||
for bottle in bottles:
|
for bottle in bottles:
|
||||||
bottle.draw(WIN, ox, oy)
|
bottle.draw(WIN, ox, oy)
|
||||||
|
|
@ -149,29 +117,7 @@ def main():
|
||||||
enemy.draw(WIN, ox, oy)
|
enemy.draw(WIN, ox, oy)
|
||||||
if minimap_visible:
|
if minimap_visible:
|
||||||
draw_minimap(WIN, map_surface, player, enemies, bottles)
|
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()
|
pygame.display.update()
|
||||||
|
|
||||||
if not player.alive:
|
if not player.alive:
|
||||||
show_lose_screen(WIN)
|
show_lose_screen(WIN)
|
||||||
running = False
|
running = False
|
||||||
|
|
@ -181,6 +127,5 @@ def main():
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue