-
Notifications
You must be signed in to change notification settings - Fork 0
/
catGo.py
58 lines (41 loc) · 1.19 KB
/
catGo.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
# from trepan.api import debug
# import pdb
# pdb.set_trace()
import runWorld as rw
import drawWorld as dw
# Initialize world
name = "Cat Go!"
width = 500
height = 500
rw.newDisplay(width, height, name)
# World state will be single x coordinate at left edge of world
initState = 0
# Display the state by drawing a cat at that x coordinate
myimage = dw.loadImage("cat.bmp")
# state -> image (IO)
def updateDisplay(state):
dw.fill(dw.black)
dw.draw(myimage, (state[0], height/2))
# We'll update the state on each tick by incrementing the x stateinate
# state -> state
def updateState(state):
return((state[0]+state[1], state[1]))
# We'll terminate when the x coordinate reaches the screen edge
# tells the simulation when it's over
# state -> bool
def endState(state):
if (state >= width):
return True
else:
return False
# For now we'll handle events just logging them to the console
# state -> event -> state
def handleEvent(state, event):
return((state[0],)
# Off we go! Start the cat at the left edge, and try for 30 FPS
#
initState = (0,1)
frameRate = 60
# debug()
rw.runWorld(initState, updateDisplay, updateState, handleEvent,
endState, frameRate)