def plane_contril(): global plane_cur_pos global plane_last_pos global t_count global user_score global game_status global barrier_list while True: if game_status == GAME_WAIT_TO_PALY: codey.face('00000000000003e60300000000000000') if codey.is_button("C"): game_status = GAME_PLAYING codey.clear() elif game_status == GAME_OVER: codey.show(user_score) for i in range(BARRIER_MAX_NUM): barrier_list[i][0] = False if codey.is_button("C"): game_status = GAME_PLAYING plane_cur_pos = 7 plane_last_pos = 6 user_score = 0 codey.clear() elif game_status == GAME_PLAYING: plane_run(plane_cur_pos, plane_last_pos) plane_last_pos = plane_cur_pos if codey.is_button("C"): shoot() if t_count >= 10: barrier_control() t_count = 0 t_count += 1 time.sleep(0.020)
def on_button_callback(): rocky.forward(50, 0.5) rocky.forward(50, 0.5) rocky.forward(50, 0.5) rocky.turn_right_angle(90) rocky.forward(50, 0.5) rocky.forward(50, 0.5) codey.face('00001020402012020212204020100000', 0.5) codey.say('cat.wav')
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 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 runCmd(cmd): if len(cmd) < 1: return for i, j in enumerate(cmd): if j == 0: rocky.stop() codey.set_variable('cmd', "0_0_0") else: t = type(j) if t == str: codey.face(j) elif t == tuple: run(j[0], j[1])
def runCmd(cmd): if len(cmd) < 1: return for i, j in enumerate(cmd): print("index: %d" % i) if j == 0: # rocky.stop() codey.set_variable('cmd', "0_0_0") else: t = type(j) if t == str: if i == 0: if len(j) > 0: codey.say(j + '.wav') else: codey.face(j) elif t == tuple: run(j[0], j[1], j[2])
def on_message_callback(): global angerValue while True: codey.face('00003c7e7e3c000000003c7e7e3c0000') time.sleep(float(random.randint(2, 6))) codey.face('0000183c3c1800000000183c3c180000') time.sleep(float(random.uniform(0, 0.05))) codey.face('00000808080800000000080808080000') time.sleep(float(random.uniform(0.1, 0.3))) codey.face('0000183c3c1800000000183c3c180000') time.sleep(float(random.uniform(0, 0.05)))
def call_back(): codey.face('00001020402012020212204020100000', 1) while True: sensor_test()
time.sleep(0.3) codey.face('00183030381800000000183830301800') time.sleep(0.1) codey.face('00003c7e7e3c000000003c7e7e3c0000') angerValue = (angerValue if isinstance(angerValue, int) or isinstance(angerValue, float) else 0) + 1 codey.message(str('hello')) codey.on_button('B', on_button2_callback) angerValue = 0 while True: cap = codey.get_battery_capacity() if cap >= BATTERY_LOW_PERCENT: codey.face('00003c7e7e3c000000003c7e7e3c0000') time.sleep(float(random.randint(2, 6))) codey.face('0000181c1c1800000000181c1c180000') time.sleep(float(random.uniform(0, 0.05))) codey.face('00000808080800000000080808080000') time.sleep(float(random.uniform(0.1, 0.3))) codey.face('0000183c3c1800000000183c3c180000') time.sleep(float(random.uniform(0, 0.05))) else: codey.color('#ff0000') codey.face('0000007e7e7e424242427e7e18000000', 1) codey.color('#000000') codey.face('00000c1e3e3c000000003c3e1e0c0000', 0.3) codey.face('000c1e3e3c000000003c3e1e0c000000', 0.1) codey.face('0000000c1e3e3c000000003c3e1e0c00', 0.1) codey.face('00000c1e3e3c000000003c3e1e0c0000', 0.3)
def ledm_test(): print("all led on") codey.face("ffffffffffffffffffffffffffffffff", 3) print("all led off")
def on_shake_callback(): codey.face('00001020402012020212204020100000', 1)
def on_message_callback(): codey.face('00001020402012020212204020100000', 1) while True: codey.show(iot.list_length('r'))
def on_button_callback(): global angerValue if angerValue > random.randint(3, 5): angerValue = 0 time.sleep(0.2) codey.face('00003c1e0e0400000000040e1e3c0000') rocky.back(50) time.sleep(0.4) codey.say('dog.wav') codey.face('00007c3e1e0e040000040e1e3e7c0000') rocky.back(100) time.sleep(0.05) rocky.forward(100) time.sleep(0.5) rocky.back(100) time.sleep(0.01) rocky.stop() time.sleep(0.2) else: codey.say('wrong.wav') codey.face('00081c1c3c3820000020383c1c1c0800') time.sleep(0.3) rocky.back(20) codey.face('00040e0e1e1c100000101c1e0e0e0400') rocky.back(50) time.sleep(0.1) codey.face('00081c1c3c3820000020383c1c1c0800') rocky.stop() time.sleep(0.3) codey.face('00183c3c7c7820000020787c3c3c1800') time.sleep(0.1) codey.face('00003c7e7e3c000000003c7e7e3c0000') angerValue = (angerValue if isinstance(angerValue, int) or isinstance(angerValue, float) else 0) + 1 codey.message(str('hello'))
import codey import rocky codey.face('00001020402012020212204020100000', 0.5) def on_button_callback(): rocky.forward(50, 0.5) rocky.forward(50, 0.5) rocky.forward(50, 0.5) rocky.turn_right_angle(90) rocky.forward(50, 0.5) rocky.forward(50, 0.5) codey.face('00001020402012020212204020100000', 0.5) codey.say('cat.wav') codey.on_button('A', on_button_callback)
def on_button1_callback(): global angerValue if angerValue > random.randint(3, 5): angerValue = 0 time.sleep(0.2) codey.face('00003c1e0e0400000000040e1e3c0000') rocky.back(50) time.sleep(0.4) codey.say('dog.wav') codey.face('00007c3e1e0e040000040e1e3e7c0000') rocky.back(100) time.sleep(0.05) rocky.forward(100) time.sleep(0.5) rocky.back(100) time.sleep(0.01) rocky.stop() time.sleep(0.2) else: codey.say('happy.wav') codey.face('000c18181c0c000000000c1c18180c00') time.sleep(0.3) rocky.left(70) time.sleep(0.05) codey.face('00183030381800000000183830301800') rocky.right(70) time.sleep(0.05) rocky.left(70) time.sleep(0.05) rocky.right(70) time.sleep(0.05) rocky.stop() codey.face('000c18181c0c000000000c1c18180c00') time.sleep(0.3) codey.face('00183030381800000000183830301800') time.sleep(0.1) codey.face('00003c7e7e3c000000003c7e7e3c0000') angerValue = (angerValue if isinstance(angerValue, int) or isinstance(angerValue, float) else 0) + 1 codey.message(str('hello'))
def main(): global game_status, score, plane_id, plane, music_name, bullet, music_id count = 0 while True: # 开机选择飞机造型及音效 if game_status == 0: if plane_id == 0: codey.face(plane_s) elif plane_id == 1: codey.face(plane_s1) else: codey.face(plane_s2) # 开始游戏 if codey.is_button("C"): codey.say("start") game_status = 1 score = 0 # 创建角色 if plane_id == 0: plane = sprite_create(plane_s) elif plane_id == 1: plane = sprite_create(plane_s1) else: plane = sprite_create(plane_s2) bullet = sprite_create(bullet_s) game.add_sprite(plane) bullet.hide() game.add_sprite(bullet) # 游戏开始 game.game_start() time.sleep(1) # 选择飞机 elif codey.is_button("A"): plane_id += 1 if plane_id > 2: plane_id = 0 while codey.is_button("A"): pass # 选择音效 elif codey.is_button("B"): music_id += 1 if music_id > 2: music_id = 0 if music_id == 0: music_name = "shot" elif music_id == 1: music_name = "laser" elif music_id == 2: music_name = "score" codey.say(music_name) while codey.is_button("B"): pass # 游戏运行控制 elif game_status == 1: # 调整数字可以调整移动灵敏度 if count % 3 == 0: plane_move_control() # 子弹移动控制 bullet_move_control() #障碍物移动控制, 速度随电位器变化而变化 if count % (codey.dail() // 6) == 0: background_control() # 飞机是否撞到障碍物检测 if game.background_collision_check(plane): codey.say('wrong') game_status = 2 game.set_background("00000000000000000000000000000000") game.sprite_list_clean() palne = None bullet = None game.game_over() time.sleep(0.02) else: # 游戏结束, 显示分数, 并等待C键按下, 重新开始游戏 codey.show(score) if codey.is_button("C"): game_status = 0 time.sleep(0.1) count += 1
if codey.is_button('C'): while codey.is_button('C'): time.sleep(0.05) sensor_control() 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)
def main(): global game_status, score, plane_id, plane, music_name, bullet, music_id count = 0 while True: if game_status == 0: if plane_id == 0: codey.face(plane_s) elif plane_id == 1: codey.face(plane_s1) else: codey.face(plane_s2) if codey.is_button("C"): codey.say("start") game_status = 1 score = 0 if plane_id == 0: plane = sprite_create(plane_s) elif plane_id == 1: plane = sprite_create(plane_s1) else: plane = sprite_create(plane_s2) bullet = sprite_create(bullet_s) game.add_sprite(plane) bullet.hide() game.add_sprite(bullet) game.game_start() time.sleep(1) elif codey.is_button("A"): plane_id += 1 if plane_id > 2: plane_id = 0 while codey.is_button("A"): pass elif codey.is_button("B"): music_id += 1 if music_id > 2: music_id = 0 if music_id == 0: music_name = "shot" elif music_id == 1: music_name = "laser" elif music_id == 2: music_name = "score" codey.say(music_name) while codey.is_button("B"): pass elif game_status == 1: if count % 3 == 0: plane_move_control() bullet_move_control() if count % (codey.dail() // 6) == 0: background_control() if game.background_collision_check(plane): codey.say('wrong') game_status = 2 game.set_background("00000000000000000000000000000000") game.sprite_list_clean() palne = None bullet = None game.game_over() time.sleep(0.02) else: codey.show(score) if codey.is_button("C"): game_status = 0 time.sleep(0.1) count += 1