-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_societes.py
208 lines (143 loc) · 5.82 KB
/
copy_societes.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/python
# -*- coding:utf-8 -*-
import pygame, sys, Image
from pygame.locals import *
import map1
#---COLORS-------------------------
# R G B Alpha
WHITE = ( 255, 255, 255)
BLACK = ( 0, 0, 0)
BLUE = ( 0, 0, 255)
GREEN = ( 0, 255, 0)
RED = ( 255, 0, 0)
YELLOW = ( 255, 250, 60)
ORANGE = ( 255, 150, 30)
BROWN = ( 150, 50, 0)
INVISIBLE = ( 0, 0, 0, 0)
#------------------------------------------
# These variables won’t change
FPS = 30
FONT = 'freesansbold.ttf'
FONTSIZE = 16
LEFT = 'left'
RIGHT = 'right'
UP = 'up'
DOWN = 'down'
#---DRAWING THE SCREEN AND INTERFACE-------------------------
SCREENSIZEx = 1000
SCREENSIZEy = 600
HALFSCREENx = int(SCREENSIZEx / 2)
HALFSCREENy = int(SCREENSIZEy / 2)
INTERFACESIZEx = SCREENSIZEx
INTERFACESIZEy = 100
OUTTERFINISHBUTTONSIZE = 60
OUTTERFINISHBUTTONPOSx = 920
OUTTERFINISHBUTTONPOSy = SCREENSIZEy - (OUTTERFINISHBUTTONSIZE + 20)
INNERFINISHBUTTONSIZE = OUTTERFINISHBUTTONSIZE / 2
INNERFINISHBUTTONPOSx = OUTTERFINISHBUTTONPOSx + (OUTTERFINISHBUTTONSIZE / 4)
INNERFINISHBUTTONPOSy = OUTTERFINISHBUTTONPOSy + (OUTTERFINISHBUTTONSIZE / 4)
POPTEXTRIGHT = SCREENSIZEx - 50
POPTEXTTOP = 30
#---COLORING-------------------------------------------------------------
BGCOLOR = BLACK
INTERFACEZONECOLOR = ORANGE
OUTTERFINISHBUTTONCOLOR = BROWN
INNERFINISHBUTTONCOLOR = RED
#----------------------------------------------------------------------
pygame.init()
#----------------------------------------------------------------------
def main():
global FPSCLOCK, INVISIBLESURF, VISIBLESURF
FPSCLOCK = pygame.time.Clock()
mousex = 0
mousey = 0
fontObj = pygame.font.Font(FONT, FONTSIZE)
# Map information
# TODO: do wtf is the actual map (map needed as it’s a relique from old code)
theMap = map1.createMap()
# Calculate stuff about the faction
pop = 0 #TODO
# Make the screen.
INVISIBLESURF = pygame.display.set_mode((SCREENSIZEx, SCREENSIZEy))
VISIBLESURF = pygame.display.set_mode((SCREENSIZEx, SCREENSIZEy))
pygame.display.set_caption('Sociétés')
# The map image
invisibleMap = pygame.image.load('invisible_map.png')
visibleMap = pygame.image.load('visible_map.png')
slideTo = False # As of now, the map didn’t slide.
mapx = 0
mapy = 0
mapInfo = 'osef' #TODO
mainLoop(mapInfo, invisibleMap, visibleMap, mousex, mousey, fontObj, mapx, mapy, slideTo)
#---MAIN LOOP--------------------------------------------------------------
def mainLoop(mapInfo, invisibleMap, visibleMap, mousex, mousey, fontObj, mapx, mapy, slideTo):
while True: # main game loop
mouseClicked = False
# The map sliding.
if slideTo:
if slideTo == UP:
mapy = mapy - 30
elif slideTo == DOWN:
mapy = mapy + 30
elif slideTo == LEFT:
mapx = mapx - 30
elif slideTo == RIGHT:
mapx = mapx + 30
slideTo = False
INVISIBLESURF.blit(invisibleMap, ((mapx, mapy)))
VISIBLESURF.blit(visibleMap, ((mapx, mapy)))
pop = 0 #TODO
# Draw the interface
drawInterface(fontObj, pop)
# What happens?
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == MOUSEMOTION:
mousex, mousey = event.pos
elif event.type == MOUSEBUTTONUP:
if event.button == 1:
mouseClicked = True
mousex, mousey = event.pos
elif event.type == KEYUP: # camera moving
if event.key == K_RIGHT:
slideTo = LEFT
elif event.key == K_LEFT:
slideTo = RIGHT
elif event.key == K_DOWN:
slideTo = UP
elif event.key == K_UP:
slideTo = DOWN
# Where did you click? Was it on a region? What region?
smth = getSomethingAtPixel(mousex, mousey, mapx, mapy, OUTTERFINISHBUTTONPOSx, OUTTERFINISHBUTTONPOSy, OUTTERFINISHBUTTONSIZE)
if mouseClicked:
print '{}'.format(smth)
pygame.display.update()
FPSCLOCK.tick(FPS)
#----------------------------
def getSomethingAtPixel(x, y, mapx, mapy, OUTTERFINISHBUTTONPOSx, OUTTERFINISHBUTTONPOSy, OUTTERFINISHBUTTONSIZE):
smth = INVISIBLESURF.get_at((x, y))
return (smth)
nextButtonRect = pygame.Rect(OUTTERFINISHBUTTONPOSx, OUTTERFINISHBUTTONPOSy, OUTTERFINISHBUTTONSIZE, OUTTERFINISHBUTTONSIZE)
if nextButtonRect.collidepoint(x, y):
return ('finishButtonClick')
#----INTERFACE DRAWING--------------
def drawInterface(fontObj, pop):
# Draw the interface.
# It’s used in main.
interfaceZone()
finishButton()
someText(fontObj, pop)
def interfaceZone():
InterfaceRect = pygame.draw.rect(INVISIBLESURF, INTERFACEZONECOLOR, (0, (SCREENSIZEy - INTERFACESIZEy), INTERFACESIZEx, INTERFACESIZEy))
def finishButton():
OutterFinishButton = pygame.draw.rect(INVISIBLESURF, OUTTERFINISHBUTTONCOLOR, (OUTTERFINISHBUTTONPOSx, OUTTERFINISHBUTTONPOSy, OUTTERFINISHBUTTONSIZE, OUTTERFINISHBUTTONSIZE))
InnerFinishButton = pygame.draw.rect(INVISIBLESURF, INNERFINISHBUTTONCOLOR, (INNERFINISHBUTTONPOSx, INNERFINISHBUTTONPOSy, INNERFINISHBUTTONSIZE, INNERFINISHBUTTONSIZE))
def someText(fontObj, pop):
popTextSurface = fontObj.render('Population: {}'.format(pop), True, WHITE, INVISIBLE)
popTextRect = popTextSurface.get_rect()
popTextRect.right = POPTEXTRIGHT
popTextRect.top = POPTEXTTOP
#---------------------------
main()