Exemplo n.º 1
0
def demo():
	global exitdemo
	exitdemo = False

	while not exitdemo:
		engine.init_engine()
		engine.set_keyboard_handler(demo_keypress_cb)
		play(demo_postinit_cb)
Exemplo n.º 2
0
def demo():
    global exitdemo
    exitdemo = False

    while not exitdemo:
        engine.init_engine()
        engine.set_keyboard_handler(demo_keypress_cb)
        play(demo_postinit_cb)
Exemplo n.º 3
0
def play():
    global s
    s = S()

    engine.init_engine()
    engine.set_keyboard_handler(input_cb)
    engine.set_mouse_handler(fire_cb)
    s.me = Me()
    engine.add_obj(s.me)

    s.playing = True
    engine.engine()
Exemplo n.º 4
0
    def load_level_selection_menu():
        print("Loading the level selection menu...")
        pos_arrow = - game.Game.LENGTH // 5, 3 * Menu.LEVEL_LINE_HEIGHT + Menu.FONT_SIZE
        rect_p1 = game.Game.LENGTH // 2, game.Game.LENGTH // 2
        rect_p2 = - game.Game.LENGTH // 2, - game.Game.LENGTH // 2

        engine.init_engine()
        engine.set_keyboard_handler(Menu.keyboard_lvl)
        Menu.cursor_position = Menu.cursor_position_on_screen = 1
        assert Menu.select_arrow is None, "Select arrow already initialized"
        Menu.lvl_rect = shapes.Rectangle(rect_p1, rect_p2, color_edge="white")
        Menu.select_arrow = engine.GameObject(*pos_arrow, 0, 0, "select_arrow", "black")
        engine.add_obj(Menu.select_arrow)
        Menu.display_level()
Exemplo n.º 5
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()
Exemplo n.º 6
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()
Exemplo n.º 7
0
    def load_skin_selection_menu():
        print("Loading the skin selection menu...")
        x_arrow, y_arrow = game.Game.LENGTH / 3.5, - game.Game.LENGTH / 6
        arrow_height, arrow_width = 34.6, 30
        rect_txt_p1 = - (y_arrow + arrow_height / 2), - x_arrow + arrow_width / 2
        rect_txt_p2 = - (y_arrow - arrow_height / 2), x_arrow - arrow_width / 2
        rect_window_p1 = rect_txt_p1[0] - 20, rect_txt_p1[1]  # 20 : shift between the two rectangles
        rect_window_p2 = rect_txt_p1[0] - 20 - Menu.SKIN_WINDOW_HEIGHT, rect_txt_p2[1]

        engine.init_engine()
        engine.set_keyboard_handler(Menu.keyboard_skin)
        _ = engine.GameObject(x_arrow, y_arrow, 0, 0, "arrow_right_skin", "gray", True)
        _ = engine.GameObject(- x_arrow, y_arrow, 0, 0, "arrow_left_skin", "gray", True)
        _ = shapes.Rectangle(rect_window_p1, rect_window_p2)
        Menu.skin_rect = shapes.Rectangle(rect_txt_p1, rect_txt_p2)
        Menu.display_skin()
Exemplo n.º 8
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()
Exemplo n.º 9
0
    def keyboard_lvl(key):
        """keyboard manager for the level selection menu"""
        total_lvl_number = len(listdir("Files/lvls/"))
        y0 = 4 * Menu.LEVEL_LINE_HEIGHT + Menu.FONT_SIZE

        if key == "Up":
            if Menu.cursor_position_on_screen > 0:
                Menu.cursor_position_on_screen -= 1
            elif Menu.cursor_position == 0:  # and Menu.cursor_position_on_screen == 0
                Menu.cursor_position_on_screen = Menu.MAX_NB_LVL_PER_PAGE - 1
            # in other cases, the arrow remains on the top
            Menu.cursor_position = (Menu.cursor_position - 1) % (total_lvl_number + 1)  # + 1 for the return button
            Menu.select_arrow.y = y0 - Menu.LEVEL_LINE_HEIGHT * Menu.cursor_position_on_screen
            Menu.display_level()

        if key == "Down":
            if Menu.cursor_position_on_screen < Menu.MAX_NB_LVL_PER_PAGE - 1:
                Menu.cursor_position_on_screen += 1
            elif Menu.cursor_position == total_lvl_number:  # and Menu.cursor_position_on_screen == MAX_NB_LVL_PER_PAGE - 1
                Menu.cursor_position_on_screen = 0
            # in other cases, the arrow remains on the bottom
            Menu.cursor_position = (Menu.cursor_position + 1) % (total_lvl_number + 1)  # + 1 for the return button
            Menu.select_arrow.y = y0 - Menu.LEVEL_LINE_HEIGHT * Menu.cursor_position_on_screen
            Menu.display_level()

        if key == "Return":
            engine.del_obj(Menu.select_arrow)
            engine.del_obj(Menu.lvl_rect)
            Menu.select_arrow = Menu.lvl_rect = None
            if Menu.cursor_position == 0:
                Menu.load_main_menu()
            else:
                lvl = "lvl" + str(Menu.cursor_position)

                engine.init_engine()
                game.Game.init_all(lvl)

                engine.add_obj(game.Game.ground)
                engine.add_obj(game.Game.rocket)

                game.cheat()
                engine.set_keyboard_handler(game.keyboard_cb)
                game.load()
