Ejemplo n.º 1
0
def play():
    global s
    s = S()

    engine.init_engine()
    engine.set_keyboard_handler(input_cb)
    engine.add_random_event(1.0, newpipe_cb)
    engine.register_collision(Me, Pipe, coll_cb)
    engine.register_collision(Pipe, Me, coll_cb2)

    s.me = Me()
    engine.add_obj(s.me)

    s.playing = True
    engine.engine()
Ejemplo n.º 2
0
def play():
	global s
	s = S()

	engine.init_engine()
	engine.set_keyboard_handler(input_cb)
	engine.add_random_event(1.0, newpipe_cb)
	engine.register_collision(Me, Pipe, coll_cb)
	engine.register_collision(Pipe, Me, coll_cb2)

	s.me = Me()
	engine.add_obj(s.me)

	s.playing = True
	engine.engine()
Ejemplo n.º 3
0
def play():
	global s
	s = S()

	engine.init_engine()
	engine.set_keyboard_handler(input_cb)

	s.me = Me()
	engine.add_random_event(0.01, leftturn_straight_cb)
	engine.add_random_event(0.01, rightturn_straight_cb)
	engine.add_obj(s.me)

	place_default_post_cb()

	engine.register_collision(Me, Post, col_post)
	engine.register_collision(Post, Me, col_post2)

	draw_text()
	draw_score()

	s.playing = True
	engine.engine()
Ejemplo n.º 4
0
def play():
    global s
    s = S()

    engine.init_engine()
    engine.set_keyboard_handler(input_cb)

    s.me = Me()
    engine.add_random_event(0.01, leftturn_straight_cb)
    engine.add_random_event(0.01, rightturn_straight_cb)
    engine.add_obj(s.me)

    place_default_post_cb()

    engine.register_collision(Me, Post, col_post)
    engine.register_collision(Post, Me, col_post2)

    draw_text()
    draw_score()

    s.playing = True
    engine.engine()
Ejemplo n.º 5
0
def play():
	global s
	s = S()

	engine.init_engine()
	engine.set_keyboard_handler(input_cb)

	s.me = Me()
	engine.add_obj(s.me)
	
	engine.add_random_event(0.01, spawn_asteroid_cb)

	engine.register_collision(Asteroid, MyShot, col_asteroid)
	engine.register_collision(MyShot, Asteroid, col_asteroid2)
	engine.register_collision(Me, Asteroid, col_gameover)
	engine.register_collision(Asteroid, Me, col_gameover)

	draw_score()

	s.playing = True
	engine.engine()
Ejemplo n.º 6
0
def play():
    global s
    s = S()

    engine.init_engine()
    engine.set_keyboard_handler(input_cb)

    s.me = Me()
    engine.add_obj(s.me)

    engine.add_random_event(0.01, spawn_asteroid_cb)

    engine.register_collision(Asteroid, MyShot, col_asteroid)
    engine.register_collision(MyShot, Asteroid, col_asteroid2)
    engine.register_collision(Me, Asteroid, col_gameover)
    engine.register_collision(Asteroid, Me, col_gameover)

    draw_score()

    s.playing = True
    engine.engine()
Ejemplo n.º 7
0
def play():
	global s
	s = S()

	engine.init_engine()
	engine.set_keyboard_handler(input_cb)
	engine.add_obj(Ground(MINX, GROUNDY, MAXX, MINY))

	s.me = Me(0, GROUNDY + 10)
	engine.add_obj(s.me)

	# the grid o' evil
	for i in range(INVADERROWS):
		for j in range(INVADERCOLS):
			enemy = Invader(XGRIDSTART + j * INVADERHSPACE,
					YGRIDSTART - i * INVADERVSPACE,
					INVADERSPEED, 0)
			s.invaders.append(enemy)
			engine.add_obj(enemy)
	engine.add_random_event(FIREPROB, fire_cb)
	engine.add_random_event(UFOPROB, ufo_cb)

	# not quite so random - do this at start of each time step
	# order is important - if no invaders left, gridmove won't be happy
	engine.add_random_event(1.0, winlose_cb)
	engine.add_random_event(1.0, gridmove_cb)

	engine.register_collision(Ground, Bomb, coll_ground1)
	engine.register_collision(Bomb, Ground, coll_ground2)
	engine.register_collision(UFO, MyShot, coll_air2air_bonus)
	engine.register_collision(MyShot, UFO, coll_air2air_bonus)
	engine.register_collision(Invader, MyShot, coll_air2air)
	engine.register_collision(MyShot, Invader, coll_air2air)
	engine.register_collision(Ground, Invader, coll_gameover1)
	engine.register_collision(Invader, Ground, coll_gameover2)
	engine.register_collision(Me, Bomb, coll_loselife1)
	engine.register_collision(Bomb, Me, coll_loselife2)

	draw_score()

	engine.engine()
