spacegame/main.py

88 lines
3.2 KiB
Python

import pygame
import sys
import button
import random
def main():
pygame.init()
screen = pygame.display.set_mode((1000,700))
pygame.display.set_caption("Space game")
icon = pygame.image.load("ICON.png")
pygame.display.set_icon(icon)
background = pygame.image.load("space.jpg")
# background = pygame.transform.scale(background, (1000,700))
hangar = pygame.image.load("HANGAR.jpg")
#text
font = pygame.font.Font("KodeMono-Medium.ttf", 32)
smaller_font = pygame.font.Font("KodeMono-Medium.ttf", 24)
over_font = pygame.font.Font("KodeMono-Medium.ttf", 96)
text_color = (255, 255, 255)
#button
new_game_img = pygame.image.load("new_game.png")
difficulty_img = pygame.image.load("difficulty.png")
difficulty_easy_img = pygame.image.load("difficulty_easy.png")
difficulty_medium_img = pygame.image.load("difficulty_medium.png")
difficulty_hard_img = pygame.image.load("difficulty_hard.png")
difficulty_insane_img = pygame.image.load("difficulty_insane.png")
best_score_img = pygame.image.load("best_score.png")
back_img = pygame.image.load("back.png")
new_game_button = button.Button(400, 320, new_game_img, 1)
difficulty_button = button.Button(400, 410, difficulty_img, 1)
best_score_button = button.Button(400, 500, best_score_img, 1)
back_button = button.Button(400, 580, back_img, 1)
difficulty_buttons = [
button.Button(290, 150, difficulty_easy_img, 1),
button.Button(510, 150, difficulty_medium_img, 1),
button.Button(290, 250, difficulty_hard_img, 1),
button.Button(510, 250, difficulty_insane_img, 1)
]
scene = "menu"
game_paused = False
game_lost = False
running = True
difficulty = 0
def draw_text(text, font, text_col, x, y):
text = font.render(text, True, text_col)
screen.blit(text, (x, y))
while running:
match scene:
case "menu":
screen.blit(hangar, (0, 0)) #menu
if new_game_button.draw(screen):
scene = "game"
if difficulty_button.draw(screen):
scene = "difficulty"
if best_score_button.draw(screen):
scene = "best_score"
case "best_score":
screen.blit(hangar, (0, 0))
print_best_score(best_score[difficulty])
if back_button.draw(screen):
scene = "menu"
case "difficulty":
screen.blit(hangar, (0, 0))
draw_text("Choose the difficulty", font, text_color, 350, 50)
for i in range(0, len(difficulty_buttons)):
if difficulty_buttons[i].draw(screen):
difficulty = i
scene = "menu"
if back_button.draw(screen):
scene = "menu"
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.blit(background, (0, 0))
pygame.display.flip()