def main(): global arena arena = Arena((480, 360)) Vehicle(arena, (40, 40), 5) Vehicle(arena, (80, 80), -5) g2d.init_canvas(arena.size()) g2d.main_loop(tick)
def main(): global arena arena = Arena((320, 240)) Alien(arena, (40, 40)) Alien(arena, (80, 80)) g2d.init_canvas(arena.size()) g2d.main_loop(tick)
def main(): global arena arena = Arena(320, 240) Alien(arena, 40, 40) Alien(arena, 80, 80) g2d.init_canvas(arena.size()) g2d.handle_events(update) g2d.main_loop()
def main(): global arena, sprites arena = Arena(320, 240) Ball(arena, 40, 80) Ball(arena, 85, 40) Wall(arena, 115, 80, 100, 20) g2d.init_canvas(arena.size()) sprites = g2d.load_image("sprites.png") g2d.main_loop(tick)
def main(): global arena, turtle, sprites arena = Arena(320, 240) for i in range(5): Ball(arena) g2d.init_canvas(arena.size()) sprites = g2d.load_image("sprites.png") g2d.main_loop(update, 1000 // 30) # millis
def main(): global arena, turtle, sprites arena = Arena(320, 240) turtle = Turtle(arena, 80, 80) g2d.init_canvas(arena.size()) sprites = g2d.load_image("sprites.png") g2d.main_loop(tick)
def main(): global arena, turtle, sprites arena = Arena(320, 240) turtle = Turtle(arena, 80, 80) g2d.init_canvas(arena.size()) sprites = g2d.load_image("sprites.png") g2d.handle_events(update, keydown, keyup) g2d.main_loop()
def main(): global arena, sprites arena = Arena(320, 240) Ball(arena, 40, 80) Ball(arena, 85, 40) Wall(arena, 115, 80, 100, 20) g2d.init_canvas(arena.size()) sprites = g2d.load_image("sprites.png") g2d.handle_events(update) g2d.main_loop()
def main(): global arena, mario, sprites, background arena = Arena(224, 256) mario = Mario(arena, 50, 230) Barrel(arena, 180, 70) Barrel(arena, 150, 70) for t, x, y, w, h in map_elements: if t == "Platform": Platform(arena, int(x), int(y)) elif t == "Ladder": Ladder(arena, int(x), int(y), int(h)) game2d.canvas_init(arena.size()) sprites = game2d.image_load("dk_sprites.png") background = game2d.image_load("dk_background.png") game2d.handle_keyboard(keydown, keyup) game2d.set_interval(update, 1000 // 30) # millis
if g2d.key_pressed("Spacebar"): mario.jump() elif g2d.key_pressed("ArrowLeft"): mario.go_left() elif g2d.key_pressed("ArrowRight"): mario.go_right() elif (g2d.key_released("ArrowLeft") or g2d.key_released("ArrowRight")): mario.stay() arena.move_all() # Game logic g2d.clear_canvas() for a in arena.actors(): if isinstance(a, Wall): g2d.fill_rect(a.position()) else: g2d.draw_image_clip(sprites, a.symbol(), a.position()) arena = Arena(320, 240) mario = Mario(arena, 80, 80) CrazyGoomba(arena, 180, 80) CrazyGoomba(arena, 150, 80) Wall(arena, 200, 80, 80, 20) Wall(arena, 120, 160, 80, 20) Wall(arena, 0, 220, 320, 20) g2d.init_canvas(arena.size()) sprites = g2d.load_image("sprites.png") g2d.main_loop(tick)
if isinstance(a, Wall): g2d.fill_rect(a.position()) else: g2d.draw_image_clip(sprites, a.symbol(), a.position()) def keydown(code): print("#"+code+"#") if code == "Space": mario.jump() elif code == "ArrowLeft": mario.go_left() elif code == "ArrowRight": mario.go_right() def keyup(code): if code in ("ArrowLeft", "ArrowRight"): mario.stay() arena = Arena(320, 240) mario = Mario(arena, 80, 80) CrazyGoomba(arena, 180, 80) CrazyGoomba(arena, 150, 80) Wall(arena, 200, 80, 80, 20) Wall(arena, 120, 160, 80, 20) Wall(arena, 0, 220, 320, 20) g2d.init_canvas(arena.size()) sprites = g2d.load_image("sprites.png") g2d.handle_events(update, keydown, keyup) g2d.main_loop()