def show_snake(): global snake_list for i in range(len(snake_list)): if i == 0: codey.pixel_off(snake_list[i][0], snake_list[i][1]) else: codey.pixel(snake_list[i][0], snake_list[i][1])
def on_start_callback(): global game_status global axis_y global count global run_speed global down_lock global music_lock global user_score last_axis_y = 3 codey.face("0010c7c7c7000000e3e3e3000000c3c3") while True: speed_control() if game_status == GAME_READY: if codey.is_button("C"): game_status = GAME_PLAYING elif game_status == GAME_PLAYING: if count % run_speed == 0: codey.face(create_background()) elif game_status == GAME_OVER: codey.show(user_score) game_status = GAME_READY game_init() elif game_status == GAME_PASS: game_status = GAME_PLAYING if count % 4 == 0: if codey.is_button('A'): music_lock = False axis_y -= 1 down_lock = True else: down_lock = False if music_lock == False: codey.say('jump.wav', False, None) music_lock = True if game_status == GAME_PLAYING: if count % run_speed == 0 and (not down_lock): axis_y += 1 if last_axis_y != axis_y: codey.pixel_off(7, last_axis_y) codey.pixel(7, axis_y) last_axis_y = axis_y if axis_y >= 7: axis_y = 7 elif axis_y < 0: axis_y = 0 game_over_check() time.sleep(0.01) count += 1
def face_update(): global barrier_list for i in range(BARRIER_MAX_NUM): if barrier_list[i][0] == True: codey.pixel_off(barrier_list[i][1], barrier_list[i][2] - 1) if barrier_list[i][2] >= FACE_LINE: barrier_list[i][0] = False else: codey.pixel(barrier_list[i][1], barrier_list[i][2]) else: codey.pixel_off(barrier_list[i][1], barrier_list[i][2])
def ledm_test(): print("all led on") codey.face("ffffffffffffffffffffffffffffffff", 3) print("all led off") print('(0, 0) on') codey.pixel(0, 0) time.sleep(1) print("(0, 0) off") codey.pixel_off(0, 0) time.sleep(1) print("(0, 0) toggle") codey.pixel_toggle(0, 0) time.sleep(1)
def plane_run(p_x_c, p_x_l): if p_x_c != p_x_l: codey.pixel_off(p_x_l, 7) codey.pixel_off(p_x_l + 1, 6) codey.pixel_off(p_x_l + 2, 7) codey.pixel(p_x_c, 7) codey.pixel(p_x_c + 1, 6) codey.pixel(p_x_c + 2, 7)
def shoot(): global plane_cur_pos global plane_last_pos global barrier_list pos = 5 codey.pixel(plane_cur_pos + 1, pos) codey.pixel(plane_cur_pos + 1, pos - 1) codey.pixel(plane_cur_pos + 1, pos - 2) time.sleep(0.01) codey.pixel_off(plane_cur_pos + 1, pos) codey.pixel(plane_cur_pos + 1, pos - 3) time.sleep(0.01) codey.pixel_off(plane_cur_pos + 1, pos - 1) codey.pixel(plane_cur_pos + 1, pos - 4) time.sleep(0.01) codey.pixel_off(plane_cur_pos + 1, pos - 2) codey.pixel(plane_cur_pos + 1, pos - 5) time.sleep(0.01) codey.pixel_off(plane_cur_pos + 1, pos - 3) time.sleep(0.01) codey.pixel_off(plane_cur_pos + 1, pos - 4) time.sleep(0.01) codey.pixel_off(plane_cur_pos + 1, pos - 5) time.sleep(0.01) for i in range(BARRIER_MAX_NUM): if barrier_list[i][0] == True: if barrier_list[i][1] == plane_cur_pos + 1: barrier_list[i][0] = False codey.pixel_off(barrier_list[i][1], barrier_list[i][2]) else: codey.pixel_off(barrier_list[i][1], barrier_list[i][2])
time.sleep(0.1) def call_back(): codey.face('00001020402012020212204020100000', 1) while True: sensor_test() # about codey codey.face('00001020402012020212204020100000', 1) codey.face('00001020402012020212204020100000') codey.show('hello world') codey.clear() codey.pixel(0, 0) codey.pixel_off(0, 0) codey.pixel_toggle(0, 0) codey.color('#334455', 1) codey.color('#334455') codey.color_off() codey.red(255) codey.green(255) codey.blue(0) codey.say('cat') codey.say('cat.wav') codey.say('cat', True) codey.mute() codey.play_note(50, 1) codey.pause(0.25) codey.play_freq(700, 1) codey.change_volume(-10)