示例#1
0
def show_snake():
    global snake_list
    for i in range(len(snake_list)):
        if i == 0:
            codey.pixel_off(snake_list[i][0], snake_list[i][1])
        else:
            codey.pixel(snake_list[i][0], snake_list[i][1])
示例#2
0
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
示例#3
0
def face_update():
    global barrier_list
    for i in range(BARRIER_MAX_NUM):
        if barrier_list[i][0] == True:
            codey.pixel_off(barrier_list[i][1], barrier_list[i][2] - 1)
            if barrier_list[i][2] >= FACE_LINE:
                barrier_list[i][0] = False
            else:
                codey.pixel(barrier_list[i][1], barrier_list[i][2])
        else:
            codey.pixel_off(barrier_list[i][1], barrier_list[i][2])
示例#4
0
def ledm_test():
    print("all led on")
    codey.face("ffffffffffffffffffffffffffffffff", 3)
    print("all led off")
    print('(0, 0) on')
    codey.pixel(0, 0)
    time.sleep(1)
    print("(0, 0) off")
    codey.pixel_off(0, 0)
    time.sleep(1)
    print("(0, 0) toggle")
    codey.pixel_toggle(0, 0)
    time.sleep(1)
示例#5
0
def point_create():
    global food_point
    global user_score
    global game_status
    user_score += 1
    p_x = random.randint(0, 15)
    p_y = random.randint(0, 7)

    order = random.randint(0, 3)
    for item in food_create_order_list[order]:
        out_point = check_region_not_full(p_x, p_y, item)
        if out_point == None:
            if item == food_create_order_list[order][-1]:
                game_status = GAME_PASS
            else:
                continue
        else:
            food_point = out_point
            codey.pixel(food_point[0], food_point[1])
            return food_point

    return None
示例#6
0
def plane_run(p_x_c, p_x_l):
    if p_x_c != p_x_l:
        codey.pixel_off(p_x_l, 7)
        codey.pixel_off(p_x_l + 1, 6)
        codey.pixel_off(p_x_l + 2, 7)

        codey.pixel(p_x_c, 7)
        codey.pixel(p_x_c + 1, 6)
        codey.pixel(p_x_c + 2, 7)
示例#7
0
def shoot():
    global plane_cur_pos
    global plane_last_pos
    global barrier_list

    pos = 5
    codey.pixel(plane_cur_pos + 1, pos)
    codey.pixel(plane_cur_pos + 1, pos - 1)
    codey.pixel(plane_cur_pos + 1, pos - 2)
    time.sleep(0.01)
    codey.pixel_off(plane_cur_pos + 1, pos)
    codey.pixel(plane_cur_pos + 1, pos - 3)
    time.sleep(0.01)
    codey.pixel_off(plane_cur_pos + 1, pos - 1)
    codey.pixel(plane_cur_pos + 1, pos - 4)
    time.sleep(0.01)
    codey.pixel_off(plane_cur_pos + 1, pos - 2)
    codey.pixel(plane_cur_pos + 1, pos - 5)
    time.sleep(0.01)
    codey.pixel_off(plane_cur_pos + 1, pos - 3)
    time.sleep(0.01)
    codey.pixel_off(plane_cur_pos + 1, pos - 4)
    time.sleep(0.01)
    codey.pixel_off(plane_cur_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_cur_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])
示例#8
0
    elif game_status == GAME_PLAYING:
        if codey.is_tilt('forward'):
            if move_dir_last != MOVE_DOWN:
                move_dir = MOVE_UP
        elif codey.is_tilt('backward'):
            if move_dir_last != MOVE_UP:
                move_dir = MOVE_DOWN
        elif codey.is_tilt('left'):
            if move_dir_last != MOVE_RIGHT:
                move_dir = MOVE_LEFT
        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]
示例#9
0
        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)
codey.pause(0.25)
codey.play_freq(700, 1)