-
Notifications
You must be signed in to change notification settings - Fork 13
/
UpdatingVillagerSim.py
102 lines (76 loc) · 2.91 KB
/
UpdatingVillagerSim.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
90
91
92
93
94
95
96
97
98
99
100
101
102
#!python2
"""This will basically be a rewrite of the original file,
but this time with a focus on clean code and commenting."""
import sys
import pygame
import gametools.vector2
import TileFuncs
import World
import DebugTools
def run(fullscreen, world_size=64):
"""The main function to run the program.
Args:
fullscreen: Boolean value that determines if the program is
in fullscreen mode.
world_size: Integer (power of 2) value that determines the
dimensions of the game world in terms of tiles.
Returns:
None
"""
pygame.init()
screen_size = (1280, 720)
if fullscreen:
screen_size = pygame.display.list_modes()[0]
if screen_size[0] > 1920:
screen_size = (1920, 1080)
screen = pygame.display.set_mode(screen_size,
pygame.FULLSCREEN | pygame.HWSURFACE)
else:
screen = pygame.display.set_mode(screen_size, 0)
game_world = World.World((world_size, world_size), screen_size)
pygame.display.set_caption("Villager Sim")
# Tick the clock once to avoid one huge tick when the game starts
game_world.clock.tick()
pause = False
done = False
while not done:
# Cap the game at 60 fps
time_passed_seconds = game_world.clock.tick(60) / 1000.0
pos = gametools.vector2.Vector2(*pygame.mouse.get_pos())
for event in pygame.event.get():
# Close button clicked
if event.type == pygame.QUIT:
done = True
elif event.type == pygame.KEYDOWN:
# Escape key pressed
if event.key == pygame.K_ESCAPE:
done = True
elif event.key == pygame.K_SPACE:
pause = not pause
elif event.key == pygame.K_F3:
pygame.image.save(game_world.world_surface, "FullScreenshot.png")
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 3:
entity = TileFuncs.get_entity(game_world, pos)
if entity is not None:
# Toggle the entity info
entity[1].active_info = not entity[1].active_info
if pygame.mouse.get_pressed()[0]:
# check to see if the user is clicking on the minimap and update position accordingly
game_world.check_minimap_update(pos)
# Process everything in the game world
if not pause:
game_world.process(time_passed_seconds)
# Clear the screen, then draw the world onto it
screen.fill((0, 0, 0))
game_world.render_all(screen)
# Update the screen
pygame.display.update()
pygame.quit()
if __name__ == "__main__":
if len(sys.argv) == 2:
run(bool(int(sys.argv[1])))
elif len(sys.argv) >= 3:
run(bool(int(sys.argv[1])), int(sys.argv[2]))
else:
run(True, 128)