-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (47 loc) · 1.58 KB
/
Copy pathmain.py
File metadata and controls
67 lines (47 loc) · 1.58 KB
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
from simulator import *
import pygame
# set number of people playing
N_PLAYERS = 2
N_CPUS = 0
N_CELLS = N_PLAYERS + N_CPUS
# set size and properties of grid
LX, LY = 100, 100
px_w = 5
edge_w = 0
wrap = True
# set cell start pattern (either 'circle' or 'random')
start_pattern = 'circle'
# set whether bullets wrap
wrap_bullets = True
target_vols = [300] * (N_PLAYERS + N_CPUS)
# keys for [up, down, left, right, fire]
player_keys = {
1: [pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT, pygame.K_SPACE],
2: [pygame.K_w, pygame.K_s, pygame.K_a, pygame.K_d, pygame.K_LSHIFT],
3: [pygame.K_y, pygame.K_h, pygame.K_g, pygame.K_j, pygame.K_t],
4: [pygame.K_p, pygame.K_SEMICOLON, pygame.K_l, pygame.K_QUOTE, pygame.K_o]
}
# this is packaged into a method so it can be later called to restart
def create_game():
state = State(LX, LY, N_CELLS, colors=None, target_vols=target_vols, start_pattern=start_pattern, wrap=wrap,
wrap_bullets=wrap_bullets)
for i in range(1, N_PLAYERS+1):
state.add_player(i, player_keys[i])
return state
state = create_game()
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (0, 0)
pygame.init()
surface = pygame.display.set_mode((LX * px_w, LY * px_w))
clock = pygame.time.Clock()
while True:
pygame.event.get()
keys = pygame.key.get_pressed()
if keys[pygame.K_p]:
continue
# press ESC to restart
if keys[pygame.K_ESCAPE]:
state = create_game()
for _ in range(1000):
cell_MC_step(state)
state.step_bullets()
draw_grid(surface, state, px_w=px_w, edge_w=edge_w)