-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
74 lines (60 loc) · 1.82 KB
/
main.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
import Tkinter as tk # Python 2
import time
import os
import random
import utils
import Gif
import Organism
import World
import datetime
start_time = datetime.datetime.now()
def update_func(world, organism):
# choose gif based on direction
organism.gif_num = 0
if organism.v_x < 0:
organism.gif_num = 1
# update frame in gif
organism.loop_gif_update()
# update the velocity, this accelerates the sprite in the current direction
accel = 0.5
if organism.v_x > 0:
organism.v_x += accel
else:
organism.v_x -= accel
if organism.defy_gravity or utils.touching_borders(world, organism):
if organism.v_y > 0:
organism.v_y += accel
else:
organism.v_y -= accel
# react upon hitting the screen edges
if utils.hit_left(world, organism):
print "OW!"
organism.v_x = accel
elif utils.hit_right(world, organism):
print "DAMMIT!"
organism.v_x = -accel
if utils.hit_top(world, organism):
print "P**********!"
organism.v_y = -accel
elif utils.hit_bottom(world, organism):
print "..."
# make a jump
organism.v_y = 10
def click_handler(event, organism):
print "i have been saved!"
organism.being_held = True
def move_handler(event, organism):
organism.x = event.x_root
organism.y = event.y_root
def release_handler(event, organism):
organism.being_held = False
print "oh no, out of control again!!"
if __name__ == '__main__':
# setup the sprite
gif_names = ["gifs/bird_right.gif", "gifs/bird_left.gif"]
organism = Organism.Organism(update_func, 60, 60, gif_names,click_handler, move_handler, release_handler)
organism.frame_interval = 50
# setup and run the world
w = World.World()
w.add_organism(organism)
w.start()