def on_start_callback(): global game_status global run_speed global user_score count = 0 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: if update_background(): pass else: game_status = GAME_OVER elif game_status == GAME_OVER: codey.show(user_score) game_status = GAME_READY game_init() elif game_status == GAME_PASS: game_status = GAME_PLAYING game_over_check() time.sleep(0.01) count += 1
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_callback3(): global current_script, speed, score, move_lock_flag game.game_start() game.set_background([4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1]) while True: index = random.randint(0, sprite_num - 1) current_script = sprite_create(sprites[index]) game.add_sprite(current_script) if game.background_collision_check(current_script): game.del_sprite(current_script) current_script = None codey.say("wrong") game.game_over() codey.show(score) score = 0 break count = 1 speed = 10 while True: if count % speed == 0: background_control() line_remove_process() if move_control(): break speed_control() time.sleep(0.05) count += 1 time.sleep(0.1) game.set_background(game.get_screen()) current_script.hide() time.sleep(0.1) game.del_sprite(current_script) move_lock_flag = False
def on_button_callback3(): global speed, score, move_lock_flag count = 1 score = 0 game.game_start() while True: speed_control() move_control() if speed != 0: if count % speed == 0: background_control() else: background_control() # 如果角色碰到背景, 则游戏结束 if game.background_collision_check( right_h) or game.background_collision_check(left_h): game.game_over() codey.say("wrong") codey.show(score) codey.color("#ff0000", 1) game_deinit() break count += 1 time.sleep(0.05)
def on_button_callback(): global x x = random.randint(1, 36) if x in list: x = random.randint(1, 36) else: codey.show(x) codey.say('score.wav') list.append(x)
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 on_button_callback3(): global current_script, down_speed, score, move_lock_flag game.game_start() game.set_background([0] * 16) while True: index = random.randint(0, sprite_num - 1) current_script = sprite_create(sprites[index]) game.add_sprite(current_script) if game.background_collision_check(current_script): game.del_sprite(current_script) current_script = None codey.say("wrong") game.game_over() codey.show(score) score = 0 break count = 1 down_speed = 10 while True: if count % down_speed == 0: current_script.right() if current_script.meet_border_check() == RIGHT_MEET: move_lock_flag = True current_script.left() codey.say("score") break if game.background_collision_check(current_script): move_lock_flag = True current_script.left() codey.say("score") break move_control() time.sleep(0.02) count += 1 time.sleep(0.1) game.set_background(game.get_screen()) current_script.hide() time.sleep(0.1) line_remove_process() game.del_sprite(current_script) move_lock_flag = False
def on_button_callback(): global a codey.wifi_close() codey.wifi('Maker-guest', 'makeblock') codey.show('hello') while not codey.wifi_is_connected(): pass codey.show(iot.weather('2164425', '0')) codey.color('#ffffff') time.sleep(2) while True: time.sleep(1) codey.show(codey.wifi_is_connected()) if codey.wifi_is_connected(): codey.say('step2.wav', True) codey.color('#00ff50') else: codey.color('#ff0000')
def on_message_callback(): codey.face('00001020402012020212204020100000', 1) while True: codey.show(iot.list_length('r'))
def on_button1_callback(): global a codey.say('wake.wav', True) codey.show(2)
elif codey.is_tilt('right'): if move_dir_last != MOVE_LEFT: move_dir = MOVE_RIGHT codey.pixel(food_point[0], food_point[1]) if count % run_speed == 0: sanke_move(move_dir) move_dir_last = move_dir show_snake() if codey.is_button("A"): game_status = GAME_OVER elif game_status == GAME_OVER: codey.show(len(snake_list) - 3) if codey.is_button("C"): snake_list = [[0, 0], [2, 3], [3, 3]] codey.clear() food_point = [0, 0] show_snake() print("create result", point_create()) game_status = GAME_PLAYING elif game_status == GAME_PASS: codey.show("OK") if codey.is_button("C"): snake_list = [[0, 0], [2, 3], [3, 3]] codey.clear() food_point = [0, 0] print("create result", point_create())
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
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) codey.mute() codey.play_note(50, 1)
def on_button2_callback(): if codey.wifi_is_connected(): codey.show(iot.weather('2161853', '1'))
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
codey.face('00001020402012020212204020100000', 1) while True: codey.show(iot.list_length('r')) codey.on_message(str('gg'), on_message_callback) def on_button_callback(): codey.say('cat.wav') codey.on_button('A', on_button_callback) def on_message1_callback(): codey.color('#ff0000', 1) while True: iot.list_add('r', iot.weather('2161853', '0')) codey.on_message(str('ww'), on_message1_callback) codey.wifi('Maker-guest', 'makeblock') codey.show('connecting...') while not codey.wifi_is_connected(): pass codey.message(str('gg')) codey.message(str('ww'))
def on_button_callback(): while True: codey.show(codey.gyro('roll'))
import codey MAIN_LOOP_TEST = 1 THREAD_LOOP_TEST = 0 if MAIN_LOOP_TEST: while True: a = 0 a = 'a' a = 9 codey.show(codey.light_strength()) elif THREAD_LOOP_TEST: def on_button_callback(): while True: codey.show(codey.gyro('roll')) codey.on_button('A', on_button_callback) else: def on_button_callback(): while True: codey.show(codey.gyro('roll')) codey.on_button('A', on_button_callback) while True: a = 0 a = 'a' a = 9 codey.show(codey.light_strength())