Exemplo n.º 10
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)
Exemplo n.º 11
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()
Exemplo n.º 12
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()
Exemplo n.º 13
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()
Exemplo n.º 14
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()
Exemplo n.º 15
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()
Exemplo n.º 16
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()
Exemplo n.º 17
0
	turtle.fd(B)			# roof
	turtle.rt(45)
	turtle.fd(B * 3/4)		# windshield
	turtle.lt(45)
	turtle.fd(B)			# hood
	turtle.rt(90)
	turtle.fd(B * 3/4)		# front
	turtle.rt(90)
	turtle.fd(B * 1/7)
	turtle.lt(90)
	turtle.circle(-B/2, 180)	# front tire
	turtle.lt(90)
	turtle.fd(B)
	turtle.lt(90)
	turtle.circle(-B/2, 180)	# back tire
	turtle.lt(90)
	turtle.fd(B * 1/7)
	turtle.rt(90)
	turtle.fd(B * 5/6)		# back
	turtle.end_poly()
	poly = turtle.get_poly()
	turtle.register_shape('car', poly)

if __name__ == '__main__':
	engine.init_screen(WIDTH, HEIGHT)
	engine.init_engine()
	makeshape()
	car = Car()
	engine.add_obj(car)
	engine.engine()
Exemplo n.º 18
0
# basic moving box

import engine

WIDTH = 640
HEIGHT = 480


class Box(engine.GameObject):
    def __init__(self):
        super().__init__(0, 0, +1, 0, 'square', 'red')


if __name__ == '__main__':
    engine.init_screen(WIDTH, HEIGHT)
    engine.init_engine()
    box = Box()
    engine.add_obj(box)
    engine.engine()
Exemplo n.º 19
0

def recalcdeltas():
    global deltax, deltay
    deltay = SPEED * math.sin(math.radians(heading))
    deltax = SPEED * math.cos(math.radians(heading))


def input_cb(key):
    global heading
    if key == 'q' or key == 'Q':
        engine.exit_engine()
    elif key == 'Left':
        heading = (heading + HEADINGSTEP) % 360
    elif key == 'Right':
        heading = (heading - HEADINGSTEP) % 360

    recalcdeltas()


if __name__ == '__main__':
    engine.init_screen(WIDTH, HEIGHT)
    engine.init_engine(delay=0)  # no delay needed with so many objects!
    engine.set_keyboard_handler(input_cb)
    recalcdeltas()
    makeshipshape()
    maketileshape()
    maketilegrid()
    engine.add_obj(Me())  # needs to be after tile grid created
    engine.engine()
Exemplo n.º 20
0
			y = HEIGHT//2 - row * B
			tile = Tile(x, y)
			engine.add_obj(tile)

def recalcdeltas():
	global deltax, deltay
	deltay = SPEED * math.sin(math.radians(heading))
	deltax = SPEED * math.cos(math.radians(heading))

def input_cb(key):
	global heading
	if key == 'q' or key == 'Q':
		engine.exit_engine()
	elif key == 'Left':
		heading = (heading + HEADINGSTEP) % 360
	elif key == 'Right':
		heading = (heading - HEADINGSTEP) % 360

	recalcdeltas()

if __name__ == '__main__':
	engine.init_screen(WIDTH, HEIGHT)
	engine.init_engine(delay=0)	# no delay needed with so many objects!
	engine.set_keyboard_handler(input_cb)
	recalcdeltas()
	makeshipshape()
	maketileshape()
	maketilegrid()
	engine.add_obj(Me())		# needs to be after tile grid created
	engine.engine()
