""""
名称：064 童芯派 面向对象 体感小飞机
硬件： 童芯派
功能介绍：
使用童芯派的精灵功能在屏幕上编写了一个基于陀螺仪控制的体感小游戏，控制角色飞机躲避空中的子弹。

难度：⭐⭐⭐
支持的模式：上传模式
无

"""
# ---------程序分割线----------------程序分割线----------------程序分割线----------
import cyberpi
import random
import math
import time

class Enemy:
    def __init__(self):
        self.x = random.randint(0, 128)
        self.y = -1
        self.pix = cyberpi.sprite()
        self.pix.draw_pixels(
            [0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0xf5a623, 0xf5a623, 0xf5a623, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xf5a623,
             0xf5a623, 0xf5a623, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xf5a623, 0xf5a623, 0xf5a623, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000])
        self.pix.set_align("center")
        self.pix.set_brush(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
        self.pix.move_to(self.x, self.y)
        self.speed = random.randint(2, 6)

    def set_speed_up(self):
        self.speed += 1
        if self.speed >= 30:
            self.speed = 30

    def set_speed_down(self):
        self.speed -= 1
        if self.speed <= 2:
            self.speed = 2

    def speed_re(self):
        self.speed = random.randint(3, 8)

    def start(self):
        self.pix.show()
        self.pix.set_brush(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
        self.x = random.randint(2, 125)
        self.y = -1
        self.pix.move_to(self.x, self.y)

    def move(self):
        if self.pix.get_y() > 128:
            self.start()
        self.pix.move_y(self.speed)

        
class Player:
    def __init__(self):
        cyberpi.led.on('b')
        self.point = 0
        self.player = cyberpi.sprite()
        self.player.draw_pixels(
            [0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff,
             0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff,
             0x1eaaff, 0x1eaaff, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000])
        self.player.move_to(64, 64)

    def reset(self):
        self.point = 0
        cyberpi.led.on('b')
        self.player.move_to(64, 64)

    def collide_detect(self):
        self.player_x = 64 - -cyberpi.get_roll()
        self.player_y = 64 - -cyberpi.get_pitch()
        if self.player_x < 0:
            self.player_x = 5
        if self.player_x > 128:
            self.player_x = 123
        if self.player_y < 0:
            self.player_y = 5
        if self.player_y > 128:
            self.player_y = 123
        self.player.move_to(self.player_x, self.player_y)

    def control(self, *para):
        self.collide_detect()
        for item in para:
            if self.player.is_touch(item.pix):
                item.pix.hide()
                self.point += 1
                print(self.point)
                num = math.floor(self.point / 4)
                cyberpi.led.off(id=6 - num)
                if self.point >= 20:
                    cyberpi.audio.play('prompt-tone')
                    return False


first = Player()
a = Enemy()
b = Enemy()
c = Enemy()
d = Enemy()
e = Enemy()
f = Enemy()
g = Enemy()
h = Enemy()
enemy_list = [a, b, c, e, f, g, h]
cyberpi.console.println("体感小飞机 上键加速 下键减速 灯光为血条")
cyberpi.console.println("A键重新开始")
cyberpi.console.println("B键开始游戏")
time.sleep(5)
while True:
    first.control(*enemy_list)
    cyberpi.screen.render()
    if cyberpi.controller.is_press("B"):
        cyberpi.display.clear()
        break
cyberpi.screen.render()
time.sleep(1)
while True:
    if first.control(*enemy_list) is False:
        cyberpi.led.on('r')
        cyberpi.display.label("GameOver", 24, 'center')
        cyberpi.audio.play('prompt-tone')
        while True:
            if cyberpi.controller.is_press('A'):
                first.reset()
                cyberpi.screen.render()
                time.sleep(2)
                for i in enemy_list:
                    i.start()
                    i.speed_re()
                cyberpi.screen.render()
                break
    for i in enemy_list:
        i.move()
    if cyberpi.controller.is_press('up'):
        for i in enemy_list:
            i.set_speed_up()
    if cyberpi.controller.is_press('down'):
        for i in enemy_list:
            i.set_speed_down()
    cyberpi.screen.render()
""""
名称：064 童芯派 面向对象 体感小飞机
硬件： 童芯派
功能介绍：
使用童芯派的精灵功能在屏幕上编写了一个基于陀螺仪控制的体感小游戏，控制角色飞机躲避空中的子弹。

难度：⭐⭐⭐
支持的模式：上传模式
无

"""
# ---------程序分割线----------------程序分割线----------------程序分割线----------
import cyberpi
import random
import math
import time

class Enemy:
    def __init__(self):
        self.x = random.randint(0, 128)
        self.y = -1
        self.pix = cyberpi.sprite()
        self.pix.draw_pixels(
            [0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0xf5a623, 0xf5a623, 0xf5a623, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xf5a623,
             0xf5a623, 0xf5a623, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0xf5a623, 0xf5a623, 0xf5a623, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000])
        self.pix.set_align("center")
        self.pix.set_brush(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
        self.pix.move_to(self.x, self.y)
        self.speed = random.randint(2, 6)

    def set_speed_up(self):
        self.speed += 1
        if self.speed >= 30:
            self.speed = 30

    def set_speed_down(self):
        self.speed -= 1
        if self.speed <= 2:
            self.speed = 2

    def speed_re(self):
        self.speed = random.randint(3, 8)

    def start(self):
        self.pix.show()
        self.pix.set_brush(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
        self.x = random.randint(2, 125)
        self.y = -1
        self.pix.move_to(self.x, self.y)

    def move(self):
        if self.pix.get_y() > 128:
            self.start()
        self.pix.move_y(self.speed)

        
class Player:
    def __init__(self):
        cyberpi.led.on('b')
        self.point = 0
        self.player = cyberpi.sprite()
        self.player.draw_pixels(
            [0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff,
             0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x1eaaff, 0x1eaaff,
             0x1eaaff, 0x1eaaff, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
             0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000])
        self.player.move_to(64, 64)

    def reset(self):
        self.point = 0
        cyberpi.led.on('b')
        self.player.move_to(64, 64)

    def collide_detect(self):
        self.player_x = 64 - -cyberpi.get_roll()
        self.player_y = 64 - -cyberpi.get_pitch()
        if self.player_x < 0:
            self.player_x = 5
        if self.player_x > 128:
            self.player_x = 123
        if self.player_y < 0:
            self.player_y = 5
        if self.player_y > 128:
            self.player_y = 123
        self.player.move_to(self.player_x, self.player_y)

    def control(self, *para):
        self.collide_detect()
        for item in para:
            if self.player.is_touch(item.pix):
                item.pix.hide()
                self.point += 1
                print(self.point)
                num = math.floor(self.point / 4)
                cyberpi.led.off(id=6 - num)
                if self.point >= 20:
                    cyberpi.audio.play('prompt-tone')
                    return False


first = Player()
a = Enemy()
b = Enemy()
c = Enemy()
d = Enemy()
e = Enemy()
f = Enemy()
g = Enemy()
h = Enemy()
enemy_list = [a, b, c, e, f, g, h]
cyberpi.console.println("体感小飞机 上键加速 下键减速 灯光为血条")
cyberpi.console.println("A键重新开始")
cyberpi.console.println("B键开始游戏")
time.sleep(5)
while True:
    first.control(*enemy_list)
    cyberpi.screen.render()
    if cyberpi.controller.is_press("B"):
        cyberpi.display.clear()
        break
cyberpi.screen.render()
time.sleep(1)
while True:
    if first.control(*enemy_list) is False:
        cyberpi.led.on('r')
        cyberpi.display.label("GameOver", 24, 'center')
        cyberpi.audio.play('prompt-tone')
        while True:
            if cyberpi.controller.is_press('A'):
                first.reset()
                cyberpi.screen.render()
                time.sleep(2)
                for i in enemy_list:
                    i.start()
                    i.speed_re()
                cyberpi.screen.render()
                break
    for i in enemy_list:
        i.move()
    if cyberpi.controller.is_press('up'):
        for i in enemy_list:
            i.set_speed_up()
    if cyberpi.controller.is_press('down'):
        for i in enemy_list:
            i.set_speed_down()
    cyberpi.screen.render()
" 名称：064 童芯派 面向对象 体感小飞机 硬件： 童芯派 功能介绍： 使用童芯派的精灵功能在屏幕上编写了一个基于陀螺仪控制的体感小游戏，控制角色飞机躲避空中的子弹。  难度：⭐⭐⭐ 支持的模式：上传模式 无 # ---------程序分割线----------------程序分割线----------------程序分割线----------