Beispiel #1
0
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)
Beispiel #2
0
def speed_control():
    global run_speed
    run_speed = 20 + int(codey.dail())
def dail_test():
    print("dail value is:", codey.dail())
Beispiel #4
0
def speed_control():
    global run_speed
    run_speed = 22 - int((codey.dail() / 5))
Beispiel #5
0
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()
codey.dail()
codey.gyro('pitch')
codey.time()
codey.reset_time()
codey.ir_send("A")
codey.ir_receive()

print("***codey APIS all succeed***")
# about rocky
rocky.color("#334455")
rocky.forward(50, 1)
rocky.backward(50, 1)
rocky.turn_left(50, 1)
rocky.turn_right(50, )
rocky.forward(50)
rocky.backward(50)
Beispiel #6
0
def barruer_speed_control():
    global barrier_move_speed
    barrier_move_speed = 11 - int(codey.dail() / 10)
Beispiel #7
0
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
Beispiel #8
0
def speed_control():
    global speed
    speed = codey.dail() // 5
Beispiel #9
0
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
Beispiel #10
0
def speed_control():
    global speed
    speed = (codey.dail() // 20) + 2