-
Notifications
You must be signed in to change notification settings - Fork 4
/
demo_20181224_15h06.py
571 lines (461 loc) · 21.6 KB
/
demo_20181224_15h06.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
#
# World of Isotiles
# Author: nicolas.bredeche(at)sorbonne-universite.fr
#
# Started: 2018-11-17
# purpose: basic code developped for teaching artificial life and ecological simulation at Sorbonne Univ. (SU)
# course: L2, 2i013 Projet, "Vie Artificielle"
# licence: CC-BY-SA
#
# Requirements: Python3, Pygame
#
# Credits for third party resources used in this project:
# - Assets: https://www.kenney.nl/ (great assets by Kenney Vleugels with *public domain license*)
# - https://www.uihere.com/free-cliparts/space-invaders-extreme-2-video-game-arcade-game-8-bit-space-invaders-3996521
#
# Random bookmarks:
# - scaling images: https://stackoverflow.com/questions/43196126/how-do-you-scale-a-design-resolution-to-other-resolutions-with-pygame
# - thoughts on grid worlds: http://www-cs-students.stanford.edu/~amitp/game-programming/grids/
# - key pressed? https://stackoverflow.com/questions/16044229/how-to-get-keyboard-input-in-pygame
# - basic example to display tiles: https://stackoverflow.com/questions/20629885/how-to-render-an-isometric-tile-based-world-in-python
# - pygame key codes: https://www.pygame.org/docs/ref/key.html
# - pygame capture key combination: https://stackoverflow.com/questions/24923078/python-keydown-combinations-ctrl-key-or-shift-key
# - methods to initialize a 2D array: https://stackoverflow.com/questions/2397141/how-to-initialize-a-two-dimensional-array-in-python
# - bug with SysFont - cf. https://www.reddit.com/r/pygame/comments/1fhq6d/pygamefontsysfont_causes_my_script_to_freeze_why/
# myfont = pygame.font.SysFont(pygame.font.get_default_font(), 16)
# myText = myfont.render("Hello, World", True, (0, 128, 0))
# screen.blit(myText, (screenWidth/2 - text.get_width() / 2, screenHeight/2 - text.get_height() / 2))
# ... will fail.
#
# TODO list
# - double buffer
# - multiple agents
import sys
import datetime
from random import *
import math
import time
import pygame
from pygame.locals import *
###
versionTag = "2018-11-18_23h24"
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
nbTrees = 350 #350
nbBurningTrees = 1 #15
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
# display screen dimensions
screenWidth = 930 # 1400
screenHeight = 640 #900
# world dimensions (ie. nb of cells in total)
worldWidth = 64
worldHeight = 64
# set surface of displayed tiles (ie. nb of cells that are rendered) -- must be superior to worldWidth and worldHeight
viewWidth = 32 #32
viewHeight = 32 #32
scaleMultiplier = 0.25 # re-scaling of loaded images
objectMapLevels = 8 # number of levels for the objectMap. This determines how many objects you can pile upon one another.
# set scope of displayed tiles
xViewOffset = 0
yViewOffset = 0
addNoise = False
maxFps = 30 # set up maximum number of frames-per-second
verbose = False # display message in console on/off
verboseFps = True # display FPS every once in a while
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
pygame.init()
#pygame.key.set_repeat(5,5)
fpsClock = pygame.time.Clock()
screen = pygame.display.set_mode((screenWidth, screenHeight), DOUBLEBUF)
pygame.display.set_caption('World of Isotiles')
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
def loadImage(filename):
global tileTotalWidthOriginal,tileTotalHeightOriginal,scaleMultiplier
image = pygame.image.load(filename).convert_alpha()
image = pygame.transform.scale(image, (int(tileTotalWidthOriginal*scaleMultiplier), int(tileTotalHeightOriginal*scaleMultiplier)))
return image
def loadAllImages():
global tileType, objectType, agentType
tileType = []
objectType = []
agentType = []
tileType.append(loadImage('assets/basic111x128/platformerTile_48_ret.png')) # grass
tileType.append(loadImage('assets/ext/isometric-blocks/PNG/Platformer tiles/platformerTile_33.png')) # brick
tileType.append(loadImage('assets/ext/isometric-blocks/PNG/Abstract tiles/abstractTile_12.png')) # blue grass (?)
tileType.append(loadImage('assets/ext/isometric-blocks/PNG/Abstract tiles/abstractTile_09.png')) # grey brock
objectType.append(None) # default -- never drawn
objectType.append(loadImage('assets/basic111x128/tree_small_NW_ret.png')) # normal tree
objectType.append(loadImage('assets/basic111x128/blockHuge_N_ret.png')) # construction block
objectType.append(loadImage('assets/basic111x128/tree_small_NW_ret_red.png')) # burning tree
agentType.append(None) # default -- never drawn
agentType.append(loadImage('assets/basic111x128/invader_ret.png')) # invader
agentType.append(loadImage('assets/basic111x128/ghost_pinky.png')) # purple ghost
agentType.append(loadImage('assets/basic111x128/baby.png')) # baby
def resetImages():
global tileTotalWidth, tileTotalHeight, tileTotalWidthOriginal, tileTotalHeightOriginal, scaleMultiplier, heightMultiplier, tileVisibleHeight
tileTotalWidth = tileTotalWidthOriginal * scaleMultiplier # width of tile image, as stored in memory
tileTotalHeight = tileTotalHeightOriginal * scaleMultiplier # height of tile image, as stored in memory
tileVisibleHeight = tileVisibleHeightOriginal * scaleMultiplier # height "visible" part of the image, as stored in memory
heightMultiplier = tileTotalHeight/2 # should be less than (or equal to) tileTotalHeight
loadAllImages()
return
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
# spritesheet-specific -- as stored on the disk ==> !!! here, assume 128x111 with 64 pixels upper-surface !!!
# Values will be updated *after* image loading and *before* display starts
tileTotalWidthOriginal = 111 # width of tile image
tileTotalHeightOriginal = 128 # height of tile image
tileVisibleHeightOriginal = 64 # height "visible" part of the image, i.e. top part without subterranean part
###
tileType = []
objectType = []
agentType = []
noObjectId = noAgentId = 0
grassId = 0
treeId = 1
burningTreeId = 3
invaderId = 1
ghostId = 2
babyId = 3
blockId = 2
###
# re-scale reference image size -- must be done *after* loading sprites
resetImages()
###
terrainMap = [x[:] for x in [[0] * worldWidth] * worldHeight]
heightMap = [x[:] for x in [[0] * worldWidth] * worldHeight]
objectMap = [ [ [ 0 for i in range(worldWidth) ] for j in range(worldHeight) ] for k in range(objectMapLevels) ]
agentMap = [x[:] for x in [[0] * worldWidth] * worldHeight]
###
# set initial position for display on screen
xScreenOffset = screenWidth/2 - tileTotalWidth/2
yScreenOffset = 3*tileTotalHeight # border. Could be 0.
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
def displayWelcomeMessage():
print ("")
print ("=-= =-= =-= =-= =-= =-= =-= =-= =-= =-= =-= =-= =-=")
print ("=-= World of Isotiles =-=")
print ("=-= =-=")
print ("=-= nicolas.bredeche(at)sorbonne-universite.fr =-=")
print ("=-= licence CC:BY:SA =-=")
print ("=-= =-= =-= =-= =-= =-= =-= =-= =-= =-= =-= =-= =-=")
print (">> v.",versionTag)
print ("")
print ("Screen resolution : (",screenWidth,",",screenHeight,")")
print ("World surface : (",worldWidth,",",worldHeight,")")
print ("View surface : (",viewWidth,",",viewHeight,")")
print ("Verbose all :",verbose)
print ("Verbose fps :",verboseFps)
print ("Maximum fps :",maxFps)
print ("")
print ("# Hotkeys:")
print ("\tcursor keys : move around (use shift for tile-by-tile move)")
print ("\tv : verbose mode")
print ("\tf : display frames-per-second")
print ("\to : decrease view surface")
print ("\tO : increase view surface")
print ("\ts : decrease scaling")
print ("\tS : increase scaling")
print ("\tESC : quit")
print ("")
return
def getWorldWidth():
return worldWidth
def getWorldHeight():
return worldHeight
def getViewWidth():
return viewWidth
def getViewHeight():
return viewHeight
def getTerrainAt(x,y):
return terrainMap[y][x]
def setTerrainAt(x,y,type):
terrainMap[y][x] = type
def getHeightAt(x,y):
return heightMap[y][x]
def setHeightAt(x,y,height):
heightMap[y][x] = height
def getObjectAt(x,y,level=0):
if level < objectMapLevels:
return objectMap[level][y][x]
else:
print ("[ERROR] getObjectMap(.) -- Cannot return object. Level does not exist.")
return 0
def setObjectAt(x,y,type,level=0): # negative values are possible: invisible but tangible objects (ie. no display, collision)
if level < objectMapLevels:
objectMap[level][y][x] = type
else:
print ("[ERROR] setObjectMap(.) -- Cannot set object. Level does not exist.")
return 0
def getAgentAt(x,y):
return agentMap[y][x]
def setAgentAt(x,y,type):
agentMap[y][x] = type
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
def render( it = 0 ):
global xViewOffset, yViewOffset
pygame.draw.rect(screen, (0,0,0), (0, 0, screenWidth, screenHeight), 0) # overkill - can be optimized. (most sprites are already "naturally" overwritten)
#pygame.display.update()
for y in range(getViewHeight()):
for x in range(getViewWidth()):
# assume: north-is-upper-right
xTile = ( xViewOffset + x + getWorldWidth() ) % getWorldWidth()
yTile = ( yViewOffset + y + getWorldHeight() ) % getWorldHeight()
heightNoise = 0
if addNoise == True: # add sinusoidal noise on height positions
if it%int(math.pi*2*199) < int(math.pi*199):
# v1.
heightNoise = math.sin(it/23+yTile) * math.sin(it/7+xTile) * heightMultiplier/10 + math.cos(it/17+yTile+xTile) * math.cos(it/31+yTile) * heightMultiplier
heightNoise = math.sin(it/199) * heightNoise
else:
# v2.
heightNoise = math.sin(it/13+yTile*19) * math.cos(it/17+xTile*41) * heightMultiplier
heightNoise = math.sin(it/199) * heightNoise
height = getHeightAt( xTile , yTile ) * heightMultiplier + heightNoise
xScreen = xScreenOffset + x * tileTotalWidth / 2 - y * tileTotalWidth / 2
yScreen = yScreenOffset + y * tileVisibleHeight / 2 + x * tileVisibleHeight / 2 - height
screen.blit( tileType[ getTerrainAt( xTile , yTile ) ] , (xScreen, yScreen)) # display terrain
for level in range(objectMapLevels):
if getObjectAt( xTile , yTile , level) > 0: # object on terrain?
screen.blit( objectType[ getObjectAt( xTile , yTile, level) ] , (xScreen, yScreen - heightMultiplier*(level+1) ))
if getAgentAt( xTile, yTile ) != 0: # agent on terrain?
screen.blit( agentType[ getAgentAt( xTile, yTile ) ] , (xScreen, yScreen - heightMultiplier ))
return
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
def initWorld():
global xAgent, yAgent, nbTrees, nbBurningTrees
# add a pyramid-shape building
building1TerrainMap = [
[ 2, 2, 2, 2 ],
[ 2, 3, 3, 2 ],
[ 2, 3, 3, 2 ],
[ 2, 2, 2, 2 ]
]
building1HeightMap = [
[ 1, 1, 1, 1 ],
[ 1, 2, 2, 1 ],
[ 1, 2, 2, 1 ],
[ 1, 1, 1, 1 ]
]
x_offset = 3
y_offset = 3
for x in range( len( building1TerrainMap[0] ) ):
for y in range( len( building1TerrainMap ) ):
setTerrainAt( x+x_offset, y+y_offset, building1TerrainMap[x][y] )
setHeightAt( x+x_offset, y+y_offset, building1HeightMap[x][y] )
setObjectAt( x+x_offset, y+y_offset, -1 ) # add a virtual object: not displayed, but used to forbid agent(s) to come here.
# add another pyramid-shape building with a tree on top
building2TerrainMap = [
[ 0, 2, 2, 2, 2, 2, 0 ],
[ 2, 2, 2, 2, 2, 2, 2 ],
[ 2, 2, 2, 2, 2, 2, 2 ],
[ 2, 2, 2, 2, 2, 2, 2 ],
[ 2, 2, 2, 2, 2, 2, 2 ],
[ 2, 2, 2, 2, 2, 2, 2 ],
[ 2, 2, 2, 2, 2, 2, 2 ],
[ 2, 2, 2, 2, 2, 2, 2 ],
[ 0, 2, 2, 2, 2, 2, 0 ]
]
building2HeightMap = [
[ 0, 1, 1, 1, 1, 1, 0 ],
[ 1, 1, 1, 1, 1, 1, 1 ],
[ 1, 2, 2, 2, 2, 2, 1 ],
[ 1, 2, 3, 3, 3, 2, 1 ],
[ 1, 2, 3, 4, 3, 2, 1 ],
[ 1, 2, 3, 3, 3, 2, 1 ],
[ 1, 2, 2, 2, 2, 2, 1 ],
[ 1, 1, 1, 1, 1, 1, 1 ],
[ 0, 1, 1, 1, 1, 1, 0 ]
]
x_offset = 4
y_offset = 13
for x in range( len( building2TerrainMap[0] ) ):
for y in range( len( building2TerrainMap ) ):
setTerrainAt( x+x_offset, y+y_offset, building2TerrainMap[y][x] )
setHeightAt( x+x_offset, y+y_offset, building2HeightMap[y][x] )
setObjectAt( x+x_offset, y+y_offset, -1 ) # add a virtual object: not displayed, but used to forbid agent(s) to come here.
setObjectAt( x_offset+3, y_offset+4, treeId )
for c in [(20,2),(30,2),(30,12),(20,12)]:
for level in range(0,objectMapLevels):
setObjectAt(c[0],c[1],blockId,level)
for i in range(9):
setObjectAt(21+i,2,blockId,objectMapLevels-1)
setObjectAt(21+i,12,blockId,objectMapLevels-1)
setObjectAt(20,3+i,blockId,objectMapLevels-1)
setObjectAt(30,3+i,blockId,objectMapLevels-1)
xAgent = yAgent = 0
while getTerrainAt(xAgent,yAgent) != 0:
xAgent = randint(0,getWorldWidth()-1)
yAgent = randint(0,getWorldHeight()-1)
setAgentAt(xAgent,yAgent,ghostId)
for i in range(nbTrees):
x = randint(0,getWorldWidth()-1)
y = randint(0,getWorldHeight()-1)
while getTerrainAt(x,y) != 0 or getObjectAt(x,y) != 0:
x = randint(0,getWorldWidth()-1)
y = randint(0,getWorldHeight()-1)
setObjectAt(x,y,treeId)
for i in range(nbBurningTrees):
x = randint(0,getWorldWidth()-1)
y = randint(0,getWorldHeight()-1)
while getTerrainAt(x,y) != 0 or getObjectAt(x,y) != 0:
x = randint(0,getWorldWidth()-1)
y = randint(0,getWorldHeight()-1)
setObjectAt(x,y,burningTreeId)
return
### ### ### ### ###
def initAgents():
return
### ### ### ### ###
def stepWorld( it = 0 ):
if it % (maxFps/10) == 0:
for x in range(worldWidth):
for y in range(worldHeight):
if getObjectAt(x,y) == treeId:
for neighbours in ((-1,0),(+1,0),(0,-1),(0,+1)):
if getObjectAt((x+neighbours[0]+worldWidth)%worldWidth,(y+neighbours[1]+worldHeight)%worldHeight) == burningTreeId:
setObjectAt(x,y,burningTreeId)
elif getAgentAt((x+neighbours[0]+worldWidth)%worldWidth,(y+neighbours[1]+worldHeight)%worldHeight) == ghostId:
setObjectAt(x,y,burningTreeId)
return
### ### ### ### ###
def stepAgents( it = 0 ):
global xAgent, yAgent
# move agent
if it % (maxFps/10) == 0:
xAgentNew = xAgent
yAgentNew = yAgent
if random() < 0.5:
xAgentNew = ( xAgent + [-1,+1][randint(0,1)] + getWorldWidth() ) % getWorldWidth()
else:
yAgentNew = ( yAgent + [-1,+1][randint(0,1)] + getWorldHeight() ) % getWorldHeight()
if getObjectAt(xAgentNew,yAgentNew) == 0: # dont move if collide with object (note that negative values means cell cannot be walked on)
setAgentAt(xAgent,yAgent,noAgentId)
xAgent = xAgentNew
yAgent = yAgentNew
setAgentAt(xAgent,yAgent,ghostId)
if verbose == True:
print (it,": agent(",xAgent,",",yAgent,")")
return
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
timestamp = datetime.datetime.now().timestamp()
loadAllImages()
displayWelcomeMessage()
initWorld()
initAgents()
print ("initWorld:",datetime.datetime.now().timestamp()-timestamp,"second(s)")
timeStampStart = timeStamp = datetime.datetime.now().timestamp()
it = itStamp = 0
userExit = False
while userExit == False:
if it != 0 and it % 100 == 0 and verboseFps:
print ("[fps] ", ( it - itStamp ) / ( datetime.datetime.now().timestamp()-timeStamp ) )
timeStamp = datetime.datetime.now().timestamp()
itStamp = it
#screen.blit(pygame.font.render(str(currentFps), True, (255,255,255)), (screenWidth-100, screenHeight-50))
render(it)
stepWorld(it)
stepAgents(it)
# continuous stroke
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and not ( keys[pygame.K_LSHIFT] or keys[pygame.K_RSHIFT] ):
xViewOffset = (xViewOffset - 1 + getWorldWidth() ) % getWorldWidth()
if verbose:
print("View at (",xViewOffset ,",",yViewOffset,")")
elif keys[pygame.K_RIGHT] and not ( keys[pygame.K_LSHIFT] or keys[pygame.K_RSHIFT] ):
xViewOffset = (xViewOffset + 1 ) % getWorldWidth()
if verbose:
print("View at (",xViewOffset ,",",yViewOffset,")")
elif keys[pygame.K_DOWN] and not ( keys[pygame.K_LSHIFT] or keys[pygame.K_RSHIFT] ):
yViewOffset = (yViewOffset + 1 ) % getWorldHeight()
if verbose:
print("View at (",xViewOffset,",",yViewOffset,")")
elif keys[pygame.K_UP] and not ( keys[pygame.K_LSHIFT] or keys[pygame.K_RSHIFT] ):
yViewOffset = (yViewOffset - 1 + getWorldHeight() ) % getWorldHeight()
if verbose:
print("View at (",xViewOffset,",",yViewOffset,")")
# single stroke
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYUP:
if event.key == K_ESCAPE:
userExit = True
elif event.key == pygame.K_n and pygame.key.get_mods() & pygame.KMOD_SHIFT:
addNoise = not(addNoise)
print ("noise is",addNoise) # easter-egg
elif event.key == pygame.K_v:
verbose = not(verbose)
print ("verbose is",verbose)
elif event.key == pygame.K_f:
verboseFps = not(verboseFps)
print ("verbose FPS is",verboseFps)
elif event.key == pygame.K_LEFT and pygame.key.get_mods() & pygame.KMOD_SHIFT:
xViewOffset = (xViewOffset - 1 + getWorldWidth() ) % getWorldWidth()
if verbose:
print("View at (",xViewOffset ,",",yViewOffset,")")
elif event.key == pygame.K_RIGHT and pygame.key.get_mods() & pygame.KMOD_SHIFT:
xViewOffset = (xViewOffset + 1 ) % getWorldWidth()
if verbose:
print("View at (",xViewOffset ,",",yViewOffset,")")
elif event.key == pygame.K_DOWN and pygame.key.get_mods() & pygame.KMOD_SHIFT:
yViewOffset = (yViewOffset + 1 ) % getWorldHeight()
if verbose:
print("View at (",xViewOffset,",",yViewOffset,")")
elif event.key == pygame.K_UP and pygame.key.get_mods() & pygame.KMOD_SHIFT:
yViewOffset = (yViewOffset - 1 + getWorldHeight() ) % getWorldHeight()
if verbose:
print("View at (",xViewOffset,",",yViewOffset,")")
elif event.key == pygame.K_o and not( pygame.key.get_mods() & pygame.KMOD_SHIFT ) :
if viewWidth > 1:
viewWidth = int(viewWidth / 2)
viewHeight = int(viewHeight / 2)
print (viewWidth)
if verbose:
print ("View surface is (",viewWidth,",",viewHeight,")")
elif event.key == pygame.K_o and pygame.key.get_mods() & pygame.KMOD_SHIFT:
if viewWidth < worldWidth :
viewWidth = viewWidth * 2
viewHeight = viewHeight * 2
if verbose:
print ("View surface is (",viewWidth,",",viewHeight,")")
elif event.key == pygame.K_s and not( pygame.key.get_mods() & pygame.KMOD_SHIFT ) :
if scaleMultiplier > 0.125:
scaleMultiplier = scaleMultiplier / 2
if scaleMultiplier < 0.125:
scaleMultiplier = 0.125
resetImages()
if verbose:
print ("scaleMultiplier is ",scaleMultiplier)
elif event.key == pygame.K_s and pygame.key.get_mods() & pygame.KMOD_SHIFT:
if scaleMultiplier < 1.0:
scaleMultiplier = scaleMultiplier * 2
if scaleMultiplier > 1.0:
scaleMultiplier = 1.0
resetImages()
if verbose:
print ("scaleMultiplier is ",scaleMultiplier)
pygame.display.flip()
fpsClock.tick(maxFps) # recommended: 30 fps
it += 1
fps = it / ( datetime.datetime.now().timestamp()-timeStampStart )
print ("[Quit] (", fps,"frames per second )")
pygame.quit()
sys.exit()