Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions demos/autotype/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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))
Expand All @@ -57,30 +57,26 @@ 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
for char in word:
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
Expand Down
80 changes: 36 additions & 44 deletions demos/breakout/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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,
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -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
Expand All @@ -200,15 +192,15 @@ 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)

# 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
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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()
Expand All @@ -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] = []
Expand All @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Loading
Loading