# X-Man import simplegui import random WIDTH = 500 HEIGHT = 500 pos = [250, 250] vel = [0, 0] card_images = simplegui.load_image("http://storage.googleapis.com/codeskulptor-assets/cards_jfitz.png") CARD_SIZE = (72, 96) CARD_CENTER = (36, 48) card_loc = [36, 48] def draw(canvas): global pos, vel, card_images, CARD_SIZE, card_loc, CARD_CENTER pos[0] = pos[0] + vel[0] pos[1] = pos[1] + vel[1] canvas.draw_image(card_images, card_loc, CARD_SIZE, [pos[0], pos[1]], CARD_SIZE) def keydown(key): global pos, vel if key == simplegui.KEY_MAP["left"]: vel[0] = -4 if key == simplegui.KEY_MAP["right"]: vel[0] = 4 if key == simplegui.KEY_MAP["down"]: vel[1] = 4 if key == simplegui.KEY_MAP["up"]: vel[1] = -4 def keyup(key): global pos, vel if key == simplegui.KEY_MAP["left"]: vel[0] = 0 if key == simplegui.KEY_MAP["right"]: vel[0] = 0 if key == simplegui.KEY_MAP["up"]: vel[1] = 0 if key == simplegui.KEY_MAP["down"]: vel[1] = 0 # create frame frame = simplegui.create_frame("Card Run", WIDTH, HEIGHT) frame.set_canvas_background('Blue') frame.set_draw_handler(draw) frame.set_keydown_handler(keydown) frame.set_keyup_handler(keyup) frame.start()