-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathciv_builder.py
More file actions
67 lines (54 loc) · 1.89 KB
/
civ_builder.py
File metadata and controls
67 lines (54 loc) · 1.89 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
67
from Civilization import Civilization
from CivMap import CivMap
from random import randint
import pygame, sys
from pygame.locals import *
def run():
h, w = 15, 30
game_map = CivMap((w, h))
civ = Civilization("America", game_map, (randint(0,w - 1), randint(0,h - 1)))
display_surface = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Civ Builder")
pygame.key.set_repeat(0, 100)
clock = pygame.time.Clock()
paused = False
frames = 0
#game loop
while True:
#check for all types of events
for event in pygame.event.get():
if event.type == QUIT:
print(str(frames))
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == pygame.K_SPACE:
paused = not paused
if event.key == pygame.K_TAB:
for i in range(20): civ.expand()
#arbitrary expansion constant, replace soon
for i in range(round(len(civ.owned_tiles) / 10)): civ.expand()
frames += 1
draw_map(display_surface, game_map)
clock.tick(FPS)
pygame.display.update()
def draw_map(display_surface, game_map):
MARGIN = 20
side_l = round(min((WIDTH - 2 * MARGIN) / (game_map.width()),(HEIGHT - 2 * MARGIN) / (game_map.height())))
def draw_tile(tile):
x = MARGIN + (tile.loc[0] * (side_l))
y = MARGIN + (tile.loc[1] * (side_l))
pygame.draw.rect(display_surface, GREEN if tile.is_owned else RED, (x, y, side_l, side_l))
#draw all tiles that have been changed, then remove them from the changed list
for tile in game_map.updated_tiles:
draw_tile(tile)
game_map.updated_tiles.remove(tile)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
WIDTH = 960
HEIGHT = 540
FPS = 10
pygame.init()
run()