The code for mouse click is
frame.set_mouseclick_handler(mouseclick_handler)
# The position argument is a tuple with two integers
def mouseclick_handler(position):
pass
Don’t write code all at once. Write a bit, debug it.
Make a copy of list: list(pos)
canvas.draw_image(image, center_source, width_height_source, center_dest,
width_height_dest)
Dictionary is not considered to be ordered. Dictionary can have boolean as its key like:
d = {True : 1}
The keys have to immutable.
We need a state machine to record current state. At state 2, when 2 cards are open, we need to check if we will leave the card open.
# Constructor
__init__
# String method
__str__
When you see an type error, use type to check the object type.
Card - rand and suit
Hand - collection of cards method: hit, score
Deck - collection of cards method: shuffle, deal
canvas.draw_image(tiled_image, …) Use dropbox, Add dl=1 at the end of address. Always test on a different computer, because image will be cached.
self.angle # ship orientation
self.angle_vec # ship's angular speed
Position - point velocity - vector acceleration - vector
position += velocity
velocity += acceleration
self.pos[0] += self.vel[0]
self.pos[1] += self.vel[1]
forward = [math.cos(self.angle), math.sin(self.angle)]
if self.thrust:
self.vel[0] += forward[0]
self.vel[1] += forward[1]
With friction
self.pos[0] += self.vel[0]
self.pos[1] += self.vel[1]
self.vel[0] *= 1-c
self.vel[1] *= 1-c
forward = [math.cos(self.angle), math.sin(self.angle)]
if self.thrust:
self.vel[0] += forward[0]
self.vel[1] += forward[1]
simplegui.load_sound
Set color transparancy demo
rgba(255, 0, 0, 0.5)
Basically idea is first to draw the image and update it, and next time it will draw the updated image.
def draw(canvas):
a_rock.draw()
a_rock.updates()
code reuse, use dictionary, avoid magic constants.