Exemplo n.º 21
0
def game():
	engine.init_engine()
	engine.set_mouse_handler(fire_cb)
	engine.set_keyboard_handler(quit_cb)
	play()
Exemplo n.º 22
0
def main():
    c = Context("pygame", (800, 400), "Renderer")
    init_engine()
    clock = Clock()
    obj0 = Obj(r"./assets/objects/tetrahedron.obj")
    obj1 = Obj(r"./assets/objects/halfcube.obj")
    obj2 = Obj(r"./assets/objects/octahedron.obj")
    obj3 = Obj(r"./assets/objects/dodecahedron.obj")
    obj4 = Obj(r"./assets/objects/teapot.obj")
    obj5 = Obj(r"./assets/objects/pointer.obj")
    tex0 = Tex(r"./assets/textures/_default.png")
    tex1 = Tex(r"./assets/textures/metal.jpg")
    tex2 = Tex(r"./assets/textures/abstract.jpg")
    tex3 = Tex(r"./assets/textures/white.png")
    model0 = Model(obj0, tex0, pos=Point(0.0, 0.0, 0.0), scale=0.8)
    model1 = Model(obj1, tex2, pos=Point(-1.5, 0.0, 0.0), scale=0.8)
    model2 = Model(obj2, tex0, pos=Point(0.0, 0.0, 0.0), scale=0.8)
    model3 = Model(obj3, tex0, pos=Point(0.0, 0.0, 0.0), scale=0.8)
    model4 = Model(obj4, tex3, pos=Point(10, 10, 10), scale=0.8)
    model5 = Model(obj5, tex1, pos=Point(0.0, 0.0, 0.0), scale=2.0)
    camera = Camera(pos=Point(0.0, 0.0, 3.0), rot=Rot(0.0, 0.0, 0.0), fovy=90)
    scene = Scene({model1, model4, model5})

    camera_rotdeltas = {
        pygame.K_LEFT: Rot(0.0, -0.04, 0.0),
        pygame.K_RIGHT: Rot(0.0, 0.04, 0.0),
        pygame.K_DOWN: Rot(-0.04, 0.0, 0.0),
        pygame.K_UP: Rot(0.04, 0.0, 0.0),
        pygame.K_COMMA: Rot(0.0, 0.0, -0.04),
        pygame.K_PERIOD: Rot(0.0, 0.0, 0.04)
    }

    camera_posdeltas = {
        pygame.K_a: Point(-0.1, 0.0, 0.0),
        pygame.K_d: Point(0.1, 0.0, 0.0),
        pygame.K_s: Point(0.0, 0.0, 0.1),
        pygame.K_w: Point(0.0, 0.0, -0.1),
        pygame.K_f: Point(0.0, -0.1, 0.0),
        pygame.K_r: Point(0.0, 0.1, 0.0)
    }

    while True:
        clock.tick(60)
        c.idle()
        model0.rot += Rot(0.01, 0.02, 0.03)
        model1.rot += Rot(0.02, 0.03, 0.01)
        model2.rot += Rot(0.03, 0.01, 0.02)
        model3.rot += Rot(0.03, 0.02, 0.01)
        ##    model4.rot += Rot(0.01, 0.03, 0.02)
        model5.rot += Rot(0.02, 0.01, 0.03)
        # rotate camera from keyboard inputs
        pygame.event.pump()
        pressed_keys = pygame.key.get_pressed()
        for k in camera_rotdeltas:
            if pressed_keys[k]:
                camera.rot += camera_rotdeltas[k]
        rx, ry, rz = camera.rot
        defacto_rot = Rot(rx, -ry, -rz)
        for k in camera_posdeltas:
            if pressed_keys[k]:
                camera.pos += defacto_rot.get_transmat() * camera_posdeltas[k]
        X, Y = c.getres()
        glViewport(0, 0, X, Y)
        scene.render(camera, aspect=X / Y, mode="full")
        c.dispbuffer()
Exemplo n.º 23
0
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys

from engine import init_engine


def main():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'server.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?") from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    path = os.path.join('data', 'output', 'trie')
    init_engine(path=path)
    main()
Exemplo n.º 24
0
def game():
    engine.init_engine()
    engine.set_keyboard_handler(input_cb)
    play()
Exemplo n.º 25
0
def game():
    engine.init_engine()
    engine.set_mouse_handler(fire_cb)
    engine.set_keyboard_handler(quit_cb)
    play()