KatrinaMagyarWeek7AssignmentGame.py - import pygame import...

This preview shows page 1 - 2 out of 2 pages.

import pygameimport randomimport syspygame.init()WIDTH = 800HEIGHT = 600PINK = (255, 0, 153)GREEN = (72, 198, 58)YELLOW = (255, 255, 0)PURPLE = (238, 32, 253)BLACK = (0, 0, 0)BACKGROUND_COLOR = (33, 102, 172)player_size = 50player_pos = [WIDTH/2, HEIGHT-2*player_size]enemy_size = 50enemy_pos = [random.randint(0, WIDTH-enemy_size), 0]enemy_list = [enemy_pos]SPEED = 10screen = pygame.display.set_mode((WIDTH, HEIGHT))game_over = Falsescore = 0clock = pygame.time.Clock()myFont = pygame.font.SysFont("lucidasanstypewriterregular", 30)def set_level(score, SPEED):if score < 20:SPEED = 7elif score < 40:SPEED = 9elif score < 60:SPEED = 12else:SPEED = score/5 + 1return SPEEDdef drop_enemies(enemy_list):delay = random.random()if len(enemy_list) < 10 and delay < 0.2:x_pos = random.randint(0, WIDTH-enemy_size)y_pos = 0enemy_list.append([x_pos, y_pos])def draw_enemies(enemy_list):for enemy_pos in enemy_list:pygame.draw.rect(screen, GREEN, (enemy_pos[0], enemy_pos[1], enemy_size,enemy_size))def update_enemy_positions(enemy_list, score):for idx, enemy_pos in enumerate(enemy_list):if enemy_pos[1] >= 0 and enemy_pos[1] < HEIGHT:enemy_pos[1] += SPEEDelse:enemy_list.pop(idx)score += 1return score

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture