diff --git a/demos/autotype/main.py b/demos/autotype/main.py index 33ba186..66e9ebf 100644 --- a/demos/autotype/main.py +++ b/demos/autotype/main.py @@ -33,7 +33,7 @@ def run(self): x_cursor = 0 y_cursor = 0 - pixel_vals = np.zeros((self.screen.x_width, self.screen.y_height)) + pixel_vals = np.zeros((self.screen.width, self.screen.height)) nephi = "And it came to pass that I, Nephi, said unto my father: I will go and do the things which the Lord hath commanded, for I know that the Lord giveth no commandments unto the children of men, save he shall prepare a way for them that they may accomplish the thing which he commandeth them." preamble = "We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defense, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America." @@ -45,10 +45,10 @@ def run(self): while True: for word in typed_text: - if self.screen.x_width - x_cursor < len(word): + if self.screen.width - x_cursor < len(word): x_cursor = 0 y_cursor += 2 - if y_cursor >= self.screen.y_height: + if y_cursor >= self.screen.height: y_cursor -= 2 # print(self.screen.get_pixel(0, 0)) @@ -57,22 +57,18 @@ def run(self): # print(self.screen.get_pixel(1, 0)) # print(self.screen.get_pixel(1, 1)) - for y in range(self.screen.y_height): - for x in range(self.screen.x_width): + for y in range(self.screen.height): + for x in range(self.screen.width): pixel_vals[y][x] = self.screen.get_pixel(x, y) pixel_vals = np.delete(pixel_vals, 0, 0) pixel_vals = np.delete(pixel_vals, 0, 0) - pixel_vals = np.append( - pixel_vals, [np.zeros(self.screen.x_width)], 0 - ) - pixel_vals = np.append( - pixel_vals, [np.zeros(self.screen.x_width)], 0 - ) + pixel_vals = np.append(pixel_vals, [np.zeros(self.screen.width)], 0) + pixel_vals = np.append(pixel_vals, [np.zeros(self.screen.width)], 0) self.screen.clear() - for y in range(self.screen.y_height): - for x in range(self.screen.x_width): + for y in range(self.screen.height): + for x in range(self.screen.width): self.screen.draw_pixel(x, y, int(pixel_vals[y][x])) self.screen.push() yield @@ -80,7 +76,7 @@ def run(self): self.screen.draw_text(x_cursor, y_cursor, char, push=True) x_cursor += 1 yield - if self.screen.x_width - x_cursor > 0: + if self.screen.width - x_cursor > 0: self.screen.draw_text(x_cursor, y_cursor, " ", push=True) x_cursor += 1 yield diff --git a/demos/breakout/main.py b/demos/breakout/main.py index 2b9cd63..33ace5e 100644 --- a/demos/breakout/main.py +++ b/demos/breakout/main.py @@ -66,15 +66,11 @@ def run(self): restart_cnt = 10 # Waits for user ready + screen.draw_text((screen.width // 2) - 4, (screen.height // 2) - 8, "BREAKOUT") screen.draw_text( - (screen.x_width // 2) - 4, (screen.y_height // 2) - 8, "BREAKOUT" - ) - screen.draw_text( - (screen.x_width // 2) - 5, (screen.y_height // 2) - 4, "PRESS START" - ) - screen.draw_text( - (screen.x_width // 2) - 4, (screen.y_height // 2) - 2, "TO BEGIN" + (screen.width // 2) - 5, (screen.height // 2) - 4, "PRESS START" ) + screen.draw_text((screen.width // 2) - 4, (screen.height // 2) - 2, "TO BEGIN") screen.push() # Don't start until user presses start @@ -87,15 +83,11 @@ def run(self): yield # Erase startup text and initialize screen + screen.draw_text((screen.width // 2) - 4, (screen.height // 2) - 8, " ") screen.draw_text( - (screen.x_width // 2) - 4, (screen.y_height // 2) - 8, " " - ) - screen.draw_text( - (screen.x_width // 2) - 5, (screen.y_height // 2) - 4, " " - ) - screen.draw_text( - (screen.x_width // 2) - 4, (screen.y_height // 2) - 2, " " + (screen.width // 2) - 5, (screen.height // 2) - 4, " " ) + screen.draw_text((screen.width // 2) - 4, (screen.height // 2) - 2, " ") screen.push() self.init_screen(self.screen) @@ -117,8 +109,8 @@ def run(self): # Pause and unpause routine if keypress == "START_P": screen.draw_text( - (screen.x_width // 2) - 3, - (screen.y_height // 2) - 8, + (screen.width // 2) - 3, + (screen.height // 2) - 8, "PAUSED", push=True, ) @@ -133,8 +125,8 @@ def run(self): ): if keypress == "START_P": screen.draw_text( - (screen.x_width // 2) - 3, - (screen.y_height // 2) - 8, + (screen.width // 2) - 3, + (screen.height // 2) - 8, " ", push=True, ) @@ -180,14 +172,14 @@ def run(self): is_down = True # Checks to see if ball hits paddle - if self.ball[1] == screen.y_height - 2: + if self.ball[1] == screen.height - 2: if self.ball[0] in self.paddle: spin, is_left = self.get_angle(self.paddle) self.frame_rate = 20 + (spin // (1 + spin // 2)) is_down = False # Checks to see if ball falls out of screen - if self.ball[1] >= screen.y_height - 1: + if self.ball[1] >= screen.height - 1: is_down = True lives -= 1 self.frame_rate = 20 @@ -200,7 +192,7 @@ def run(self): if lives == 0: self.gameover = True break - self.ball = [screen.x_width // 2, screen.y_height // 2] + self.ball = [screen.width // 2, screen.height // 2] # Calculates ball path is_left, is_down = self.ball_travel(is_left, is_down, spin, screen) @@ -208,7 +200,7 @@ def run(self): # Quick pause to reorient if life lost if restart: restart_cnt -= 1 - self.ball = [screen.x_width // 2, screen.y_height // 2] + self.ball = [screen.width // 2, screen.height // 2] if restart_cnt == 0: restart_cnt = 10 restart = False @@ -220,13 +212,13 @@ def run(self): self.paddle[val] -= 1 screen.draw_pixel( self.paddle[0], - screen.y_height - 1, + screen.height - 1, PIXEL_ON, combine=False, ) screen.draw_pixel( self.paddle[-1] + 1, - screen.y_height - 1, + screen.height - 1, PIXEL_OFF, combine=False, ) @@ -236,13 +228,13 @@ def run(self): self.paddle[val] += 1 screen.draw_pixel( self.paddle[0] - 1, - screen.y_height - 1, + screen.height - 1, PIXEL_OFF, combine=False, ) screen.draw_pixel( self.paddle[-1], - screen.y_height - 1, + screen.height - 1, PIXEL_ON, combine=False, ) @@ -262,19 +254,19 @@ def run(self): screen.clear() screen.draw_text( - (screen.x_width // 2) - 4, (screen.y_height // 2) - 8, "GAME OVER" + (screen.width // 2) - 4, (screen.height // 2) - 8, "GAME OVER" ) screen.draw_text( - (screen.x_width // 2) - 4, (screen.y_height // 2) - 6, "---------" + (screen.width // 2) - 4, (screen.height // 2) - 6, "---------" ) screen.draw_text( - (screen.x_width // 2) - 4, - (screen.y_height // 2) - 4, + (screen.width // 2) - 4, + (screen.height // 2) - 4, "SCORE " + str(score), ) screen.draw_text( - (screen.x_width // 2) - 4, - (screen.y_height // 2) - 2, + (screen.width // 2) - 4, + (screen.height // 2) - 2, "HISCORE " + str(hscore), ) screen.push() @@ -295,22 +287,22 @@ def init_screen(self, screen): self.paddle = [24] if self.level == 1: - self.line_right = screen.x_width - ARENA_START + self.line_right = screen.width - ARENA_START self.line_left = ARENA_START - 1 - self.ball = [screen.x_width // 2, screen.y_height // 2] + self.ball = [screen.width // 2, screen.height // 2] if self.level % 2 == 0: - for pix in range(screen.y_height): + for pix in range(screen.height): screen.draw_pixel(self.line_left, pix, 0x0) screen.draw_pixel(self.line_right, pix, 0x0) self.line_left = 13 - self.level - self.line_right = (screen.x_width - ARENA_START) + self.level + self.line_right = (screen.width - ARENA_START) + self.level else: self.rows = self.level + 2 - screen.draw_vline(self.line_left, 0, screen.y_height, left=False) - screen.draw_vline(self.line_right, 0, screen.y_height) + screen.draw_vline(self.line_left, 0, screen.height, left=False) + screen.draw_vline(self.line_right, 0, screen.height) for row in range(self.rows): self.bricks[row] = [] @@ -331,10 +323,10 @@ def init_screen(self, screen): self.paddle.append(self.paddle[-1] + 1) for val in range(self.line_left + 1, self.line_right): - screen.draw_pixel(val, screen.y_height - 1, PIXEL_OFF) + screen.draw_pixel(val, screen.height - 1, PIXEL_OFF) for val in self.paddle: - screen.draw_pixel(val, screen.y_height - 1, PIXEL_ON, combine=False) + screen.draw_pixel(val, screen.height - 1, PIXEL_ON, combine=False) screen.push() @@ -401,10 +393,10 @@ def ball_travel(self, is_left, is_down, spin, screen): if is_down: # A possible conflict with ball trying to jump paddle - if (screen.y_height - 1) - (self.ball[1] + spin) <= 0 and spin > 1: + if (screen.height - 1) - (self.ball[1] + spin) <= 0 and spin > 1: for block in collide_field: if block[0] in self.paddle: - self.ball[1] = screen.y_height - 2 + self.ball[1] = screen.height - 2 is_down = False if self.paddle.index(block[0]) > len(self.paddle) // 2: is_left = False @@ -433,7 +425,7 @@ def ball_travel(self, is_left, is_down, spin, screen): if self.ball[1] < 0: self.ball[1] = 0 - elif self.ball[1] > screen.y_height - 1: - self.ball[1] = screen.y_height - 1 + elif self.ball[1] > screen.height - 1: + self.ball[1] = screen.height - 1 return is_left, is_down diff --git a/demos/breakout_ai/main.py b/demos/breakout_ai/main.py index e6bd19e..7bc23cf 100644 --- a/demos/breakout_ai/main.py +++ b/demos/breakout_ai/main.py @@ -113,12 +113,12 @@ def run(self): is_left = True if self.ball[1] == 0: is_down = True - if self.ball[1] == screen.y_height - 2: + if self.ball[1] == screen.height - 2: if self.ball[0] in self.paddle: spin, is_left = self.get_angle(self.paddle) self.frame_rate = self.frame_rate * spin // (1 + spin // 2) is_down = False - if self.ball[1] >= screen.y_height - 1: + if self.ball[1] >= screen.height - 1: is_down = True screen.draw_pixel( @@ -127,8 +127,8 @@ def run(self): if lives == 0: gameover = True break - self.ball[0] = screen.x_width // 2 - self.ball[1] = screen.y_height // 2 + self.ball[0] = screen.width // 2 + self.ball[1] = screen.height // 2 is_left, is_down = self.ball_travel(is_left, is_down, spin, screen) predicted_landing = self.predict_ball_landing( @@ -144,13 +144,13 @@ def run(self): self.paddle[val] -= 1 screen.draw_pixel( self.paddle[0], - screen.y_height - 1, + screen.height - 1, PIXEL_ON, combine=False, ) screen.draw_pixel( self.paddle[-1] + 1, - screen.y_height - 1, + screen.height - 1, PIXEL_OFF, combine=False, ) @@ -160,13 +160,13 @@ def run(self): self.paddle[val] += 1 screen.draw_pixel( self.paddle[0] - 1, - screen.y_height - 1, + screen.height - 1, PIXEL_OFF, combine=False, ) screen.draw_pixel( self.paddle[-1], - screen.y_height - 1, + screen.height - 1, PIXEL_ON, combine=False, ) @@ -191,13 +191,13 @@ def run(self): # Update the screen pixels for the paddle movement screen.draw_pixel( self.paddle[0] - 1, - screen.y_height - 1, + screen.height - 1, PIXEL_OFF, combine=False, ) screen.draw_pixel( self.paddle[-1], - screen.y_height - 1, + screen.height - 1, PIXEL_ON, combine=False, ) @@ -218,13 +218,13 @@ def run(self): # Update the screen pixels for the paddle movement screen.draw_pixel( self.paddle[0], - screen.y_height - 1, + screen.height - 1, PIXEL_ON, combine=False, ) screen.draw_pixel( self.paddle[-1] + 1, - screen.y_height - 1, + screen.height - 1, PIXEL_OFF, combine=False, ) @@ -246,13 +246,13 @@ def run(self): # Update the screen pixels for the paddle movement screen.draw_pixel( self.paddle[0], - screen.y_height - 1, + screen.height - 1, PIXEL_ON, combine=False, ) screen.draw_pixel( self.paddle[-1] + 1, - screen.y_height - 1, + screen.height - 1, PIXEL_OFF, combine=False, ) @@ -270,13 +270,13 @@ def run(self): # Update the screen pixels for the paddle movement screen.draw_pixel( self.paddle[0] - 1, - screen.y_height - 1, + screen.height - 1, PIXEL_OFF, combine=False, ) screen.draw_pixel( self.paddle[-1], - screen.y_height - 1, + screen.height - 1, PIXEL_ON, combine=False, ) @@ -301,22 +301,22 @@ def init_screen(self, screen): self.paddle = [24] if self.level == 1: - self.line_right = screen.x_width - ARENA_START + self.line_right = screen.width - ARENA_START self.line_left = ARENA_START - 1 - self.ball = [screen.x_width // 2, screen.y_height // 2] + self.ball = [screen.width // 2, screen.height // 2] if self.level % 2 == 0: - for pix in range(screen.y_height): + for pix in range(screen.height): screen.draw_pixel(self.line_left, pix, 0x0) screen.draw_pixel(self.line_right, pix, 0x0) self.line_left = 13 - self.level - self.line_right = (screen.x_width - ARENA_START) + self.level + self.line_right = (screen.width - ARENA_START) + self.level else: self.rows = self.level + 2 - screen.draw_vline(self.line_left, 0, screen.y_height, left=False) - screen.draw_vline(self.line_right, 0, screen.y_height) + screen.draw_vline(self.line_left, 0, screen.height, left=False) + screen.draw_vline(self.line_right, 0, screen.height) for row in range(self.rows): self.bricks[row] = [] @@ -337,10 +337,10 @@ def init_screen(self, screen): self.paddle.append(self.paddle[-1] + 1) for val in range(self.line_left + 1, self.line_right): - screen.draw_pixel(val, screen.y_height - 1, PIXEL_OFF) + screen.draw_pixel(val, screen.height - 1, PIXEL_OFF) for val in self.paddle: - screen.draw_pixel(val, screen.y_height - 1, PIXEL_ON, combine=False) + screen.draw_pixel(val, screen.height - 1, PIXEL_ON, combine=False) screen.push() @@ -407,10 +407,10 @@ def ball_travel(self, is_left, is_down, spin, screen): if is_down: # A possible conflict with ball trying to jump paddle - if (screen.y_height - 1) - (self.ball[1] + spin) <= 0 and spin > 1: + if (screen.height - 1) - (self.ball[1] + spin) <= 0 and spin > 1: for block in collide_field: if block[0] in self.paddle: - self.ball[1] = screen.y_height - 2 + self.ball[1] = screen.height - 2 is_down = False if self.paddle.index(block[0]) > len(self.paddle) // 2: is_left = False @@ -439,8 +439,8 @@ def ball_travel(self, is_left, is_down, spin, screen): if self.ball[1] < 0: self.ball[1] = 0 - elif self.ball[1] > screen.y_height - 1: - self.ball[1] = screen.y_height - 1 + elif self.ball[1] > screen.height - 1: + self.ball[1] = screen.height - 1 return is_left, is_down @@ -458,9 +458,7 @@ def predict_ball_landing(self, is_left, is_down, spin, screen): ball_x = self.ball[0] ball_y = self.ball[1] - while ( - ball_y < screen.y_height - 1 - ): # Simulate until the ball reaches the bottom + while ball_y < screen.height - 1: # Simulate until the ball reaches the bottom if is_left: ball_x -= 1 else: diff --git a/demos/camera/_main.py b/demos/camera/_main.py index 1897c50..c7b6646 100644 --- a/demos/camera/_main.py +++ b/demos/camera/_main.py @@ -201,8 +201,8 @@ def run(self): logger.debug("Printing on screen") self.screen.clear() self.screen.draw_text( - (self.screen.x_width // 2) - 4, - (self.screen.y_height // 2) - 6, + (self.screen.width // 2) - 4, + (self.screen.height // 2) - 6, "NO CAMERA", ) self.screen.push() @@ -232,8 +232,8 @@ def run(self): if self.url_rets["ret"]: # Found the url self.screen.draw_text( - (self.screen.x_width // 2) - 4, - (self.screen.y_height // 2) - 6, + (self.screen.width // 2) - 4, + (self.screen.height // 2) - 6, " ", ) self.screen.push() @@ -250,8 +250,8 @@ def run(self): logger.debug("Printing on screen") self.screen.clear() self.screen.draw_text( - (self.screen.x_width // 2) - 4, - (self.screen.y_height // 2) - 6, + (self.screen.width // 2) - 4, + (self.screen.height // 2) - 6, "NO CAMERA", ) self.screen.push() diff --git a/demos/checkerboard/main.py b/demos/checkerboard/main.py index 46bf93b..6d4b57b 100644 --- a/demos/checkerboard/main.py +++ b/demos/checkerboard/main.py @@ -28,8 +28,8 @@ def run(self): """Runs the simulation loop""" # Create generator here while True: - for x in range(self.screen.x_width): - for y in range(self.screen.y_height): + for x in range(self.screen.width): + for y in range(self.screen.height): if y % 2 == 0: if x % 2: self.screen.draw_pixel(x, y, 0xF, combine=False, push=False) @@ -39,8 +39,8 @@ def run(self): self.screen.push() yield - for x in range(self.screen.x_width): - for y in range(self.screen.y_height): + for x in range(self.screen.width): + for y in range(self.screen.height): if y % 2: if x % 2: self.screen.draw_pixel(x, y, 0xF, combine=False, push=False) diff --git a/demos/circle/main.py b/demos/circle/main.py index 2c50912..240b7d9 100644 --- a/demos/circle/main.py +++ b/demos/circle/main.py @@ -26,8 +26,8 @@ def __init__(self, input_queue, output_queue, screen): def run(self): """Runs the simulation loop""" # Create generator here - width = self.screen.x_width - height = self.screen.y_height + width = self.screen.width + height = self.screen.height while True: for x in range(1, width): self.screen.draw_pixel(x - 1, 0, 0x0, push=True) diff --git a/demos/doom/main.py b/demos/doom/main.py index 6f86aec..b40a930 100644 --- a/demos/doom/main.py +++ b/demos/doom/main.py @@ -118,8 +118,8 @@ def run(self): # In case memory cannot be initialized correctly or game is not found if not self.game_installed or not self.shared_mem_init: self.screen.draw_text( - self.screen.x_width // 2 - 10, - self.screen.y_height // 2 - 4, + self.screen.width // 2 - 10, + self.screen.height // 2 - 4, "ERROR INITIALIZING DOOM", push=True, ) diff --git a/demos/flappy_pixel/main.py b/demos/flappy_pixel/main.py index b246e5d..25b80d9 100644 --- a/demos/flappy_pixel/main.py +++ b/demos/flappy_pixel/main.py @@ -89,12 +89,12 @@ def _update_pipes(self): if -2.5 < x < 45.5: for i in range(y): self.screen.draw_pixel(round(x) + 2, i, 0x0) - for i in range(y + 11, self.screen.y_height): + for i in range(y + 11, self.screen.height): self.screen.draw_pixel(round(x) + 2, i, 0x0) if -5.5 < x < 42.5: for i in range(y): self.screen.draw_pixel(round(x) + 4, i, 0x0) - for i in range(y + 11, self.screen.y_height): + for i in range(y + 11, self.screen.height): self.screen.draw_pixel(round(x) + 4, i, 0x0) # self.screen.draw_pixel(round(x)+2,y-1,0x0) # self.screen.draw_pixel(round(x)+2,y+11,0x0) @@ -106,12 +106,12 @@ def _update_pipes(self): if 0 <= x < 47.5: # top pipe self.screen.draw_hline( - round(x), y, 5 if x < 42.5 else self.screen.x_width - round(x) + round(x), y, 5 if x < 42.5 else self.screen.width - round(x) ) self.screen.draw_hline( round(x), y, - 5 if x < 42.5 else self.screen.x_width - round(x), + 5 if x < 42.5 else self.screen.width - round(x), False, ) self.screen.draw_pixel(round(x), y, 0x2) @@ -124,12 +124,12 @@ def _update_pipes(self): # bottom pipe self.screen.draw_hline( - round(x), y + 10, 5 if x < 42.5 else self.screen.x_width - round(x) + round(x), y + 10, 5 if x < 42.5 else self.screen.width - round(x) ) self.screen.draw_hline( round(x), y + 10, - 5 if x < 42.5 else self.screen.x_width - round(x), + 5 if x < 42.5 else self.screen.width - round(x), False, ) self.screen.draw_pixel(round(x), y + 10, 0x2) @@ -137,11 +137,11 @@ def _update_pipes(self): self.screen.draw_pixel(round(x) + 4, y + 10, 0x8) if x < 46.5: self.screen.draw_vline( - round(x) + 1, y + 11, self.screen.y_height - (y + 11) + round(x) + 1, y + 11, self.screen.height - (y + 11) ) if x < 43.5: self.screen.draw_vline( - round(x) + 3, y + 11, self.screen.y_height - (y + 11), False + round(x) + 3, y + 11, self.screen.height - (y + 11), False ) if x < 0: # left side of the screen now @@ -159,14 +159,14 @@ def _update_pipes(self): self.screen.draw_vline(round(x) + 1, 0, y) # bottom self.screen.draw_vline( - round(x) + 1, y + 11, self.screen.y_height - (y + 11) + round(x) + 1, y + 11, self.screen.height - (y + 11) ) if x > -3.5: # top self.screen.draw_vline(round(x) + 3, 0, y) # bottom self.screen.draw_vline( - round(x) + 3, y + 11, self.screen.y_height - (y + 11), False + round(x) + 3, y + 11, self.screen.height - (y + 11), False ) def run(self): diff --git a/demos/game_of_life/main.py b/demos/game_of_life/main.py index c9f998e..4ba4caa 100644 --- a/demos/game_of_life/main.py +++ b/demos/game_of_life/main.py @@ -51,8 +51,8 @@ def _display_board(self, board): board (list): The board to display """ - for x in range(self.screen.x_width): - for y in range(self.screen.y_height): + for x in range(self.screen.width): + for y in range(self.screen.height): self.screen.draw_pixel(x, y, 0xF if board[y][x] else 0x0) self.screen.push() @@ -128,7 +128,7 @@ def run(self): # Set up the initial state self.screen.clear() old_boards.clear() - board = self._create_board(self.screen.x_width, self.screen.y_height) + board = self._create_board(self.screen.width, self.screen.height) # Display the board self._display_board(board) diff --git a/demos/letters/main.py b/demos/letters/main.py index 7bc2afd..bd48e6a 100644 --- a/demos/letters/main.py +++ b/demos/letters/main.py @@ -32,14 +32,14 @@ def run(self): while True: for _ in range(4): self.screen.draw_text( - random.randint(0, self.screen.x_width - 1), - random.randint(0, self.screen.y_height - 2), + random.randint(0, self.screen.width - 1), + random.randint(0, self.screen.height - 2), chr(random.randint(33, 126)), ) for _ in range(4): self.screen.draw_text( - random.randint(0, self.screen.x_width - 1), - random.randint(0, self.screen.y_height - 2), + random.randint(0, self.screen.width - 1), + random.randint(0, self.screen.height - 2), " ", ) self.screen.push() diff --git a/demos/menu/main.py b/demos/menu/main.py index 90eb5c6..286aade 100644 --- a/demos/menu/main.py +++ b/demos/menu/main.py @@ -55,7 +55,7 @@ def _draw_menu(self): if i >= self.max_demos_per_column: self.screen.draw_text( - self.screen.x_width // 2, + self.screen.width // 2, 4 + ((i - self.max_demos_per_column) * 2), f"{i + 1:2}. {demo.upper()}", ) @@ -63,7 +63,7 @@ def _draw_menu(self): def _update_menu(self, selected, show_text=True): if selected >= self.max_demos_per_column: selected_v_offset = selected - self.max_demos_per_column - selected_h_offset = self.screen.x_width // 2 + selected_h_offset = self.screen.width // 2 else: selected_v_offset = selected selected_h_offset = 0 @@ -85,10 +85,8 @@ def run(self): count = 0 # Set up initial screen - self.screen.draw_text( - (self.screen.x_width - len(self.title)) // 2, 0, self.title - ) - self.screen.draw_hline(0, 2, self.screen.x_width) + self.screen.draw_text((self.screen.width - len(self.title)) // 2, 0, self.title) + self.screen.draw_hline(0, 2, self.screen.width) self._draw_menu() self._update_menu(old_selected, selected) self.screen.push() diff --git a/demos/minesweeper/main.py b/demos/minesweeper/main.py index 7863f8a..4a78a7f 100644 --- a/demos/minesweeper/main.py +++ b/demos/minesweeper/main.py @@ -54,17 +54,17 @@ def run(self): """Runs the game loop""" # Waits for user ready self.screen.draw_text( - (self.screen.x_width // 2) - 5, - (self.screen.y_height // 2) - 8, + (self.screen.width // 2) - 5, + (self.screen.height // 2) - 8, "MINESWEEPER", ) self.screen.draw_text( - (self.screen.x_width // 2) - 5, - (self.screen.y_height // 2) - 4, + (self.screen.width // 2) - 5, + (self.screen.height // 2) - 4, "PRESS START", ) self.screen.draw_text( - (self.screen.x_width // 2) - 4, (self.screen.y_height // 2) - 2, "TO BEGIN" + (self.screen.width // 2) - 4, (self.screen.height // 2) - 2, "TO BEGIN" ) self.screen.push() @@ -79,17 +79,17 @@ def run(self): # Erase startup text and initialize screen self.screen.draw_text( - (self.screen.x_width // 2) - 5, - (self.screen.y_height // 2) - 8, + (self.screen.width // 2) - 5, + (self.screen.height // 2) - 8, " ", ) self.screen.draw_text( - (self.screen.x_width // 2) - 5, - (self.screen.y_height // 2) - 4, + (self.screen.width // 2) - 5, + (self.screen.height // 2) - 4, " ", ) self.screen.draw_text( - (self.screen.x_width // 2) - 4, (self.screen.y_height // 2) - 2, " " + (self.screen.width // 2) - 4, (self.screen.height // 2) - 2, " " ) self.screen.push() self.init_screen() @@ -564,23 +564,23 @@ def game_over(self, win=False): self.screen.clear() self.screen.draw_text( - (self.screen.x_width // 2) - 4, - (self.screen.y_height // 2) - 8, + (self.screen.width // 2) - 4, + (self.screen.height // 2) - 8, "GAME OVER", ) self.screen.draw_text( - (self.screen.x_width // 2) - 4, - (self.screen.y_height // 2) - 6, + (self.screen.width // 2) - 4, + (self.screen.height // 2) - 6, "---------", ) self.screen.draw_text( - (self.screen.x_width // 2) - 4, - (self.screen.y_height // 2) - 4, + (self.screen.width // 2) - 4, + (self.screen.height // 2) - 4, "SCORE " + str(diff).split(".")[0], ) self.screen.draw_text( - (self.screen.x_width // 2) - 4, - (self.screen.y_height // 2) - 2, + (self.screen.width // 2) - 4, + (self.screen.height // 2) - 2, "HISCORE " + str(hscore).split(".")[0], ) self.screen.push() @@ -599,8 +599,8 @@ def game_over(self, win=False): self.screen.clear() self.screen.draw_text( - (self.screen.x_width // 2) - 4, - (self.screen.y_height // 2) - 8, + (self.screen.width // 2) - 4, + (self.screen.height // 2) - 8, "GAME OVER", push=True, ) diff --git a/demos/netlab_flag/main.py b/demos/netlab_flag/main.py index 562d1e1..7dc94b8 100644 --- a/demos/netlab_flag/main.py +++ b/demos/netlab_flag/main.py @@ -29,125 +29,125 @@ def run(self): """Main loop of the demo/game""" # Create generator here # draw the logo in the center of the screen - self.screen.draw_pixel(23, 2 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(24, 2 + (self.screen.y_height // 4), 0xF, combine=False) + self.screen.draw_pixel(23, 2 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(24, 2 + (self.screen.height // 4), 0xF, combine=False) - self.screen.draw_pixel(23, 22 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(24, 22 + (self.screen.y_height // 4), 0xF, combine=False) + self.screen.draw_pixel(23, 22 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(24, 22 + (self.screen.height // 4), 0xF, combine=False) - self.screen.draw_pixel(21, 3 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(19, 4 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(17, 5 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(15, 6 + (self.screen.y_height // 4), 0xF, combine=False) + self.screen.draw_pixel(21, 3 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(19, 4 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(17, 5 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(15, 6 + (self.screen.height // 4), 0xF, combine=False) - self.screen.draw_pixel(26, 3 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(28, 4 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(30, 5 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(32, 6 + (self.screen.y_height // 4), 0xF, combine=False) + self.screen.draw_pixel(26, 3 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(28, 4 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(30, 5 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(32, 6 + (self.screen.height // 4), 0xF, combine=False) - self.screen.draw_pixel(21, 21 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(19, 20 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(17, 19 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(15, 18 + (self.screen.y_height // 4), 0xF, combine=False) + self.screen.draw_pixel(21, 21 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(19, 20 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(17, 19 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(15, 18 + (self.screen.height // 4), 0xF, combine=False) - self.screen.draw_pixel(26, 21 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(28, 20 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(30, 19 + (self.screen.y_height // 4), 0xF, combine=False) - self.screen.draw_pixel(32, 18 + (self.screen.y_height // 4), 0xF, combine=False) + self.screen.draw_pixel(26, 21 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(28, 20 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(30, 19 + (self.screen.height // 4), 0xF, combine=False) + self.screen.draw_pixel(32, 18 + (self.screen.height // 4), 0xF, combine=False) for line in range(11): self.screen.draw_pixel( - 15, 6 + line + (self.screen.y_height // 4), 0xF, combine=True + 15, 6 + line + (self.screen.height // 4), 0xF, combine=True ) self.screen.draw_pixel( - 32, 6 + line + (self.screen.y_height // 4), 0xF, combine=True + 32, 6 + line + (self.screen.height // 4), 0xF, combine=True ) # Text for n in range(5): self.screen.draw_pixel( - 17, 7 + n + (self.screen.y_height // 4), 0xF, combine=True + 17, 7 + n + (self.screen.height // 4), 0xF, combine=True ) self.screen.draw_pixel( - 20, 7 + n + (self.screen.y_height // 4), 0xF, combine=True + 20, 7 + n + (self.screen.height // 4), 0xF, combine=True ) - self.screen.draw_pixel(18, 8 + (self.screen.y_height // 4), 0xF, combine=True) - self.screen.draw_pixel(19, 9 + (self.screen.y_height // 4), 0xF, combine=True) + self.screen.draw_pixel(18, 8 + (self.screen.height // 4), 0xF, combine=True) + self.screen.draw_pixel(19, 9 + (self.screen.height // 4), 0xF, combine=True) for e in range(5): self.screen.draw_pixel( - 22, 7 + e + (self.screen.y_height // 4), 0xF, combine=True + 22, 7 + e + (self.screen.height // 4), 0xF, combine=True ) for ee in range(3): self.screen.draw_pixel( - 23 + ee, 7 + (self.screen.y_height // 4), 0xF, combine=True + 23 + ee, 7 + (self.screen.height // 4), 0xF, combine=True ) self.screen.draw_pixel( - 23 + ee, 9 + (self.screen.y_height // 4), 0xF, combine=True + 23 + ee, 9 + (self.screen.height // 4), 0xF, combine=True ) self.screen.draw_pixel( - 23 + ee, 11 + (self.screen.y_height // 4), 0xF, combine=True + 23 + ee, 11 + (self.screen.height // 4), 0xF, combine=True ) for t in range(4): self.screen.draw_pixel( - 27 + t, 7 + (self.screen.y_height // 4), 0xF, combine=True + 27 + t, 7 + (self.screen.height // 4), 0xF, combine=True ) self.screen.draw_pixel( - 28, 8 + t + (self.screen.y_height // 4), 0xF, combine=True + 28, 8 + t + (self.screen.height // 4), 0xF, combine=True ) for l in range(5): self.screen.draw_pixel( - 17, 13 + l + (self.screen.y_height // 4), 0xF, combine=True + 17, 13 + l + (self.screen.height // 4), 0xF, combine=True ) for ll in range(3): self.screen.draw_pixel( - 18 + ll, 17 + (self.screen.y_height // 4), 0xF, combine=True + 18 + ll, 17 + (self.screen.height // 4), 0xF, combine=True ) for a in range(5): self.screen.draw_pixel( - 22, 13 + a + (self.screen.y_height // 4), 0xF, combine=True + 22, 13 + a + (self.screen.height // 4), 0xF, combine=True ) self.screen.draw_pixel( - 25, 13 + a + (self.screen.y_height // 4), 0xF, combine=True + 25, 13 + a + (self.screen.height // 4), 0xF, combine=True ) for aa in range(2): self.screen.draw_pixel( - 23 + aa, 13 + (self.screen.y_height // 4), 0xF, combine=True + 23 + aa, 13 + (self.screen.height // 4), 0xF, combine=True ) self.screen.draw_pixel( - 23 + aa, 15 + (self.screen.y_height // 4), 0xF, combine=True + 23 + aa, 15 + (self.screen.height // 4), 0xF, combine=True ) for b in range(5): self.screen.draw_pixel( - 27, 13 + b + (self.screen.y_height // 4), 0xF, combine=True + 27, 13 + b + (self.screen.height // 4), 0xF, combine=True ) for bb in range(3): self.screen.draw_pixel( - 28 + bb, 15 + (self.screen.y_height // 4), 0xF, combine=True + 28 + bb, 15 + (self.screen.height // 4), 0xF, combine=True ) self.screen.draw_pixel( - 28 + bb, 17 + (self.screen.y_height // 4), 0xF, combine=True + 28 + bb, 17 + (self.screen.height // 4), 0xF, combine=True ) for bbb in range(2): self.screen.draw_pixel( - 28 + bbb, 13 + (self.screen.y_height // 4), 0xF, combine=True + 28 + bbb, 13 + (self.screen.height // 4), 0xF, combine=True ) - self.screen.draw_pixel(30, 16 + (self.screen.y_height // 4), 0xF) - self.screen.draw_pixel(30, 14 + (self.screen.y_height // 4), 0xF) + self.screen.draw_pixel(30, 16 + (self.screen.height // 4), 0xF) + self.screen.draw_pixel(30, 14 + (self.screen.height // 4), 0xF) while True: for x in range(13): - for y in range(self.screen.y_height): + for y in range(self.screen.height): if y % 2 == 0: if x % 3: self.screen.draw_pixel(x, y, 0xF, combine=False, push=False) @@ -155,8 +155,8 @@ def run(self): if x % 3 == 0: self.screen.draw_pixel(x, y, 0xF, combine=False, push=False) - for x in range(35, self.screen.x_width): - for y in range(self.screen.y_height): + for x in range(35, self.screen.width): + for y in range(self.screen.height): if y % 2 == 0: if x % 3: self.screen.draw_pixel(x, y, 0xF, combine=False, push=False) @@ -166,7 +166,7 @@ def run(self): self.screen.push() yield for x in range(13): - for y in range(self.screen.y_height): + for y in range(self.screen.height): if y % 2: if x % 3: self.screen.draw_pixel(x, y, 0xF, combine=False, push=False) @@ -174,8 +174,8 @@ def run(self): if x % 3 == 0: self.screen.draw_pixel(x, y, 0xF, combine=False, push=False) - for x in range(35, self.screen.x_width): - for y in range(self.screen.y_height): + for x in range(35, self.screen.width): + for y in range(self.screen.height): if y % 2: if x % 3: self.screen.draw_pixel(x, y, 0xF, combine=False, push=False) diff --git a/demos/snake/main.py b/demos/snake/main.py index 43303b1..816de74 100644 --- a/demos/snake/main.py +++ b/demos/snake/main.py @@ -43,13 +43,13 @@ def _draw_set_up(self): """Draw the setup on the game screen""" logger.debug("Game reset and starting again") # draw banner at the top - self.screen.draw_hline(0, 2, self.screen.x_width, push=True) - self.screen.draw_hline(0, 3, self.screen.x_width, push=True) + self.screen.draw_hline(0, 2, self.screen.width, push=True) + self.screen.draw_hline(0, 3, self.screen.width, push=True) self.screen.draw_text(0, 0, "SCORE 000") self.screen.draw_text( - self.screen.x_width - 3 - 8, 0, "H-SCORE " + str(self.h_score).zfill(3) + self.screen.width - 3 - 8, 0, "H-SCORE " + str(self.h_score).zfill(3) ) - self.screen.draw_text(self.screen.x_width // 2 - 2, 0, "SNAKE", push=True) + self.screen.draw_text(self.screen.width // 2 - 2, 0, "SNAKE", push=True) self.output_queue.put("SCORE ") self.output_queue.put("LIVES ") @@ -57,7 +57,7 @@ def run(self): """Main game loop""" game_over = False self.screen.clear() - current_location = (self.screen.x_width // 2, self.screen.y_height // 2) + current_location = (self.screen.width // 2, self.screen.height // 2) snek_list = [ (current_location[0] - 2, current_location[1]), (current_location[0] - 1, current_location[1]), @@ -70,13 +70,13 @@ def run(self): def get_new_food_location(): food_location = ( - round(random.randrange(0, self.screen.x_width - 1)), - round(random.randrange(4, self.screen.y_height - 1)), + round(random.randrange(0, self.screen.width - 1)), + round(random.randrange(4, self.screen.height - 1)), ) while food_location in snek_list: food_location = ( - round(random.randrange(0, self.screen.x_width - 1)), - round(random.randrange(4, self.screen.y_height - 1)), + round(random.randrange(0, self.screen.width - 1)), + round(random.randrange(4, self.screen.height - 1)), ) # print(food_location) return food_location @@ -170,9 +170,9 @@ def get_new_food_location(): # check to make sure snek isn't in the weeds if ( - current_location[0] >= self.screen.x_width + current_location[0] >= self.screen.width or current_location[0] < 0 - or current_location[1] >= self.screen.y_height + or current_location[1] >= self.screen.height or current_location[1] < 4 or current_location in snek_list[:-1] ): @@ -199,26 +199,26 @@ def get_new_food_location(): current_food_location[0], current_food_location[1], 0 ) self.screen.draw_text( - self.screen.x_width // 2 - 4, self.screen.y_height // 2 - 2, "GAME OVER" + self.screen.width // 2 - 4, self.screen.height // 2 - 2, "GAME OVER" ) # update the highscore if highscore was acheived if self.snek_length > self.h_score: self.screen.draw_text( - self.screen.x_width // 2 - 6, - self.screen.y_height // 2, + self.screen.width // 2 - 6, + self.screen.height // 2, "H-SCORE " + str(self.snek_length - 3).zfill(3), ) self.h_score = self.snek_length with open("demos/snake/high_score.txt", "w", encoding="utf8") as scores: scores.write(str(self.h_score)) self.screen.draw_text( - self.screen.x_width - 3, 0, str(self.snek_length - 3).zfill(3) + self.screen.width - 3, 0, str(self.snek_length - 3).zfill(3) ) else: self.screen.draw_text( - self.screen.x_width // 2 - 6, - self.screen.y_height // 2, + self.screen.width // 2 - 6, + self.screen.height // 2, "SCORE " + str(self.snek_length - 3).zfill(3), ) self.screen.push() @@ -233,7 +233,7 @@ def get_new_food_location(): yield # reset the state and start the game again - current_location = (self.screen.x_width // 2, self.screen.y_height // 2) + current_location = (self.screen.width // 2, self.screen.height // 2) snek_list = [ (current_location[0] - 2, current_location[1]), (current_location[0] - 1, current_location[1]), diff --git a/demos/snake/main_old.py b/demos/snake/main_old.py index 6da070c..fdceb53 100644 --- a/demos/snake/main_old.py +++ b/demos/snake/main_old.py @@ -98,7 +98,7 @@ def snek_game(display, queue, mqtt_client, fps=10, ai=False): game_over = False display.clear() tick = frameRate(fps) - current_location = (display.x_width // 2, display.y_height // 2) + current_location = (display.width // 2, display.height // 2) snek_list = [current_location] snek_length = 1 h_score = 0 @@ -114,13 +114,13 @@ def get_new_food_location(): """ food_location = ( - round(random.randrange(0, display.x_width - 1)), - round(random.randrange(4, display.y_height - 1)), + round(random.randrange(0, display.width - 1)), + round(random.randrange(4, display.height - 1)), ) while food_location in snek_list: food_location = ( - round(random.randrange(0, display.x_width - 1)), - round(random.randrange(4, display.y_height - 1)), + round(random.randrange(0, display.width - 1)), + round(random.randrange(4, display.height - 1)), ) # print(food_location) return food_location @@ -131,10 +131,10 @@ def get_new_food_location(): if ai: logger.info("Run snake AI") # game_state = generate_game_state( - # display.x_width, display.y_height, current_location, current_food_location + # display.width, display.height, current_location, current_food_location # ) game_state = generate_game_state2( - display.x_width, display.y_height, current_location, current_food_location + display.width, display.height, current_location, current_food_location ) direction = "ai" snek_path = snek_ai.run_Search2( @@ -154,11 +154,11 @@ def get_new_food_location(): ) # draw banner at the top - display.draw_hline(0, 2, display.x_width, push=True) - display.draw_hline(0, 3, display.x_width, push=True) + display.draw_hline(0, 2, display.width, push=True) + display.draw_hline(0, 3, display.width, push=True) display.draw_text(0, 0, "SCORE 000") - display.draw_text(display.x_width - 3 - 8, 0, "H-SCORE " + str(h_score).zfill(3)) - display.draw_text(display.x_width // 2 - 2, 0, "SNAKE", push=True) + display.draw_text(display.width - 3 - 8, 0, "H-SCORE " + str(h_score).zfill(3)) + display.draw_text(display.width // 2 - 2, 0, "SNAKE", push=True) while True: # if not ai: @@ -299,9 +299,9 @@ def get_new_food_location(): # print(direction, current_location) # check to make sure snek isn't in the weeds if ( - current_location[0] >= display.x_width + current_location[0] >= display.width or current_location[0] < 0 - or current_location[1] >= display.y_height + or current_location[1] >= display.height or current_location[1] < 4 or current_location in snek_list[:-1] ): @@ -342,23 +342,21 @@ def get_new_food_location(): for i in snek_list[:-1]: display.draw_pixel(i[0], i[1], 0) display.draw_pixel(current_food_location[0], current_food_location[1], 0) - display.draw_text( - display.x_width // 2 - 4, display.y_height // 2 - 2, "GAME OVER" - ) + display.draw_text(display.width // 2 - 4, display.height // 2 - 2, "GAME OVER") if snek_length > h_score: display.draw_text( - display.x_width // 2 - 6, - display.y_height // 2, + display.width // 2 - 6, + display.height // 2, "H-SCORE " + str(snek_length).zfill(3), ) h_score = snek_length with open("games/snake/ai_high_score.txt", "w") as scores: scores.write(str(h_score)) - display.draw_text(display.x_width - 3, 0, str(snek_length).zfill(3)) + display.draw_text(display.width - 3, 0, str(snek_length).zfill(3)) else: display.draw_text( - display.x_width // 2 - 6, - display.y_height // 2, + display.width // 2 - 6, + display.height // 2, "SCORE " + str(snek_length).zfill(3), ) display.push() @@ -366,16 +364,16 @@ def get_new_food_location(): # return time.sleep(5) print("\n\n\nNEW GAME") - start_sweep_x = display.x_width // 2 - 1 + start_sweep_x = display.width // 2 - 1 for i in range(start_sweep_x + 1): display.draw_shape_line( - start_sweep_x - i, 4, start_sweep_x - i, display.y_height - 1, 15 + start_sweep_x - i, 4, start_sweep_x - i, display.height - 1, 15 ) display.draw_shape_line( start_sweep_x + i + 1, 4, start_sweep_x + i + 1, - display.y_height - 1, + display.height - 1, 15, ) if i > 0: @@ -383,41 +381,41 @@ def get_new_food_location(): start_sweep_x - i + 1, 4, start_sweep_x - i + 1, - display.y_height - 1, + display.height - 1, 0, ) display.draw_shape_line( start_sweep_x + i, 4, start_sweep_x + i, - display.y_height - 1, + display.height - 1, 0, ) display.push() next(tick) - display.draw_shape_line(0, 4, 0, display.y_height - 1, 0) + display.draw_shape_line(0, 4, 0, display.height - 1, 0) display.draw_shape_line( - display.x_width - 1, + display.width - 1, 4, - display.x_width - 1, - display.y_height - 1, + display.width - 1, + display.height - 1, 0, ) game_over = False snek_length = 1 current_food_location = get_new_food_location() - current_location = (display.x_width // 2, display.y_height // 2) + current_location = (display.width // 2, display.height // 2) snek_list = [current_location] if ai: # game_state = generate_game_state( - # display.x_width, - # display.y_height, + # display.width, + # display.height, # current_location, # current_food_location, # ) game_state = generate_game_state2( - display.x_width, - display.y_height, + display.width, + display.height, current_location, current_food_location, ) diff --git a/demos/snake_ai/main.py b/demos/snake_ai/main.py index 36b7d6b..a28417d 100644 --- a/demos/snake_ai/main.py +++ b/demos/snake_ai/main.py @@ -46,13 +46,13 @@ def _draw_set_up(self): """Draw the setup on the game screen""" logger.debug("Game reset and starting again") # draw banner at the top - self.screen.draw_hline(0, 2, self.screen.x_width, push=True) - self.screen.draw_hline(0, 3, self.screen.x_width, push=True) + self.screen.draw_hline(0, 2, self.screen.width, push=True) + self.screen.draw_hline(0, 3, self.screen.width, push=True) self.screen.draw_text(0, 0, "SCORE 000") self.screen.draw_text( - self.screen.x_width - 3 - 8, 0, "H-SCORE " + str(self.h_score).zfill(3) + self.screen.width - 3 - 8, 0, "H-SCORE " + str(self.h_score).zfill(3) ) - self.screen.draw_text(self.screen.x_width // 2 - 2, 0, "SNAKE", push=True) + self.screen.draw_text(self.screen.width // 2 - 2, 0, "SNAKE", push=True) self.output_queue.put("SCORE ") self.output_queue.put("LIVES ") @@ -60,7 +60,7 @@ def run(self): """Main game loop""" game_over = False self.screen.clear() - current_location = (self.screen.x_width // 2, self.screen.y_height // 2) + current_location = (self.screen.width // 2, self.screen.height // 2) snek_list = [ (current_location[0] - 2, current_location[1]), (current_location[0] - 1, current_location[1]), @@ -73,13 +73,13 @@ def run(self): def get_new_food_location(): food_location = ( - round(random.randrange(0, self.screen.x_width - 1)), - round(random.randrange(4, self.screen.y_height - 1)), + round(random.randrange(0, self.screen.width - 1)), + round(random.randrange(4, self.screen.height - 1)), ) while food_location in snek_list: food_location = ( - round(random.randrange(0, self.screen.x_width - 1)), - round(random.randrange(4, self.screen.y_height - 1)), + round(random.randrange(0, self.screen.width - 1)), + round(random.randrange(4, self.screen.height - 1)), ) # print(food_location) return food_location @@ -94,8 +94,8 @@ def generate_game_state(width, height, snake, food_loc): current_food_location = get_new_food_location() game_state = generate_game_state( - self.screen.x_width, - self.screen.y_height, + self.screen.width, + self.screen.height, snek_list, current_food_location, ) @@ -185,9 +185,9 @@ def generate_game_state(width, height, snake, food_loc): # check to make sure snek isn't in the weeds if ( - current_location[0] >= self.screen.x_width + current_location[0] >= self.screen.width or current_location[0] < 0 - or current_location[1] >= self.screen.y_height + or current_location[1] >= self.screen.height or current_location[1] < 4 or current_location in snek_list[:-1] ): @@ -213,14 +213,14 @@ def generate_game_state(width, height, snake, food_loc): current_food_location[0], current_food_location[1], 0 ) self.screen.draw_text( - self.screen.x_width // 2 - 4, self.screen.y_height // 2 - 2, "GAME OVER" + self.screen.width // 2 - 4, self.screen.height // 2 - 2, "GAME OVER" ) # update the highscore if highscore was acheived if self.snek_length > self.h_score: self.screen.draw_text( - self.screen.x_width // 2 - 6, - self.screen.y_height // 2, + self.screen.width // 2 - 6, + self.screen.height // 2, "H-SCORE " + str(self.snek_length - 3).zfill(3), ) self.h_score = self.snek_length @@ -229,12 +229,12 @@ def generate_game_state(width, height, snake, food_loc): ) as scores: scores.write(str(self.h_score)) self.screen.draw_text( - self.screen.x_width - 3, 0, str(self.snek_length - 3).zfill(3) + self.screen.width - 3, 0, str(self.snek_length - 3).zfill(3) ) else: self.screen.draw_text( - self.screen.x_width // 2 - 6, - self.screen.y_height // 2, + self.screen.width // 2 - 6, + self.screen.height // 2, "SCORE " + str(self.snek_length - 3).zfill(3), ) self.screen.push() @@ -252,7 +252,7 @@ def generate_game_state(width, height, snake, food_loc): yield # reset the state and start the game again - current_location = (self.screen.x_width // 2, self.screen.y_height // 2) + current_location = (self.screen.width // 2, self.screen.height // 2) snek_list = [ (current_location[0] - 2, current_location[1]), (current_location[0] - 1, current_location[1]), @@ -262,8 +262,8 @@ def generate_game_state(width, height, snake, food_loc): current_food_location = get_new_food_location() game_state = generate_game_state( - self.screen.x_width, - self.screen.y_height, + self.screen.width, + self.screen.height, snek_list, current_food_location, ) diff --git a/demos/snake_ai/main_old.py b/demos/snake_ai/main_old.py index 33eb026..869cf0a 100644 --- a/demos/snake_ai/main_old.py +++ b/demos/snake_ai/main_old.py @@ -98,7 +98,7 @@ def snek_game(display, queue, mqtt_client, fps=10, ai=False): game_over = False display.clear() tick = frameRate(fps) - current_location = (display.x_width // 2, display.y_height // 2) + current_location = (display.width // 2, display.height // 2) snek_list = [current_location] snek_length = 1 h_score = 0 @@ -114,13 +114,13 @@ def get_new_food_location(): """ food_location = ( - round(random.randrange(0, display.x_width - 1)), - round(random.randrange(4, display.y_height - 1)), + round(random.randrange(0, display.width - 1)), + round(random.randrange(4, display.height - 1)), ) while food_location in snek_list: food_location = ( - round(random.randrange(0, display.x_width - 1)), - round(random.randrange(4, display.y_height - 1)), + round(random.randrange(0, display.width - 1)), + round(random.randrange(4, display.height - 1)), ) # print(food_location) return food_location @@ -131,10 +131,10 @@ def get_new_food_location(): if ai: logger.info("Run snake AI") # game_state = generate_game_state( - # display.x_width, display.y_height, current_location, current_food_location + # display.width, display.height, current_location, current_food_location # ) game_state = generate_game_state2( - display.x_width, display.y_height, current_location, current_food_location + display.width, display.height, current_location, current_food_location ) direction = "ai" snek_path = snek_ai.run_Search2( @@ -154,11 +154,11 @@ def get_new_food_location(): ) # draw banner at the top - display.draw_hline(0, 2, display.x_width, push=True) - display.draw_hline(0, 3, display.x_width, push=True) + display.draw_hline(0, 2, display.width, push=True) + display.draw_hline(0, 3, display.width, push=True) display.draw_text(0, 0, "SCORE 000") - display.draw_text(display.x_width - 3 - 8, 0, "H-SCORE " + str(h_score).zfill(3)) - display.draw_text(display.x_width // 2 - 2, 0, "SNAKE", push=True) + display.draw_text(display.width - 3 - 8, 0, "H-SCORE " + str(h_score).zfill(3)) + display.draw_text(display.width // 2 - 2, 0, "SNAKE", push=True) while True: # if not ai: @@ -299,9 +299,9 @@ def get_new_food_location(): # print(direction, current_location) # check to make sure snek isn't in the weeds if ( - current_location[0] >= display.x_width + current_location[0] >= display.width or current_location[0] < 0 - or current_location[1] >= display.y_height + or current_location[1] >= display.height or current_location[1] < 4 or current_location in snek_list[:-1] ): @@ -342,23 +342,21 @@ def get_new_food_location(): for i in snek_list[:-1]: display.draw_pixel(i[0], i[1], 0) display.draw_pixel(current_food_location[0], current_food_location[1], 0) - display.draw_text( - display.x_width // 2 - 4, display.y_height // 2 - 2, "GAME OVER" - ) + display.draw_text(display.width // 2 - 4, display.height // 2 - 2, "GAME OVER") if snek_length > h_score: display.draw_text( - display.x_width // 2 - 6, - display.y_height // 2, + display.width // 2 - 6, + display.height // 2, "H-SCORE " + str(snek_length).zfill(3), ) h_score = snek_length with open("games/snake/ai_high_score.txt", "w") as scores: scores.write(str(h_score)) - display.draw_text(display.x_width - 3, 0, str(snek_length).zfill(3)) + display.draw_text(display.width - 3, 0, str(snek_length).zfill(3)) else: display.draw_text( - display.x_width // 2 - 6, - display.y_height // 2, + display.width // 2 - 6, + display.height // 2, "SCORE " + str(snek_length).zfill(3), ) display.push() @@ -366,16 +364,16 @@ def get_new_food_location(): # return time.sleep(5) print("\n\n\nNEW GAME") - start_sweep_x = display.x_width // 2 - 1 + start_sweep_x = display.width // 2 - 1 for i in range(start_sweep_x + 1): display.draw_shape_line( - start_sweep_x - i, 4, start_sweep_x - i, display.y_height - 1, 15 + start_sweep_x - i, 4, start_sweep_x - i, display.height - 1, 15 ) display.draw_shape_line( start_sweep_x + i + 1, 4, start_sweep_x + i + 1, - display.y_height - 1, + display.height - 1, 15, ) if i > 0: @@ -383,41 +381,41 @@ def get_new_food_location(): start_sweep_x - i + 1, 4, start_sweep_x - i + 1, - display.y_height - 1, + display.height - 1, 0, ) display.draw_shape_line( start_sweep_x + i, 4, start_sweep_x + i, - display.y_height - 1, + display.height - 1, 0, ) display.push() next(tick) - display.draw_shape_line(0, 4, 0, display.y_height - 1, 0) + display.draw_shape_line(0, 4, 0, display.height - 1, 0) display.draw_shape_line( - display.x_width - 1, + display.width - 1, 4, - display.x_width - 1, - display.y_height - 1, + display.width - 1, + display.height - 1, 0, ) game_over = False snek_length = 1 current_food_location = get_new_food_location() - current_location = (display.x_width // 2, display.y_height // 2) + current_location = (display.width // 2, display.height // 2) snek_list = [current_location] if ai: # game_state = generate_game_state( - # display.x_width, - # display.y_height, + # display.width, + # display.height, # current_location, # current_food_location, # ) game_state = generate_game_state2( - display.x_width, - display.y_height, + display.width, + display.height, current_location, current_food_location, ) diff --git a/demos/sound_visualizer/main.py b/demos/sound_visualizer/main.py index dc53519..0e302af 100644 --- a/demos/sound_visualizer/main.py +++ b/demos/sound_visualizer/main.py @@ -15,9 +15,9 @@ def sound_visualizer(display, queue, sound_frames, fps): fps (int): Frames per second to display """ tick = utils.frameRate(fps) - bottom = display.y_height - 1 + bottom = display.height - 1 # Display first frame - for x in range(display.x_width): + for x in range(display.width): display.draw_shape_line(x, bottom, x, bottom - sound_frames[0][x], 15) display.push() next(tick) @@ -30,7 +30,7 @@ def sound_visualizer(display, queue, sound_frames, fps): display.clear() return - for x in range(display.x_width): + for x in range(display.width): if sound_frames[frame_num][x] > sound_frames[frame_num - 1][x]: display.draw_shape_line( x, @@ -113,7 +113,7 @@ def stop(self): # display, # queue, # [ -# [random.randint(0, display.y_height - 1) for x in range(display.x_width)] +# [random.randint(0, display.height - 1) for x in range(display.width)] # for frames in range(1000) # ], # 10, diff --git a/demos/spiral/main.py b/demos/spiral/main.py index 3545a67..ce92197 100644 --- a/demos/spiral/main.py +++ b/demos/spiral/main.py @@ -28,8 +28,8 @@ def __init__(self, input_queue, output_queue, screen): def run(self): """Main loop for the demo""" - width = self.screen.x_width - height = self.screen.y_height + width = self.screen.width + height = self.screen.height across = width down = height x_in = 0 diff --git a/demos/sweep/main.py b/demos/sweep/main.py index 4d19dca..7d74319 100644 --- a/demos/sweep/main.py +++ b/demos/sweep/main.py @@ -27,11 +27,11 @@ def run(self): """Run the demo""" # Create generator here while True: - for column in range(0, self.screen.x_width): + for column in range(0, self.screen.width): self.draw_vline_loc(column, 0xFF) yield - for column in range(self.screen.x_width - 1, -1, -1): + for column in range(self.screen.width - 1, -1, -1): self.draw_vline_loc(column, 0x0) yield @@ -47,7 +47,7 @@ def draw_vline_loc(self, x, value): x (int): x location of the line value (int): value of the line """ - for y in range(self.screen.y_height // 2): + for y in range(self.screen.height // 2): self.screen.draw_raw(x, y, value) # self.screen.draw_pixel(x, pix, val) self.screen.push() diff --git a/demos/template/main.py b/demos/template/main.py index 817eaff..3bbd227 100644 --- a/demos/template/main.py +++ b/demos/template/main.py @@ -33,8 +33,8 @@ def run(self): # Create generator here while True: self.screen.draw_text( - self.screen.x_width // 2 - 5, - self.screen.y_height // 2 - 4, + self.screen.width // 2 - 5, + self.screen.height // 2 - 4, "HELLO THERE", push=True, ) diff --git a/demos/tetris/main.py b/demos/tetris/main.py index 2781e8e..f4e8c41 100644 --- a/demos/tetris/main.py +++ b/demos/tetris/main.py @@ -624,7 +624,7 @@ def init_screen(self): ) self.screen.draw_pixel( x + self.x_offset, - self.screen.y_height - self.y_offset - 1, + self.screen.height - self.y_offset - 1, full_pixel, combine=True, push=False, @@ -651,14 +651,14 @@ def draw_game_over_screen(self): """Draw the game over screen.""" self.screen.clear() self.screen.draw_text( - (self.screen.x_width // 2) - 4, (self.screen.y_height // 2) - 8, "GAME OVER" + (self.screen.width // 2) - 4, (self.screen.height // 2) - 8, "GAME OVER" ) self.screen.draw_text( - (self.screen.x_width // 2) - 4, (self.screen.y_height // 2) - 6, "---------" + (self.screen.width // 2) - 4, (self.screen.height // 2) - 6, "---------" ) self.screen.draw_text( - (self.screen.x_width // 2) - 4, - (self.screen.y_height // 2) - 4, + (self.screen.width // 2) - 4, + (self.screen.height // 2) - 4, "SCORE " + str(self.score), ) @@ -666,18 +666,18 @@ def draw_high_score_screen(self): """Draw the high score screen.""" self.screen.clear() self.screen.draw_text( - (self.screen.x_width // 3), - (self.screen.y_height // 2) - 8, + (self.screen.width // 3), + (self.screen.height // 2) - 8, "NEW hIGh SCORE", ) self.screen.draw_text( - (self.screen.x_width // 3) - 2, - (self.screen.y_height // 2) - 6, + (self.screen.width // 3) - 2, + (self.screen.height // 2) - 6, "--------------------", ) self.screen.draw_text( - (self.screen.x_width // 3) - 4, - (self.screen.y_height // 2) - 4, + (self.screen.width // 3) - 4, + (self.screen.height // 2) - 4, "ENTER YOuR INITIALS: " + "AA", ) @@ -685,18 +685,18 @@ def display_high_scores(self): """Display the high scores.""" self.screen.clear() self.screen.draw_text( - (self.screen.x_width // 2) - 5, - (self.screen.y_height // 3) - 4, + (self.screen.width // 2) - 5, + (self.screen.height // 3) - 4, "hIGh SCORES", ) self.screen.draw_text( - (self.screen.x_width // 2) - 12, - (self.screen.y_height // 3) + 26, + (self.screen.width // 2) - 12, + (self.screen.height // 3) + 26, "PRESS START TO PLAY AGAIN", ) self.screen.draw_text( - (self.screen.x_width // 2) - 5, - (self.screen.y_height // 3) - 2, + (self.screen.width // 2) - 5, + (self.screen.height // 3) - 2, "-----------", ) with open(self.high_score_file_path, "r") as scores: @@ -704,8 +704,8 @@ def display_high_scores(self): for score in scores: score = score.strip() self.screen.draw_text( - (self.screen.x_width // 2) - (len(score) // 2), - (self.screen.y_height // 3) + offset, + (self.screen.width // 2) - (len(score) // 2), + (self.screen.height // 3) + offset, score, ) offset += 4 diff --git a/demos/under_construction/main.py b/demos/under_construction/main.py index 39eac31..17f4532 100644 --- a/demos/under_construction/main.py +++ b/demos/under_construction/main.py @@ -34,8 +34,8 @@ def __init__(self, input_queue, output_queue, screen): def run(self): """Main loop of the demo""" # Create generator here - xmax = self.screen.x_width - ymax = self.screen.y_height + xmax = self.screen.width + ymax = self.screen.height line = self.screen.draw_shape_line dot = self.screen.draw_pixel diff --git a/demos/video/main.py b/demos/video/main.py index 92886f2..99cb9de 100644 --- a/demos/video/main.py +++ b/demos/video/main.py @@ -42,7 +42,7 @@ def __init__(self, input_queue, output_queue, screen): self.pause = False self.new_video = False self.next_frame = False - self.previous_frame = np.zeros((self.screen.x_width, self.screen.y_height)) + self.previous_frame = np.zeros((self.screen.width, self.screen.height)) # Get the next video in the list def get_next_video(self): @@ -74,8 +74,8 @@ def draw_frame(self, frame): # Get frame of which pixels need to get updated diff_frame = np.not_equal(frame, self.previous_frame) - for r in range(self.screen.x_width): - for c in range(self.screen.y_height): + for r in range(self.screen.width): + for c in range(self.screen.height): # If pixel is different from last frame, update if diff_frame[r, c]: self.screen.draw_pixel(c, r, int(frame[r, c])) diff --git a/demos/welcome_netlab/main.py b/demos/welcome_netlab/main.py index 7bc2080..8bd3d19 100644 --- a/demos/welcome_netlab/main.py +++ b/demos/welcome_netlab/main.py @@ -34,8 +34,8 @@ def __init__(self, input_queue, output_queue, screen): def run(self): """Run the demo""" # Create generator here - xmax = self.screen.x_width - ymax = self.screen.y_height + xmax = self.screen.width + ymax = self.screen.height line = self.screen.draw_shape_line dot = self.screen.draw_pixel diff --git a/demos/welcome_y/main.py b/demos/welcome_y/main.py index 0d55466..cb9a777 100644 --- a/demos/welcome_y/main.py +++ b/demos/welcome_y/main.py @@ -58,11 +58,11 @@ def run(self): if location[0] == 0: isLeft = False - if location[0] == self.screen.x_width - RIGHT_X_OFFSET - 1: + if location[0] == self.screen.width - RIGHT_X_OFFSET - 1: isLeft = True if location[1] == 0: isDown = True - if location[1] == self.screen.y_height - BOTTOM_Y_OFFSET - 1: + if location[1] == self.screen.height - BOTTOM_Y_OFFSET - 1: isDown = False if not isLeft: diff --git a/display/display.py b/display/display.py index 3566be5..a967190 100644 --- a/display/display.py +++ b/display/display.py @@ -4,20 +4,20 @@ class Display: """Game Display is a class that abstracts different S^3 panels into one display""" - def __init__(self, board_objects, x_width, y_height): + def __init__(self, board_objects, width, height): """ Constructor Args: board_objects (int[][]): 2d array of seven segment objects oriented how the sign is put together, i.e. [[panel0, panel1],[panel2,panel3]] - x_width (int): number of digits in the display on the x axis - y_height (int): number of pixels on the y axis (each vertical digit is split into two pixels) + width (int): number of digits in the display on the x axis + height (int): number of pixels on the y axis (each vertical digit is split into two pixels) """ self.board_objects = board_objects - self.x_width = int(x_width) - self.y_height = int(y_height) + self.width = int(width) + self.height = int(height) self.display_buf = [ - [0 for x in range(self.x_width)] for y in range(self.y_height // 2) + [0 for x in range(self.width)] for y in range(self.height // 2) ] self.changed_list = [] @@ -141,7 +141,7 @@ def push(self): def clear(self): """Clear all the panels on the display""" self.display_buf = [ - [0 for x in range(self.x_width)] for y in range(self.y_height // 2) + [0 for x in range(self.width)] for y in range(self.height // 2) ] for row in self.board_objects: for board in row: @@ -275,7 +275,7 @@ def draw_shape_line( def draw_text(self, x, y, msg, combine=True, push=False): """ - Print a message to the screen, y_height-2 is lowest y value accepted + Print a message to the screen, height-2 is lowest y value accepted without error. If the message is too long for the given x position, it will throw a ValueError. This function does not provide any wrapping. @@ -290,7 +290,7 @@ def draw_text(self, x, y, msg, combine=True, push=False): """ # Check to make sure the message is not too big - if len(msg) + x > self.x_width: + if len(msg) + x > self.width: raise ValueError( "Message is too long for the display at the given x position" ) diff --git a/display/segment_display.py b/display/segment_display.py index b0d8726..5651cca 100644 --- a/display/segment_display.py +++ b/display/segment_display.py @@ -20,8 +20,8 @@ def __init__(self, screen): self.screen = screen - self.screen_width = screen.x_width - 1 - self.screen_height = screen.y_height // 2 + self.screen_width = screen.width - 1 + self.screen_height = screen.height // 2 self.width = 2 * self.screen_width self.height = 3 * self.screen_height diff --git a/docs/Tutorials/Creating a demo.md b/docs/Tutorials/Creating a demo.md index 27e2183..d708b66 100644 --- a/docs/Tutorials/Creating a demo.md +++ b/docs/Tutorials/Creating a demo.md @@ -46,7 +46,7 @@ class Template: def run(self): # Create generator here while True: - self.screen.draw_text(self.screen.x_width // 2 - 5, self.screen.y_height // 2 - 4, "HELLO THERE", push=True) + self.screen.draw_text(self.screen.width // 2 - 5, self.screen.height // 2 - 4, "HELLO THERE", push=True) yield def stop(self): diff --git a/docs/Tutorials/Game Display (Graphics functions).md b/docs/Tutorials/Game Display (Graphics functions).md index 277fa9d..25e9023 100644 --- a/docs/Tutorials/Game Display (Graphics functions).md +++ b/docs/Tutorials/Game Display (Graphics functions).md @@ -2,13 +2,13 @@ Many of the following functions have parameters called combine and push. Push is inherently set to False. If it is set to True then all of the recent game display function calls will be written to the screen. Combine is inherently set to True. Each of the the individual seven segment digits are broken up into two separate digits. When writing to one of the pixels of a digit, combine states that you want to keep what is in the other pixel of the digit. When set to false it will erase whatever is on the other side of the digit. This is a quirk of making pixels out of seven segment digits. -Many of the below functions also take an x and y parameters. These are self explanatory. They are the x, y coordinates of where you want to start to draw. The origin is on the top left of the screen. A game_display object has a x_width and y_height class member that can be accessed and encouraged to be used. +Many of the below functions also take an x and y parameters. These are self explanatory. They are the x, y coordinates of where you want to start to draw. The origin is on the top left of the screen. A game_display object has a width and height class member that can be accessed and encouraged to be used. --- ### **init** -The init function has three parameters: board_objects, x_width, and y_height. The later two are easier to explain. The x_width and y_height are for how many pixels the display is across. A seven segment display digit is broken up into 1 pixel across and 2 pixels down, where the two pixels down share the middle line. Lets say you have 8 seven segment digits across you would put 8 for x_width and 2 for y_height. The last parameter is the board_objects. This parameter needs to be a 2d list of panel objects in the order they are on the sign. The hardware is broken up into 3 panels across and 4 panels down. Each panel has 16 columns and 6 rows of digits. An example of what would be passed into this is [[panel0, panel1, panel2],[panel3, panel4, panel5],[panel6, panel7, panel8],[panel9, panel10, panel11]]. For the physical hardware, the panel class is called SevenSegnment, which can be found under display/seven_seg.py. The simulator panel class is called Panel and is found under simulator/simulator.py. +The init function has three parameters: board_objects, width, and height. The later two are easier to explain. The width and height are for how many pixels the display is across. A seven segment display digit is broken up into 1 pixel across and 2 pixels down, where the two pixels down share the middle line. Lets say you have 8 seven segment digits across you would put 8 for width and 2 for height. The last parameter is the board_objects. This parameter needs to be a 2d list of panel objects in the order they are on the sign. The hardware is broken up into 3 panels across and 4 panels down. Each panel has 16 columns and 6 rows of digits. An example of what would be passed into this is [[panel0, panel1, panel2],[panel3, panel4, panel5],[panel6, panel7, panel8],[panel9, panel10, panel11]]. For the physical hardware, the panel class is called SevenSegnment, which can be found under display/seven_seg.py. The simulator panel class is called Panel and is found under simulator/simulator.py. ### draw_pixel diff --git a/runners/test.py b/runners/test.py index 8a27b79..c784a0b 100644 --- a/runners/test.py +++ b/runners/test.py @@ -22,8 +22,8 @@ def test_demo(demo_name, demo_module_name): """ logger.info(f"Testing {demo_name}...") display = MagicMock() - display.y_height = 48 - display.x_width = 48 + display.height = 48 + display.width = 48 input_q = Queue() output_q = Queue()