-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.py
executable file
·89 lines (78 loc) · 3.06 KB
/
game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pygame, sys
import menu, instructions, about, stonehunt, stage, player, results
from pygame.locals import *
from constants import Container
def start(c):
# We create the screen surface
screen = pygame.display.set_mode((640,480), DOUBLEBUF | HWSURFACE, 32)
pygame.display.set_caption("StoneHunters - By RoCR [ To Gab ]")
icon = pygame.image.load("images/icon.png").convert_alpha()
pygame.display.set_icon(icon)
screen.fill((0, 10, 0))
# We specify for each import, the constant object as a global var
stonehunt.c = c
stage.c = c
player.c = c
about.c = c
instructions.c = c
menu.c = c
results.c = c
# We create the menu with this characteristics
# [text, method, type, None]
game_menu = menu.Menu([
["Hunt Stones", stonehunt.start, c.NORMAL, None],
["About the Game", about.start, c.NORMAL, None],
["Instructions", instructions.start, c.NORMAL, None],
["Options", options, c.OPTIONS, None],
["Quit Game", end, c.END, None]], c)
game_menu.center_at(320, 200)
c.MENU_SONG.play(-1) # Infinite loop the song
loop(game_menu, screen)
c.save_settings()
def loop(game_menu, screen):
'''Create a loop to show the menu in the screen suface.
It also catches the events to update the menu.
'''
running = True
clock = pygame.time.Clock()
while True:
clock.tick(30)
events = pygame.event.get()
if events:
if game_menu.update(events):
screen = pygame.display.set_mode((640,480),DOUBLEBUF | HWSURFACE, 32)
for e in events:
if e.type == pygame.QUIT:
return
elif e.type == pygame.KEYDOWN:
if e.key == pygame.K_ESCAPE:
return
screen.fill((50, 50, 50))
game_menu.draw(screen)
pygame.display.flip()
def end():
'''End of the game.'''
pygame.event.post(pygame.event.Event(pygame.QUIT,{}))
def options():
'''Shows the options submenu.
Thies method will be executed if the options option is selected in
the general menu.'''
screen = pygame.display.set_mode((640,480),DOUBLEBUF | HWSURFACE, 32)
screen.fill((50, 100, 0))
# It works identicall as the main menu but with more options to select
game_menu = menu.Menu([
#[text, variable_name, colour, [min, max, step, actual_value, sign]]
["Players", "PLAYERS", c.NORMAL, [2,3,1,c.PLAYERS, '']],
["Stage", "STAGE", c.NORMAL, [0,len(c.STAGES)-1,1,c.STAGE,'']],
["Spawn time", "SPAWN_TIME", c.NORMAL, [0,3,1,c.SPAWN_TIME,' s']],
["Goals", "GOALS", c.NORMAL, [1,10,1,c.GOALS,'']],
["Hunting time", "HUNTING_TIME", c.NORMAL, [20,60,5,c.HUNTING_TIME,' s']],
["Maximum FPS", "FPS", c.NORMAL, [20,60,5,c.FPS,'']],
["Back to Menu", end, c.END, None]], c)
game_menu.center_at(320, 200)
loop(game_menu, screen)
if __name__ == "__main__":
c = Container()
start(c)