def draw(self):
     """Draw all columns of wall."""
     for x in range(WIDTH):
         for y in range(HEIGHT):
             bottom, top = self.wall[x]
             if y < bottom or y > top:
                 led_matrix.point(x, y, color=int(self.color)) # draw wall with less brightness
 def draw(self):
     """Draw all columns of wall."""
     for x in range(WIDTH):
         for y in range(HEIGHT):
             bottom, top = self.wall[x]
             if y < bottom or y > top:
                 led_matrix.point(x, y, color=int(
                     self.color))  # draw wall with less brightness
Example #3
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)
Example #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)
    def update(self):
        global state
        self.bounced_x = False
        self.bounced_y = False
        self.can_move_x = True
        self.can_move_y = True
#        Player wins if there are no more bricks
        if len(bricks) == 0:
            state = State.WIN
            return
#        Bounce off edge of screen
        if self.pos[1] >= 15 and self.dir[1] == 1:
            self.dir[1] = -1
        if self.pos[0] <= 0 and self.dir[0] == -1:
            self.dir[0] = 1
        if self.pos[0] >= 15 and self.dir[0] == 1:
            self.dir[0] = -1

#        Loop through bricks and check for collisions
        self.brick_col()

#        If one col check to see if we are inbetween two bricks
        if self.bounced_x or self.bounced_y:
            self.brick_col()

#        If the ball hits the paddle reverse its y direction                            
        if (self.pos[1] + self.dir[1] == p.pos[1]) and (self.pos[0] + self.dir[0] >= p.pos[0]) and (self.pos[0] + self.dir[0] < p.pos[0] + p.size[0]):
            self.dir[1] = -self.dir[1]
#        Lose if the ball passes the paddle
        if self.pos[1] <= 0:
            for i in range(4):
                led_matrix.point(self.pos[0], self.pos[1])
                led_matrix.show()
                time.sleep(0.1)
                led_matrix.point(self.pos[0], self.pos[1], 0)
                led_matrix.show()
                time.sleep(0.1)
            state = State.LOSE
            return
        if self.can_move_x:
            self.pos[0] = clamp(self.pos[0] + self.dir[0], 0, 15)
        if self.can_move_y:
            self.pos[1] = clamp(self.pos[1] + self.dir[1], 0, 15)
def draw_grid():
    """Draws the current generation to led_matrix."""
    for y in range(num_rows):
        for x in range(num_cols):
            led_matrix.point(x, y, curr_gen[y][x])
Example #7
0
def draw_grid():
    """Draws the current generation to led_matrix."""
    for y in range(num_rows):
        for x in range(num_cols):
            led_matrix.point(x, y, curr_gen[y][x])
Example #8
0
 def draw(self):
     led_matrix.point(*self.position, color=8)
 def draw(self):
     led_matrix.point(self.x(), self.y())
#	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)
Example #11
0
 def draw(self):
     for point in self.body:
         led_matrix.point(point)
Example #12
0
 def draw_apple(self):
     led_matrix.point(self.apple, color=9)
Example #13
0
 def draw(self):
     """Draws block on led matrix display"""
     x_start, y_start = self.origin
     for x_offset in range(self.width):
         led_matrix.point(x_start + x_offset, y_start, self.color)
        scroll_text("SPACE INVADERS!!!")
        
    elif state == State.PLAYING:
#    	Clear previous framebuffer    
        led_matrix.fill(0)

#    	Player wins if no more enemies are left
        if len(enemies) == 0:
            state == State.WIN
            continue

#  		Redraw enemies and update if its their game tick
        for e in enemies:
            if game_tick%enemy_tick == 0 and not game_tick == 0:
                e.update()
            led_matrix.point(e.pos[0], e.pos[1])
        if state != State.PLAYING:
            continue

# 	    Update and redraw missles
        for m in missles:
            m.update()    
            led_matrix.point(m.pos[0], m.pos[1])

#   	Check for collisions
        for m in missles:
            for e in enemies:
                if m.pos == e.pos:
                    enemies.remove(e)
                    missles.remove(m)
#   	Get angles from accelerometer
 def draw(self):
     led_matrix.point(*self.origin, color=int(self.color))
Example #16
0
 def draw(self):
     """Draws block on led matrix display"""
     x_start, y_start = self.origin
     for x_offset in range(self.width):
         led_matrix.point(x_start + x_offset, y_start, self.color)
Example #17
0
 def draw(self):
     led_matrix.point(self.x(), self.y())
Example #18
0
 def draw_apple(self):
     led_matrix.point(self.apple, color=9)
Example #19
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))
    
    elif state == State.EXIT:
        led_matrix.cleanup()
        GPIO.cleanup()
Example #20
0
 def draw(self):
     for point in self.body:
         led_matrix.point(point)
try:
#    Start game
    while True:

#       Clear previous framebuffer    
        led_matrix.fill(0)
        
#       Get angles from accelerometer
        data = accel.angles()

#       Generate smooth movement data using IIR filter, and make a 1/4 turn move
#       the player to the edge of the screen
        player_pos[0] = player_pos[0] + (clamp(data[0]*8*4/90 + 7) - player_pos[0])*0.1
    
#       Draw player
        led_matrix.point(int(round(player_pos[0])), int(round(player_pos[1])))

#       Show framebuffer
        led_matrix.show()

#       Delay one game tick, in this case 1ms
        time.sleep(0.001)

#Stop if player hits Ctrl-C
except KeyboardInterrupt:
        pass

#Clean everything up
finally:
        led_matrix.cleanup()
 def draw(self):
     led_matrix.point(*self.origin, color=int(self.color))
        self.pos[0] = self.pos[0] + self.dir[0]
        self.pos[1] = self.pos[1] + self.dir[1]
        if self.pos[1] > 15 or self.pos[1] < 0 or self.pos[0] < 0 or self.pos[
                1] > 15:
            missles.remove(self)
try:
    #   Start game
    while True:

        #       Clear previous framebuffer
        led_matrix.fill(0)

        #       Update and redraw missles
        for m in missles:
            m.update()
            led_matrix.point(m.pos[0], m.pos[1])

#       Get angles from accelerometer
        data = accel.angles()

        #       Generate smooth movement data using IIR filter, and make a 1/4 turn move
        #       the player to the edge of the screen
        player_pos[0] = player_pos[0] + (clamp(data[0] * 8 * 4 / 90 + 7) -
                                         player_pos[0]) * 0.1

        #       Draw player
        led_matrix.point(int(round(player_pos[0])), int(round(player_pos[1])))

        #       Show framebuffer
        led_matrix.show()
Example #24
0
 def draw(self):
     led_matrix.point(*self.position, color=3)