def initialize(): global arena, mario, background, sprites, platforms arena = actor.Arena(screen_x, screen_y) mario = jumper.Jumper(arena, 16, 248) game2d.canvas_init(arena.size()) platforms = [] for n in range(len(dk_elements.map_elements)): if dk_elements.map_elements[n][0] == "Platform": x, y, w, h = dk_elements.map_elements[n][-4:] platforms.append(entities.Platform(x, y, w, h, arena)) print(platforms) background = game2d.image_load("dk_background.png") sprites = game2d.image_load("dk_sprites.png") game2d.handle_keyboard(keydown, keyup)
def main(): global key_block game2d.canvas_init((screen_x,screen_y)) game2d.handle_keyboard(keydown, keyup) game2d.set_interval(update,1000//30)
def main(): global balls arena = actors.Arena(screen_x, screen_y) balls.append( actors.Ball(0 + radius, arena.get_size()[1] // 2, radius, arena)) balls.append( actors.Ball(0 + radius + second_ball_distance, arena.get_size()[1] // 2, radius, arena)) game2d.handle_keyboard(keydown, keyup) game2d.canvas_init((arena.get_size())) game2d.set_interval(update, 1000 // 30)
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
elif player == gold: draw_tile(color_gold, player) g2d.draw_text('Gold!', (0, 0, 255), (0, 0), 24) else: draw_tile(color_now, player) g2d.update_canvas() color_now = (0, 0, 0) color_old = (127, 127, 127) color_gold = (0, 255, 0) color_monster = (255, 0, 0) W, H = 5, 5 TILE = 20 g2d.init_canvas((W * TILE, H * TILE)) player = 0, 0 monster = player while monster == player: monster = randrange(W), randrange(H) gold = player while gold == player or gold == monster: gold = randrange(W), randrange(H) print('Monster:', monster) print('Gold:', gold) draw_tile((0, 0, 0), player) g2d.handle_keyboard(keydown, None) g2d.main_loop()
def keydown(key: str): if key == "ArrowRight": ball.go_right() elif key == "ArrowLeft": ball.go_left() elif key == "ArrowUp": ball.jump() def keyup(key: str): ball.stay() def update(): game2d.canvas_fill((255, 255, 255)) ball.move() x, y, r = ball.get_coord() game2d.draw_circle((0, 0, 0), (x, y), (r + 3)) game2d.draw_circle((ball.getter()), (x, y), (r)) ball = Ball(0 + radius + 1, screen_y - radius, radius, screen_x, screen_y) ball.stay() game2d.handle_keyboard(keydown, keyup) game2d.canvas_init((screen_x, screen_y)) game2d.set_interval(update, 1000 // 30)