def bullet_move_control(): global bullet_run_flag, bullet_run_count, score, music_name, music_id if codey.is_button('C'): bullet_run_flag = True move_step = 5 if bullet_run_flag: if bullet_run_count == 0: codey.say(music_name) bullet.set_position( [plane.get_position()[0], plane.get_position()[1] + 2]) bullet.show() bullet_run_count += 1 if game.background_collision_check(bullet): score += 1 barrier_delete() elif bullet_run_count < move_step: bullet.up() bullet_run_count += 1 if game.background_collision_check(bullet): score += 1 barrier_delete() else: bullet.home() bullet.hide() bullet_run_count = 0 bullet_run_flag = False
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 shoot(): global plane_cur_pos global plane_last_pos global barrier_list plane_c_pos = plane_cur_pos pos = 5 codey.say("gunshot.wav") codey.pixel(plane_c_pos + 1, pos) codey.pixel(plane_c_pos + 1, pos - 1) codey.pixel(plane_c_pos + 1, pos - 2) time.sleep(0.01) codey.pixel_off(plane_c_pos + 1, pos) codey.pixel(plane_c_pos + 1, pos - 3) time.sleep(0.01) codey.pixel_off(plane_c_pos + 1, pos - 1) codey.pixel(plane_c_pos + 1, pos - 4) time.sleep(0.01) codey.pixel_off(plane_c_pos + 1, pos - 2) codey.pixel(plane_c_pos + 1, pos - 5) time.sleep(0.01) codey.pixel_off(plane_c_pos + 1, pos - 3) time.sleep(0.01) codey.pixel_off(plane_c_pos + 1, pos - 4) time.sleep(0.01) codey.pixel_off(plane_c_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_c_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])
def game_over_check(): global snake_list global game_status if snake_list[-1] in snake_list[0:(len(snake_list) - 1)]: game_status = GAME_OVER codey.say('death.wav') codey.color("#ff0000", 1)
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 game_over_check(): global snake_list global game_status #print("list", snake_list) if snake_list[-1] in snake_list[0:(len(snake_list) - 1)]: game_status = GAME_OVER codey.say('wrong.wav') codey.color("#ff0000", 1)
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_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 speaker_test(): print("speaker say cat") codey.say('meow.wav', True) print("play node") codey.play('C5', 1) print("pause") print("pre time value is ", codey.time()) codey.pause(1) print("later time value is ", codey.time()) print("play freequence") codey.play_freq(523, 1)
def on_shake_callback(): global screen_list if len(screen_list) >= 10: codey.say("codey") p.hide() for i in range(10): game.set_background(screen_list[i]) time.sleep(0.5) p.show() screen_list = [] else: codey.say("hi") screen_list.append(game.get_screen()) time.sleep(0.5)
def line_remove_process(): global score screen = game.get_screen() background = game.get_background() removed_flag = False i = 0 while i < 16: if screen[i] & 0xff == 0xff: score += 1 removed_flag = True del background[i] background.insert(0, 0x00) i += 1 if removed_flag: codey.say("start") game.set_background(background)
def on_button_callback2(): global cur_direc, last_direc count = 0 while True: speed = codey.dail() // 10 if cur_direc == 1: if a.meet_border_check() == 0x01: # up cur_direc = 2 elif a.meet_border_check() == 0x08: # right cur_direc = 3 elif cur_direc == 2: if a.meet_border_check() == 0x02: # down cur_direc = 1 elif a.meet_border_check() == 0x08: # right cur_direc = 4 elif game.collision_check(a, b): cur_direc = 1 codey.say('jump.wav', False) elif cur_direc == 3: if a.meet_border_check() == 0x01: # up cur_direc = 4 elif a.meet_border_check() == 0x04: # left cur_direc = 1 elif cur_direc == 4: if a.meet_border_check() == 0x02: # down cur_direc = 3 elif a.meet_border_check() == 0x04: # left cur_direc = 2 elif game.collision_check(a, b): cur_direc = 3 codey.say('jump.wav', False) if cur_direc == 1: a.up() a.right() elif cur_direc == 2: a.down() a.right() elif cur_direc == 3: a.left() a.up() elif cur_direc == 4: a.left() a.down() time.sleep(1.05 - speed / 10)
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: 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_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 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 test(): global down_flag count = 0 while True: if count % 2 == 0: p.show() else: p.hide() if count % 10 == 0: a.rotate() if count % 2 == 0: b.rotate() if count % 15 == 0: down_flag = True c.show() if down_flag: c.down() if c.meet_border_check() == DOWN_MEET: c.hide() c.home() down_flag = False if codey.is_button('B'): p.right() elif codey.is_button('A'): p.left() if game.collision_check(p, a) or game.collision_check( p, b) or game.collision_check(p, c): codey.say("wrong") codey.color("#ff0000", 0.05) p.home() time.sleep(0.05) count += 1
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'))
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 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
def on_button1_callback(): global a codey.say('wake.wav', True) codey.show(2)
def snake_add_point(p_x, p_y): snake_list.append([p_x, p_y]) codey.say('score.wav')
import codey import time while True: print("music test") codey.say("test_cat.wav") time.sleep(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
def on_button_callback(): codey.say('cat.wav')
# 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) codey.set_volume(100) codey.get_volume() codey.message("a") codey.is_button('A') codey.is_shaked() codey.is_tilt('forward') codey.sound_strength() codey.light_strength()