Ejemplo n.º 1
0
def on_button_callback():
    codey.wifi_close()
    codey.wifi('Maker-guest', 'makeblock')
    while not codey.wifi_is_connected():
        pass

    codey.color('#1dff00', 1)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def game_over_check():
    global game_status
    global axis_y
    global background_face
    #print('the string is', background_face[14 : 16], 'y is ', axis_y)

    if axis_y <= 0:
        codey.color("#ff0000")
        game_status = GAME_OVER
        return

    if int(background_face[14:16], 16) & (1 << (7 - axis_y)):
        print('a is', int(background_face[14:16], 16), 'y is', axis_y)
        codey.color("#ff0000")
        game_status = GAME_OVER
Ejemplo n.º 6
0
def game_over_check():
    global plane_cur_pos
    global plane_last_pos
    global barrier_list 
    global game_status
    for i in range(BARRIER_MAX_NUM):
        if barrier_list[i][0] == True:
            if barrier_list[i][1] >= plane_cur_pos and barrier_list[i][1] <= (plane_cur_pos + 2):
                if barrier_list[i][1] == plane_cur_pos + 1:
                    if barrier_list[i][2] >= 6:
                        game_status = GAME_OVER
                        codey.color("#ff0000", 1)
                else:
                    if barrier_list[i][2] == 7:
                        game_status = GAME_OVER
                        codey.color("#ff0000", 1)
Ejemplo n.º 7
0
def game_init():
    global run_speed
    global background_face
    global add_space_flag
    global last_column_data
    global user_score
    global axis_y
    global count
    global down_lock
    global music_lock

    run_speed = 40
    background_face = START_FACE
    add_space_flag = 0
    last_column_data = '00'
    user_score = 0
    axis_y = 3
    count = 0
    down_lock = False
    music_lock = False
    codey.color("#000000")
def rgb_test():
    print("red on")
    codey.color("#ff0000", 1)
    print("green on")
    codey.color("#00ff00", 1)
    print("blue on")
    codey.color("#0000ff", 1)
Ejemplo n.º 9
0
def rgb_test():
    print("red on")
    codey.color("#ff0000", 1)
    print("green on")
    codey.color("#00ff00", 1)
    print("blue on")
    codey.color("#0000ff", 1)
    print("single red on")
    codey.red(255)
    time.sleep(1)
    print("single green on")
    codey.green(255)
    time.sleep(1)
    print("single blue on")
    codey.blue(255)
    time.sleep(1)
    print("single red off")
    codey.red(0)
    time.sleep(1) 
    print("single green off")
    codey.green(0)
    time.sleep(1)
    print("single blue off")
    codey.blue(0)       
    time.sleep(1)
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
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')
Ejemplo n.º 12
0
        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)
    time.sleep(0.1)
Ejemplo n.º 13
0
def on_tilt3_callback():
    codey.color('#ffffff', 1)
Ejemplo n.º 14
0
def on_tilt2_callback():
    codey.color('#3f00ff', 1)
Ejemplo n.º 15
0
def on_tilt1_callback():
    codey.color('#7fff00', 1)
Ejemplo n.º 16
0
def on_tilt_callback():
    codey.color('#ff0000', 1)
Ejemplo n.º 17
0
def on_sound_over_callback():
    global test_num
    test_num = 5
    codey.color("#000ff0", 0.5)
Ejemplo n.º 18
0
def on_tilt3_callback():
    global test_num
    test_num = 4
    codey.color("#223344", 0.5)
Ejemplo n.º 19
0
def on_tilt_callback():
    global test_num
    test_num = 1
    codey.color("#ff000", 0.5)
def on_button2_callback():
    global test_num
    test_num = 3
    codey.color("#ff0000", 0.2)
def on_light_under_callback():
    global test_num
    test_num = 5
    codey.color("#ff0000", 0.2)
Ejemplo n.º 22
0
def on_tilt1_callback():
    global test_num
    test_num = 2
    codey.color("#0000ff", 0.5)
Ejemplo n.º 23
0
def on_button2_callback():
    global a
    codey.color('#ff0000', 1)
Ejemplo n.º 24
0
def on_message1_callback():
    codey.color('#ff0000', 1)
    while True:
        iot.list_add('r', iot.weather('2161853', '0'))
Ejemplo n.º 25
0
    

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)
codey.pause(0.25)
codey.play_freq(700, 1)
codey.change_volume(-10)
codey.set_volume(100)
codey.get_volume()
Ejemplo n.º 26
0
def on_tilt2_callback():
    global test_num
    test_num = 3
    codey.color("#ffffff", 0.5)