Ejemplo n.º 8
0
		engine.del_obj(target)
		ntargets -= 1
		if ntargets == 0:
			win(timer.gettime())

def draw_score(time):
	turtle.goto(0, HEIGHT//2 - 25)
	turtle.dot(50, ROOFCOLOR)
	turtle.color('black')
	turtle.write(time, align='center', font=('Arial', 14, 'normal'))

def win(time):
	mesg = 'Time to complete: %d' % time
	turtle.goto(0, -30)
	turtle.color('black')
	turtle.write(mesg, True, align='center', font=('Arial', 24, 'italic'))

if __name__ == '__main__':
	engine.init_screen(WIDTH, HEIGHT)
	engine.init_engine()
	engine.set_keyboard_handler(input_cb)
	makescenery()
	makeguns()
	me = Gun()
	engine.add_obj(me)
	timer = Timer()
	engine.add_obj(timer)
	engine.register_collision(Shot, Target, coll1)
	engine.register_collision(Target, Shot, coll2)
	engine.engine()
Ejemplo n.º 9
0
def play(postfn=None):
    global s, score
    s = S()
    score = 0
    engine.add_obj(Ground(MINX, GROUNDY, MAXX, MINY))
    engine.add_random_event(0.002, Holes_cb)
    engine.add_random_event(0.007, Rocks_cb)
    engine.register_collision(Me, Holes, coll_Me)
    engine.register_collision(Holes, Me, coll_Me2)
    engine.register_collision(Me, Rocks, coll_Me)
    engine.register_collision(Rocks, Me, coll_Me2)
    engine.register_collision(Me, Rocks, coll_Me)
    engine.register_collision(Rocks, Me, coll_Me)
    engine.register_collision(missileside, Rocks, coll_missile)
    engine.register_collision(Rocks, missileside, coll_missile)

    draw_stars()
    draw_score()
    s.me = Me()
    engine.add_obj(s.me)

    s.playing = True
    if postfn:
        postfn()
    engine.engine()
Ejemplo n.º 10
0
def play(postfn=None):
    global score, cities

    score = 0
    cities = NCITIES

    engine.add_obj(Ground(MINX, GROUNDY, MAXX, MINY))
    draw_score()

    draw_stars()

    # we built this city on rock and roll
    xcoords = list(range(MINX, MAXX, WIDTH // (NCITIES + 1)))[1:-1]
    for x in xcoords:
        engine.add_obj(City(x, GROUNDY))

    engine.add_random_event(NEWENEMYPROB, newenemy_cb)

    engine.register_collision(City, Enemy, coll_city1)
    engine.register_collision(Enemy, City, coll_city2)
    engine.register_collision(Ground, Enemy, coll_ground1)
    engine.register_collision(Enemy, Ground, coll_ground2)
    engine.register_collision(Enemy, Missile, coll_air2air)
    engine.register_collision(Missile, Enemy, coll_air2air)

    engine.register_collision(Ground, Missile, coll_groundnoboom1)
    engine.register_collision(Missile, Ground, coll_groundnoboom2)

    if postfn:
        postfn()
    engine.engine()
Ejemplo n.º 11
0
def init():
    global score
    score = 0
    engine.init_screen(W, H)
    engine.init_engine()
    turtle.bgcolor('black')
    engine.set_keyboard_handler(inputs)
    engine.add_random_event(0.01, rock)
    engine.add_random_event(0.01, hole)
    engine.add_random_event(0.1, newStar)
    engine.add_obj(buggy1)
    engine.add_obj(_ground(120, 320, -320, 240))
    draw_score()
    engine.add_obj(_starstuff(1, 1))
    engine.register_collision(_buggy, _rock, collbr)
    engine.register_collision(_rock, _buggy, collrb)
    engine.register_collision(_buggy, _hole, collbh)
    engine.register_collision(_hole, _buggy, collhb)
    engine.register_collision(_rocket, _rock, collrtr)
    engine.register_collision(_rock, _rocket, collrrt)
Ejemplo n.º 12
0
def circle_cb():
	obj = Circle(0, 0, 1, 1)
	engine.add_obj(obj)

def quit_cb(key):
	if key == 'q' or key == 'Q':
		engine.exit_engine()

# main routine

if __name__ == '__main__':
	#random.seed(86753)

	engine.init_screen(WIDTH, HEIGHT)
	engine.init_engine()
	engine.set_keyboard_handler(quit_cb)
	engine.add_random_event(0.005, circle_cb)
	engine.register_collision(Circle, Circle, coll_circle)
	engine.register_collision(Boom, Circle, coll_boom1)
	engine.register_collision(Circle, Boom, coll_boom2)
	for i in range(4):
		ypos = engine.MAXY - i * HEIGHT/3
		obj = DelayedBox(engine.MINX, ypos, i*250)
		engine.add_obj(obj)
	engine.add_obj(PulsingCircle(50, 50, 100))
	engine.add_obj(BigRect(engine.MINX + 25, 0,
			       engine.MAXX - 25, engine.MINY + 25))
	engine.add_obj(BigRect(0, 100, 25, 25))
	engine.add_obj(BigRect(-200, 150, -100, 125))
	engine.engine()
Ejemplo n.º 13
0
    genericGroundCollisionCall(ship, gnd)


def collide_GD_SH(gnd, ship):
    genericGroundCollisionCall(ship, gnd)


if __name__ == '__main__':
    engine.init_screen(WIDTH, HEIGHT)
    engine.init_engine()
    engine.set_keyboard_handler(keyboard_cb)
    drawground()
    drawfus_alt()
    drawsun()

    ship = Fusee()
    gnd = Ground()
    sun = Sun()
    engine.add_obj(gnd)
    engine.add_obj(sun)
    engine.add_obj(ship)
    # Call collision_cb_SL() each step for each pair of {Sun, Lander}
    engine.register_collision(Sun, Fusee, collision_cb_SL)
    # Call collision_cb_LS() each step for each pair of {Lander, Sun}
    engine.register_collision(Fusee, Sun, collision_cb_LS)

    engine.register_collision(Fusee, Ground, collide_SH_GD)
    engine.register_collision(Ground, Fusee, collide_GD_SH)

    engine.engine()
Ejemplo n.º 14
0
	drawFuelBar(100)
	drawSpeedBar(0)
	turtle.register_shape("ess.gif")

	ship = Fusee()
	gnd = Ground()
	gnd.ground = lvl
	gnd.x = -wlength / 2
	sun = Sun()
	ess = GreenBarFuel()
	spd = SpeedBar()
	engine.add_obj(gnd)
	engine.add_obj(sun)

	engine.add_obj(ess)
	engine.add_obj(spd)
	
	logo = LogoEssence()
	engine.add_obj(logo)
	
	engine.add_obj(ship)
	
	engine.register_collision(Sun, Fusee, collision_cb_SL)
	engine.register_collision(Fusee, Sun, collision_cb_LS)

	engine.register_collision(Fusee, Ground, collide_SH_GD)
	engine.register_collision(Ground, Fusee, collide_GD_SH)

	engine.engine()

Ejemplo n.º 15
0
    engine.add_obj(obj)


def quit_cb(key):
    if key == 'q' or key == 'Q':
        engine.exit_engine()


# main routine

if __name__ == '__main__':
    #random.seed(86753)

    engine.init_screen(WIDTH, HEIGHT)
    engine.init_engine()
    engine.set_keyboard_handler(quit_cb)
    engine.add_random_event(0.005, circle_cb)
    engine.register_collision(Circle, Circle, coll_circle)
    engine.register_collision(Boom, Circle, coll_boom1)
    engine.register_collision(Circle, Boom, coll_boom2)
    for i in range(4):
        ypos = engine.MAXY - i * HEIGHT / 3
        obj = DelayedBox(engine.MINX, ypos, i * 250)
        engine.add_obj(obj)
    engine.add_obj(PulsingCircle(50, 50, 100))
    engine.add_obj(
        BigRect(engine.MINX + 25, 0, engine.MAXX - 25, engine.MINY + 25))
    engine.add_obj(BigRect(0, 100, 25, 25))
    engine.add_obj(BigRect(-200, 150, -100, 125))
    engine.engine()
Ejemplo n.º 16
0
def play(postfn=None):
	global score, cities

	score = 0
	cities = NCITIES

	engine.add_obj(Ground(MINX, GROUNDY, MAXX, MINY))
	draw_score()

	draw_stars()

	# we built this city on rock and roll
	xcoords = list(range(MINX, MAXX, WIDTH // (NCITIES+1)))[1:-1]
	for x in xcoords:
		engine.add_obj(City(x, GROUNDY))

	engine.add_random_event(NEWENEMYPROB, newenemy_cb)

	engine.register_collision(City, Enemy, coll_city1)
	engine.register_collision(Enemy, City, coll_city2)
	engine.register_collision(Ground, Enemy, coll_ground1)
	engine.register_collision(Enemy, Ground, coll_ground2)
	engine.register_collision(Enemy, Missile, coll_air2air)
	engine.register_collision(Missile, Enemy, coll_air2air)

	engine.register_collision(Ground, Missile, coll_groundnoboom1)
	engine.register_collision(Missile, Ground, coll_groundnoboom2)

	if postfn:
		postfn()
	engine.engine()
Ejemplo n.º 17
0
    logo = FuelLogo()
    accl = AccelerationLogo()
    engine.add_obj(logo)
    engine.add_obj(accl)

    engine.add_obj(ship)

    # create a random number of enemies located at random places
    nb_enemies = random.randint(5, 10)
    for i in range(nb_enemies):
        en = Enemy()
        en.x0 = random.randint(-wlength / 2, wlength / 2)
        en.y0 = random.randint(-HEIGHT / 2, HEIGHT / 2)
        engine.add_obj(en)

    # register collisions
    engine.register_collision(Sun, Fusee, collision_cb_SL)
    engine.register_collision(Fusee, Sun, collision_cb_LS)

    engine.register_collision(Fusee, Ground, collision_ship_ground)
    engine.register_collision(Ground, Fusee, collision_ground_ship)

    engine.register_collision(Fusee, Enemy, collision_enemy)

    engine.register_collision(Enemy, Bullet, collision_en_bl)
    engine.register_collision(Fusee, Bullet, collision_sh_bl)
    engine.register_collision(Bullet, Fusee, collision_bl_sh)

    # start the game!
    engine.engine()
Ejemplo n.º 18
0
def registerCollisionCallback(Class1, Class2, callback):
    engine.register_collision(Class1, Class2, callback)
    engine.register_collision(
        Class2, Class1,
        lambda instance2, instance1: callback(instance1, instance2))
Ejemplo n.º 19
0
    Test and deal with for the landing/crashing of the ship.
    :param groundInst: Instance of the Ground class.
    :param landerInst: Instance of the Lander class.
    :return: None
    """
    collision_cb_GL(groundInst, landerInst)


if __name__ == '__main__':
    # Create the various elements of the game
    engine.init_screen(WIDTH, HEIGHT)
    engine.init_engine()
    makeshape()
    lander = Lander()
    engine.set_keyboard_handler(keyboard_cb)
    sun = Sun()
    ground = Ground(groundS1)
    engine.add_obj(sun)
    engine.add_obj(lander)
    engine.add_obj(ground)

    # Call collision_cb_SL() each step for each pair of {Sun, Lander}
    engine.register_collision(Sun, Lander, collision_cb_SL)
    # Call collision_cb_LS() each step for each pair of {Lander, Sun}
    engine.register_collision(Lander, Sun, collision_cb_LS)
    engine.register_collision(Ground, Lander, collision_cb_GL)
    engine.register_collision(Lander, Ground, collision_cb_LG)

    # Start the game
    engine.engine()
Ejemplo n.º 20
0
def start_game():
    global score
    engine.init_engine()
    engine.set_keyboard_handler(keyboard_cb)

    # Adds Ground and Car and Mountains
    engine.add_obj(Mountain('Mountain2', 'ivory4', (-SPEED/4)))
    engine.add_obj(Mountain('Mountain1', 'bisque', (-SPEED/2)))
    engine.add_obj(Ground(MIN_X, GROUND_Y, MAX_X, MIN_Y))
    engine.add_obj(Car())

    # Adds Wheels
    engine.add_obj(Wheel(2, GROUND_Y, -3))
    engine.add_obj(Wheel(15, GROUND_Y, 3))
    engine.add_obj(Wheel(28, GROUND_Y, -3))

    # Random Events
    engine.add_random_event(0.006, hole_cb)
    engine.add_random_event(0.007, turtle_cb)
    engine.add_random_event(0.004, UFO_cb)

    # Collision Detection
    engine.register_collision(Car, Hole, hole_collision_cb)
    engine.register_collision(Hole, Car, hole_collision_cb2)

    engine.register_collision(Car, EnemyTurtle, turt_collision_cb)
    engine.register_collision(EnemyTurtle, Car, turt_collision_cb2)

    engine.register_collision(MissileRight, EnemyTurtle, miss_turt_collision_cb)
    engine.register_collision(EnemyTurtle, MissileRight, miss_turt_collision_cb2)

    engine.register_collision(MissleVertical, UFO, miss_ufo_collision_cb)
    engine.register_collision(UFO, MissleVertical, miss_ufo_collision_cb2)

    engine.register_collision(Car, UFO, car_ufo_collision_cb)
    engine.register_collision(UFO, Car, car_ufo_collision_cb2)

    engine.register_collision(Car, MissleVertical, car_miss_collision_cb)
    engine.register_collision(MissleVertical, Car, car_miss_collision_cb2)

    # Score and Stars drawn
    draw_score(False)
    draw_random_stars(50)

    engine.engine()
Ejemplo n.º 21
0
    logo = FuelLogo()
    accl = AccelerationLogo()
    engine.add_obj(logo)
    engine.add_obj(accl)

    engine.add_obj(ship)

    # create a random number of enemies located at random places
    nb_enemies = random.randint(5, 10)
    for i in range(nb_enemies):
        en = Enemy()
        en.x0 = random.randint(-wlength/2, wlength/2)
        en.y0 = random.randint(-HEIGHT/2, HEIGHT/2)
        engine.add_obj(en)

    # register collisions
    engine.register_collision(Sun, Fusee, collision_cb_SL)
    engine.register_collision(Fusee, Sun, collision_cb_LS)

    engine.register_collision(Fusee, Ground, collision_ship_ground)
    engine.register_collision(Ground, Fusee, collision_ground_ship)

    engine.register_collision(Fusee, Enemy, collision_enemy)

    engine.register_collision(Enemy, Bullet, collision_en_bl)
    engine.register_collision(Fusee, Bullet, collision_sh_bl)
    engine.register_collision(Bullet, Fusee, collision_bl_sh)

    # start the game!
    engine.engine()
Ejemplo n.º 22
0
def play():
    global s
    s = S()

    engine.init_engine()
    engine.set_keyboard_handler(input_cb)
    engine.add_obj(Ground(MINX, GROUNDY, MAXX, MINY))

    s.me = Me(0, GROUNDY + 10)
    engine.add_obj(s.me)

    # the grid o' evil
    for i in range(INVADERROWS):
        for j in range(INVADERCOLS):
            enemy = Invader(XGRIDSTART + j * INVADERHSPACE, YGRIDSTART - i * INVADERVSPACE, INVADERSPEED, 0)
            s.invaders.append(enemy)
            engine.add_obj(enemy)
    engine.add_random_event(FIREPROB, fire_cb)
    engine.add_random_event(UFOPROB, ufo_cb)

    # not quite so random - do this at start of each time step
    # order is important - if no invaders left, gridmove won't be happy
    engine.add_random_event(1.0, winlose_cb)
    engine.add_random_event(1.0, gridmove_cb)

    engine.register_collision(Ground, Bomb, coll_ground1)
    engine.register_collision(Bomb, Ground, coll_ground2)
    engine.register_collision(UFO, MyShot, coll_air2air_bonus)
    engine.register_collision(MyShot, UFO, coll_air2air_bonus)
    engine.register_collision(Invader, MyShot, coll_air2air)
    engine.register_collision(MyShot, Invader, coll_air2air)
    engine.register_collision(Ground, Invader, coll_gameover1)
    engine.register_collision(Invader, Ground, coll_gameover2)
    engine.register_collision(Me, Bomb, coll_loselife1)
    engine.register_collision(Bomb, Me, coll_loselife2)

    draw_score()

    engine.engine()