Beispiel #1
0
 def draw(self):
     led_matrix.line((self.x_pos, 0), (self.x_pos, led_matrix.height() - 1))
     # draw the next piece
     next_piece.draw(pos=(self.x_pos + 3, led_matrix.height() - 5))
     # draw the score (aligned nicely)
     if score < 10:
         led_matrix.text(str(score), (self.x_pos + 5, 1))
     else:
         led_matrix.text(str(score), (self.x_pos + 1, 1))
 def draw(self):
     led_matrix.line((self.x_pos, 0), (self.x_pos, led_matrix.height()-1))
     # draw the next piece
     next_piece.draw(pos=(self.x_pos + 3, led_matrix.height() - 5))
     # draw the score (aligned nicely)
     if score < 10:
         led_matrix.text(str(score), (self.x_pos + 5, 1))
     else:
         led_matrix.text(str(score), (self.x_pos + 1, 1))
 def draw(self, blinking_off=False):
     """Draws stack on led display
     @param blinking_off: If set, it will display full lines as a line of all color == 0.
         Useful for blinking full lines.
     @type blinking_off: boolean
     """
     for y, line in enumerate(self.points):
         # show a line of color == 0 for full lines if currently blinking off
         if blinking_off and all(pixel != 16 for pixel in line):  # short-circuit avoids heavy computation if not needed
             led_matrix.line((0,y), (self.width-1, y), color=0)
         else:
             for x, pixel in enumerate(line):
                 led_matrix.point(x, y, pixel)
Beispiel #4
0
 def draw(self, blinking_off=False):
     """Draws stack on led display
     @param blinking_off: If set, it will display full lines as a line of all color == 0.
         Useful for blinking full lines.
     @type blinking_off: boolean
     """
     for y, line in enumerate(self.points):
         # show a line of color == 0 for full lines if currently blinking off
         if blinking_off and all(
                 pixel != 16 for pixel in line
         ):  # short-circuit avoids heavy computation if not needed
             led_matrix.line((0, y), (self.width - 1, y), color=0)
         else:
             for x, pixel in enumerate(line):
                 led_matrix.point(x, y, pixel)
#	Clear frame buffer
	led_matrix.fill(0)
#	Get angle data
	angles = accel.angles()
#	Simple lowpass filter for velocity data
	velocity = velocity*alpha + (angles[0]*2*8/90)*(1 - alpha)
#	Move player's paddle
	player_pos = player_pos + velocity
	player_pos = clamp(player_pos, 0, 15 - (p.size[0] - 1))
#	If the paddle hits the edge the velocity can't be into the edge
	if int(player_pos) <= 0 and velocity < 0:
		velocity = 0
	elif int(player_pos) >= 15 and velocity > 0:
		velcoity = 0
#	Move player
	p.move(player_pos)
#	Update physics
	if ball_tick == 0:
		ball.update()
#	Display player, bricks, and the ball
	led_matrix.line(p.pos, [p.pos[0] + p.size[0] - 1, 0])
	for b in bricks:
		for y in range(b.size[1]):
			led_matrix.line((b.pos[0], b.pos[1]+y),(b.pos[0] + b.size[0] - 1, b.pos[1] + y), b.brightness)
	led_matrix.point(ball.pos[0], ball.pos[1])
	led_matrix.show()

#	Delay and increase game tick
	time.sleep(0.1)
	ball_tick = (ball_tick + 1) & (MAX_BALL_TICK - 1)
        player_pos = player_pos + velocity
        player_pos = clamp(player_pos, 0, 15 - (p.size[0] - 1))
    #    If the paddle hits the edge the velocity can't be into the edge
        if int(player_pos) <= 0 and velocity < 0:
            velocity = 0
        elif int(player_pos) >= 15 and velocity > 0:
            velcoity = 0
    #    Move player
        p.move(player_pos)
    #    Update physics
        if ball_tick == 0:
            ball.update()
            if state != State.PLAYING:
                break
    #    Display player, bricks, and the ball
        led_matrix.line(p.pos, [p.pos[0] + p.size[0] - 1, 0])
        for b in bricks:
            for y in range(b.size[1]):
                led_matrix.line((b.pos[0], b.pos[1]+y),(b.pos[0] + b.size[0] - 1, b.pos[1] + y), b.brightness)
        led_matrix.point(ball.pos[0], ball.pos[1])
        led_matrix.show()

    #    Delay and increase game tick
        time.sleep(0.1)
        ball_tick = (ball_tick + 1) & (MAX_BALL_TICK - 1)
    
    elif state == State.LOSE:
        scroll_text("You lost! Score: %i" % (score))
        
    elif state == State.WIN:
        scroll_text("You won! Score: %i" % (score))
