def start(lap_delta, max_reaction_time): # Draw the red start lights one at a time clear_screen() display.set_pen(255, 0, 0) for light in range(5): display.circle(40 + (light * 40), 50, 10) display.update() utime.sleep(1) delay = math.fmod(utime.ticks_ms(), 4) + 1 utime.sleep(delay) # Random delay before go lights out # Remove lights display.set_pen(0, 0, 0) display.rectangle(20, 35, 200, 30) # No effect until next display.update() # Click the correct side to "Go" display.set_pen(0, 255, 0) # Green for GO # display.circle(120, 50, 20) # Pick side randomly for the start button, indicated by GO side = random.choice(["<", ">"]) if side == "<": display.text("G0", 20, 105, 240, 2) else: display.text("G0", 200, 105, 240, 2) # Cover up start lights and display "Go" display.update() # Time the user's reaction lap_delta += time_user(side, max_reaction_time) return lap_delta
def straight(lead_time): clear_screen() # Green circle for Go, straight-ahead until next turn display.set_pen(0, 255, 0) display.circle(120, 50, 20) display.update() # Leave straight-ahead on screen for the length of the straight utime.sleep(lead_time) # Clear screen, small pause for transistion clear_screen() utime.sleep_ms(1)
def show(self): food_x, food_y = self.pos food_red, food_green, food_blue = food_color display.set_pen(food_red, food_green, food_blue) # calculate center of tile on canvas tile_x = (tile_size * food_x) + tile_size//2 tile_y = (tile_size * food_y) + tile_size//2 radius = (tile_size-2)//2 display.circle(tile_x, tile_y, radius)
def show(self): snake_red, snake_green, snake_blue = snake_color display.set_pen(snake_red, snake_green, snake_blue) current_node = self.head while current_node != None: if current_node != self.head: x1, y1 = current_node.pos x2, y2 = previous_node.pos invisible = (abs(x1-x2)>1)or(abs(y1-y2)>1) if not invisible: x1 *= tile_size y1 *= tile_size x2 *= tile_size y2 *= tile_size x1 += tile_size//2 y1 += tile_size//2 x2 += tile_size//2 y2 += tile_size//2 self.line(x1, y1, x2, y2) else: # draw circle for snake head grid_x, grid_y = current_node.pos canvas_x = (tile_size * grid_x) canvas_y = (tile_size * grid_y) center_x = canvas_x+(tile_size//2) center_y = canvas_y+(tile_size//2) radius = (tile_size-4)//2 display.circle(center_x, center_y, radius) previous_node = current_node current_node = current_node.next
ball.x += ball.dx ball.y += ball.dy if ball.x <= 0: if ball.y > bat.y + 25 or ball.y < bat.y: #display.set_led(255,0,0) ball.dx = 0 ball.dy = 0 ball.x = 500 ball.y = 500 if ball.x < 0 or ball.x > width: ball.dx *= -1 if ball.y < 0 or ball.y > height: ball.dy *= -1 display.set_pen(ball.pen) display.circle(int(ball.x), int(ball.y), int(ball.r)) if display.is_pressed(display.BUTTON_Y) and bat.y < height - 25: bat.y = bat.y + 1 if display.is_pressed(display.BUTTON_X) and bat.y > 0: bat.y = bat.y - 1 display.set_pen(100, 100, 100) display.rectangle(0, bat.y, 10, 25) if display.is_pressed(display.BUTTON_B): display.set_led(0, 0, 0) display.update()
for ufo in area51: ufo.x += ufo.dx ufo.y += ufo.dy if ufo.x < 0 or ufo.x > width: ufo.dx *= -1 if ufo.y < 0 or ufo.y > height: ufo.dy *= -1 if missile.active: if (ufo.x > missile.x - ufo.r and ufo.x < missile.x + ufo.r) and ( ufo.y > missile.y - ufo.r and ufo.y < missile.y + ufo.r): missile.active = False display.set_pen(255, 255, 255) display.circle(int(ufo.x), int(ufo.y), int(ufo.r) + 5) ufo.dx = 0 ufo.dy = 0 ufo.x = 500 ufo.y = 500 display.set_pen(ufo.pen) drawufo((ufo.x), int(ufo.y), int(ufo.r), ufo.pen) if display.is_pressed(display.BUTTON_Y) and bat.y < height - 25: bat.y = bat.y + 1 if display.is_pressed(display.BUTTON_X) and bat.y > 0: bat.y = bat.y - 1 display.set_pen(100, 100, 100) display.rectangle(width - 10, bat.y, 10, 20)
while plane.flying: display.set_pen(black) display.clear() for tree in jungle: drawtree(tree.x, tree.treeheight) if missile.active: if missile.x >= tree.x * 10 and missile.x <= ( (tree.x + 1) * 10) - 1: if missile.y >= height - tree.treeheight * 10: missile.active = False tree.treeheight -= 5 display.set_pen(brightwhite) display.circle(missile.x, missile.y, 10) if plane.x + 20 == tree.x * 10 and plane.y + 10 == height - ( tree.treeheight * 10): plane.crashed = True display.set_pen(brightwhite) display.circle(plane.x, plane.y, 10) #draw the plane drawplane(plane.x, plane.y) #move the plane if not plane.crashed: if plane.x < width: plane.x += 1 else:
while plane.flying: display.set_pen(black) display.clear() for tree in jungle: drawtree(tree.x, tree.treeheight) if missile.active: if missile.x >= tree.x * 10 and missile.x <= ( (tree.x + 1) * 10) - 1: if missile.y >= height - tree.treeheight * 10: missile.active = False tree.treeheight -= 5 display.set_pen(brightwhite) display.circle(missile.x, missile.y, 10) if plane.x + 20 == tree.x * 10 and plane.y + 10 == height - ( tree.treeheight * 10): plane.crashed = True display.set_pen(brightwhite) display.circle(plane.x + 10, plane.y + 5, 10) #draw the plane drawplane(plane.x, plane.y) #move the plane if not plane.crashed: if plane.x < width: plane.x += 1 else: