import pygame import random import math import sys # ================== הגדרות ================== pygame.init() WIDTH, HEIGHT = 1000, 700 # מסך גדול יותר למדבר screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("קאובוי במדבר: ירייה בזומבים! 🏜️🧟‍♂️🔫") clock = pygame.time.Clock() # צבעים SAND = (210, 180, 140) # חול מדבר SKY = (135, 206, 235) # שמיים כחולים BROWN = (139, 69, 19) # חום קאובוי BLACK = (0, 0, 0) WHITE = (255, 255, 255) GREEN_TREE = (34, 139, 34) # ירוק עצים RED_BLOOD = (139, 0, 0) # דם אדום ZOMBIE_GREEN = (0, 128, 0) ZOMBIE_PURPLE = (128, 0, 128) # shooter ZOMBIE_RED = (200, 0, 0) # runner # פונט font_big = pygame.font.SysFont("Arial", 48, bold=True) font_small = pygame.font.SysFont("Arial", 24) # שחקן player_pos = [WIDTH // 2, HEIGHT - 100] player_speed = 6 player_size = 40 player_health = 100 player_max_health = 100 # זומבים zombies = [] zombie_spawn_rate = 0.03 # כדורים bullets = [] bullet_speed = 12 bullet_size = 6 # פרטיקלי דם blood_particles = [] particle_speed = 5 # עצים/קקטוסים (סטטיים) trees = [] for _ in range(15): # 15 עצים/שיחים trees.append([random.randint(50, WIDTH-100), random.randint(HEIGHT//2, HEIGHT-100)]) # ניקוד score = 0 # משתנים משחק game_over = False running = True def draw_tree(x, y): # גזע pygame.draw.rect(screen, BROWN, (x-10, y-40, 20, 40)) # עלים/קוצים pygame.draw.circle(screen, GREEN_TREE, (x, y-60), 30) pygame.draw.circle(screen, GREEN_TREE, (x-20, y-40), 25) pygame.draw.circle(screen, GREEN_TREE, (x+20, y-40), 25) def draw_player(px, py): # גוף pygame.draw.rect(screen, BROWN, (px, py, player_size, player_size + 20)) # ראש pygame.draw.circle(screen, (255, 220, 177), (px + player_size//2, py - 5), 18) # כובע pygame.draw.rect(screen, BLACK, (px + 5, py - 35, player_size - 10, 25)) # חגורה pygame.draw.rect(screen, BLACK, (px + 5, py + player_size//2, player_size - 10, 8)) def draw_zombie(z): x, y, ztype, speed = z if ztype == "walker": color = ZOMBIE_GREEN size = 35 elif ztype == "runner": color = ZOMBIE_RED size = 40 else: # shooter color = ZOMBIE_PURPLE size = 38 pygame.draw.rect(screen, color, (x - size//2, y - size//2, size, size)) pygame.draw.circle(screen, (150, 50, 50), (x, y - 10), 12) # ראש def create_bullets(px, py, mx, my): dx = mx - px dy = my - py dist = math.hypot(dx, dy) if dist != 0: dx, dy = dx / dist, dy / dist bullets.append([px, py, dx * bullet_speed, dy * bullet_speed]) def create_blood(x, y): for _ in range(10): angle = random.uniform(0, 2 * math.pi) speed = random.uniform(2, particle_speed) blood_particles.append([x, y, math.cos(angle) * speed, math.sin(angle) * speed, random.randint(5, 12)]) def draw_blood(): for p in blood_particles[:]: p[0] += p[2] p[1] += p[3] p[4] -= 0.3 # כיווץ if p[4] > 0: pygame.draw.circle(screen, RED_BLOOD, (int(p[0]), int(p[1])), int(p[4])) else: blood_particles.remove(p) def show_text(text, x, y, font, color=WHITE): txt = font.render(text, True, color) screen.blit(txt, (x - txt.get_width()//2, y)) # ================== לולאת המשחק ================== while running: mx, my = pygame.mouse.get_pos() # עכבר לירייה for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.MOUSEBUTTONDOWN and not game_over: create_bullets(player_pos[0] + player_size//2, player_pos[1] + player_size//2, mx, my) if not game_over: # תנועת שחקן (חצים + WASD) keys = pygame.key.get_pressed() if keys[pygame.K_LEFT] or keys[pygame.K_a]: player_pos[0] -= player_speed if keys[pygame.K_RIGHT] or keys[pygame.K_d]: player_pos[0] += player_speed if keys[pygame.K_UP] or keys[pygame.K_w]: player_pos[1] -= player_speed if keys[pygame.K_DOWN] or keys[pygame.K_s]: player_pos[1] += player_speed # גבולות player_pos[0] = max(0, min(WIDTH - player_size, player_pos[0])) player_pos[1] = max(0, min(HEIGHT - player_size - 20, player_pos[1])) # ספאון זומבים if random.random() < zombie_spawn_rate: x = random.choice([random.randint(-50, 0), random.randint(WIDTH, WIDTH+50)]) y = random.randint(-60, 0) ztype = random.choice(["walker", "runner", "shooter"]) speed = 1.5 if ztype == "walker" else 4 if ztype == "runner" else 2.2 zombies.append([x, y, ztype, speed]) # תנועת זומבים לכיוון שחקן for z in zombies[:]: dx = player_pos[0] + player_size//2 - z[0] dy = player_pos[1] + player_size//2 - z[1] dist = math.hypot(dx, dy) if dist != 0: z[0] += (dx / dist) * z[3] z[1] += (dy / dist) * z[3] # פגיעה בשחקן if math.hypot(z[0] - (player_pos[0] + player_size//2), z[1] - (player_pos[1] + player_size//2)) < 35: player_health -= 1 zombies.remove(z) if player_health <= 0: game_over = True # תנועת כדורים + פגיעות for b in bullets[:]: b[0] += b[2] b[1] += b[3] if b[0] < 0 or b[0] > WIDTH or b[1] < 0 or b[1] > HEIGHT: bullets.remove(b) continue for z in zombies[:]: if math.hypot(b[0] - z[0], b[1] - z[1]) < 25: create_blood(z[0], z[1]) zombies.remove(z) bullets.remove(b) score += 10 if z[2] == "walker" else 20 if z[2] == "runner" else 30 break # ציור # רקע שמיים → חול for i in range(HEIGHT//2): color = [int(SKY[j] + (SAND[j] - SKY[j]) * i / (HEIGHT//2)) for j in range(3)] pygame.draw.line(screen, color, (0, i), (WIDTH, i)) screen.fill(SAND, (0, HEIGHT//2, WIDTH, HEIGHT//2)) # עצים for tree in trees: draw_tree(tree[0], tree[1]) draw_blood() if not game_over: draw_player(player_pos[0], player_pos[1]) for z in zombies: draw_zombie(z) # כדורים for b in bullets: pygame.draw.circle(screen, (255, 255, 0), (int(b[0]), int(b[1])), bullet_size) # כדורים צהובים # UI show_text(f"ניקוד: {score}", 100, 40, font_big, BLACK) show_text(f"בריאות: {player_health}", WIDTH - 200, 40, font_big, RED_BLOOD) show_text("חצים/WASD: תנועה | עכבר: כוון וקליק: ירייה!", WIDTH//2, 30, font_small, BLACK) else: show_text("GAME OVER!", WIDTH//2, HEIGHT//2 - 50, font_big, RED_BLOOD) show_text(f"ניקוד סופי: {score}", WIDTH//2, HEIGHT//2 + 20, font_big, BLACK) show_text("לחץ ESC לצאת", WIDTH//2, HEIGHT//2 + 80, font_small, WHITE) pygame.display.flip() clock.tick(60) pygame.quit() sys.exit()