Beispiel #7
0
#Declare paddle for use in ball class
p = Paddle([7, 0], [4, 0])

#Initialize player movement data
velocity = 0.0
player_pos = 7.0
alpha = 0.1

while True:
#	Clear frame buffer
	led_matrix.fill(0)
#	Get angle data
	angles = accel.angles()
#	Simple lowpass filter for velocity data
	velocity = velocity*alpha + (angles[0]*8/90)*(1 - alpha)
#	Move player's paddle
	player_pos = player_pos + velocity
	player_pos = clamp(player_pos, 0, 15 - (p.size[0] - 1))
#	If the paddle hits the edge the velocity can't be into the edge
	if int(player_pos) <= 0 and velocity < 0:
		velocity = 0
	elif int(player_pos) >= 15 and velocity > 0:
		velcoity = 0
#	Move player and update physics
	p.move(player_pos)
#	Display paddle
	led_matrix.line(p.pos, [p.pos[0] + p.size[0] - 1, 0])
#	Display player and wait slightly
	led_matrix.show()
	time.sleep(0.01)
Beispiel #8
0
 def draw(self):
     for offset in range(self.width):
         x = self.x_position + offset
         led_matrix.line((x, 0), (x, self.opening_location - 1))
         led_matrix.line((x, self.opening_location + self.opening_height),
                         (x, led_matrix.height()))
            # display title in the center of the screen
            led_matrix.erase()
            led_matrix.sprite(
                title,
                (int(led_matrix.width() / 2) - int(title.width / 2), y_pos))
            led_matrix.show()
            y_pos += 1
            time.sleep(.1)

    elif curr_state == State.PLAYING:
        # show the blocks
        led_matrix.erase()
        draw_blocks()
        # draw edge lines if not whole screen
        if LEFT_EDGE != 0:
            led_matrix.line((LEFT_EDGE, 0), (LEFT_EDGE, HEIGHT - 1))
        if RIGHT_EDGE != WIDTH:
            led_matrix.line((RIGHT_EDGE, 0), (RIGHT_EDGE, HEIGHT - 1))

        led_matrix.show()
        time.sleep(1.0 / curr_speed)

        #            global button_pressed
        if blocks[-1].moving:
            # change direction if hit edge of screen
            if curr_direction == Direction.RIGHT:
                if blocks[-1].origin[0] + blocks[-1].width == RIGHT_EDGE:
                    curr_direction = Direction.LEFT
            elif blocks[-1].origin[0] == LEFT_EDGE + 1:
                curr_direction = Direction.RIGHT
                break
            # display title in the center of the screen
            led_matrix.erase()
            led_matrix.sprite(title, (int(led_matrix.width()/2) - int(title.width/2), y_pos))
            led_matrix.show()
            y_pos += 1
            time.sleep(.1)
        

    elif curr_state == State.PLAYING:
        # show the blocks
        led_matrix.erase()
        draw_blocks()
        # draw edge lines if not whole screen
        if LEFT_EDGE != 0:
            led_matrix.line((LEFT_EDGE, 0), (LEFT_EDGE, HEIGHT-1))
        if RIGHT_EDGE != WIDTH:
            led_matrix.line((RIGHT_EDGE, 0), (RIGHT_EDGE, HEIGHT-1))
        
        led_matrix.show()
        time.sleep(1.0/curr_speed)
    
#            global button_pressed
        if blocks[-1].moving:
            # change direction if hit edge of screen
            if curr_direction == Direction.RIGHT:
                if blocks[-1].origin[0] + blocks[-1].width == RIGHT_EDGE:
                    curr_direction = Direction.LEFT
            elif blocks[-1].origin[0] == LEFT_EDGE+1:
                curr_direction = Direction.RIGHT
                
 def draw(self):
     for offset in range(self.width):
         x = self.x_position + offset
         led_matrix.line((x, 0), (x, self.opening_location-1))
         led_matrix.line((x, self.opening_location + self.opening_height), (x, led_matrix.height()))