Skip to content

Commit 74c5700

Browse files
Merge pull request #91 from NET-BYU/fix_naming_dim
Rename dims
2 parents 0997679 + cfad7b0 commit 74c5700

File tree

31 files changed

+341
-361
lines changed

31 files changed

+341
-361
lines changed

demos/autotype/main.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def run(self):
3333
x_cursor = 0
3434
y_cursor = 0
3535

36-
pixel_vals = np.zeros((self.screen.x_width, self.screen.y_height))
36+
pixel_vals = np.zeros((self.screen.width, self.screen.height))
3737

3838
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."
3939
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):
4545

4646
while True:
4747
for word in typed_text:
48-
if self.screen.x_width - x_cursor < len(word):
48+
if self.screen.width - x_cursor < len(word):
4949
x_cursor = 0
5050
y_cursor += 2
51-
if y_cursor >= self.screen.y_height:
51+
if y_cursor >= self.screen.height:
5252
y_cursor -= 2
5353

5454
# print(self.screen.get_pixel(0, 0))
@@ -57,30 +57,26 @@ def run(self):
5757
# print(self.screen.get_pixel(1, 0))
5858
# print(self.screen.get_pixel(1, 1))
5959

60-
for y in range(self.screen.y_height):
61-
for x in range(self.screen.x_width):
60+
for y in range(self.screen.height):
61+
for x in range(self.screen.width):
6262
pixel_vals[y][x] = self.screen.get_pixel(x, y)
6363

6464
pixel_vals = np.delete(pixel_vals, 0, 0)
6565
pixel_vals = np.delete(pixel_vals, 0, 0)
66-
pixel_vals = np.append(
67-
pixel_vals, [np.zeros(self.screen.x_width)], 0
68-
)
69-
pixel_vals = np.append(
70-
pixel_vals, [np.zeros(self.screen.x_width)], 0
71-
)
66+
pixel_vals = np.append(pixel_vals, [np.zeros(self.screen.width)], 0)
67+
pixel_vals = np.append(pixel_vals, [np.zeros(self.screen.width)], 0)
7268

7369
self.screen.clear()
74-
for y in range(self.screen.y_height):
75-
for x in range(self.screen.x_width):
70+
for y in range(self.screen.height):
71+
for x in range(self.screen.width):
7672
self.screen.draw_pixel(x, y, int(pixel_vals[y][x]))
7773
self.screen.push()
7874
yield
7975
for char in word:
8076
self.screen.draw_text(x_cursor, y_cursor, char, push=True)
8177
x_cursor += 1
8278
yield
83-
if self.screen.x_width - x_cursor > 0:
79+
if self.screen.width - x_cursor > 0:
8480
self.screen.draw_text(x_cursor, y_cursor, " ", push=True)
8581
x_cursor += 1
8682
yield

demos/breakout/main.py

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,11 @@ def run(self):
6666
restart_cnt = 10
6767

6868
# Waits for user ready
69+
screen.draw_text((screen.width // 2) - 4, (screen.height // 2) - 8, "BREAKOUT")
6970
screen.draw_text(
70-
(screen.x_width // 2) - 4, (screen.y_height // 2) - 8, "BREAKOUT"
71-
)
72-
screen.draw_text(
73-
(screen.x_width // 2) - 5, (screen.y_height // 2) - 4, "PRESS START"
74-
)
75-
screen.draw_text(
76-
(screen.x_width // 2) - 4, (screen.y_height // 2) - 2, "TO BEGIN"
71+
(screen.width // 2) - 5, (screen.height // 2) - 4, "PRESS START"
7772
)
73+
screen.draw_text((screen.width // 2) - 4, (screen.height // 2) - 2, "TO BEGIN")
7874
screen.push()
7975

8076
# Don't start until user presses start
@@ -87,15 +83,11 @@ def run(self):
8783
yield
8884

8985
# Erase startup text and initialize screen
86+
screen.draw_text((screen.width // 2) - 4, (screen.height // 2) - 8, " ")
9087
screen.draw_text(
91-
(screen.x_width // 2) - 4, (screen.y_height // 2) - 8, " "
92-
)
93-
screen.draw_text(
94-
(screen.x_width // 2) - 5, (screen.y_height // 2) - 4, " "
95-
)
96-
screen.draw_text(
97-
(screen.x_width // 2) - 4, (screen.y_height // 2) - 2, " "
88+
(screen.width // 2) - 5, (screen.height // 2) - 4, " "
9889
)
90+
screen.draw_text((screen.width // 2) - 4, (screen.height // 2) - 2, " ")
9991
screen.push()
10092
self.init_screen(self.screen)
10193

@@ -117,8 +109,8 @@ def run(self):
117109
# Pause and unpause routine
118110
if keypress == "START_P":
119111
screen.draw_text(
120-
(screen.x_width // 2) - 3,
121-
(screen.y_height // 2) - 8,
112+
(screen.width // 2) - 3,
113+
(screen.height // 2) - 8,
122114
"PAUSED",
123115
push=True,
124116
)
@@ -133,8 +125,8 @@ def run(self):
133125
):
134126
if keypress == "START_P":
135127
screen.draw_text(
136-
(screen.x_width // 2) - 3,
137-
(screen.y_height // 2) - 8,
128+
(screen.width // 2) - 3,
129+
(screen.height // 2) - 8,
138130
" ",
139131
push=True,
140132
)
@@ -180,14 +172,14 @@ def run(self):
180172
is_down = True
181173

182174
# Checks to see if ball hits paddle
183-
if self.ball[1] == screen.y_height - 2:
175+
if self.ball[1] == screen.height - 2:
184176
if self.ball[0] in self.paddle:
185177
spin, is_left = self.get_angle(self.paddle)
186178
self.frame_rate = 20 + (spin // (1 + spin // 2))
187179
is_down = False
188180

189181
# Checks to see if ball falls out of screen
190-
if self.ball[1] >= screen.y_height - 1:
182+
if self.ball[1] >= screen.height - 1:
191183
is_down = True
192184
lives -= 1
193185
self.frame_rate = 20
@@ -200,15 +192,15 @@ def run(self):
200192
if lives == 0:
201193
self.gameover = True
202194
break
203-
self.ball = [screen.x_width // 2, screen.y_height // 2]
195+
self.ball = [screen.width // 2, screen.height // 2]
204196

205197
# Calculates ball path
206198
is_left, is_down = self.ball_travel(is_left, is_down, spin, screen)
207199

208200
# Quick pause to reorient if life lost
209201
if restart:
210202
restart_cnt -= 1
211-
self.ball = [screen.x_width // 2, screen.y_height // 2]
203+
self.ball = [screen.width // 2, screen.height // 2]
212204
if restart_cnt == 0:
213205
restart_cnt = 10
214206
restart = False
@@ -220,13 +212,13 @@ def run(self):
220212
self.paddle[val] -= 1
221213
screen.draw_pixel(
222214
self.paddle[0],
223-
screen.y_height - 1,
215+
screen.height - 1,
224216
PIXEL_ON,
225217
combine=False,
226218
)
227219
screen.draw_pixel(
228220
self.paddle[-1] + 1,
229-
screen.y_height - 1,
221+
screen.height - 1,
230222
PIXEL_OFF,
231223
combine=False,
232224
)
@@ -236,13 +228,13 @@ def run(self):
236228
self.paddle[val] += 1
237229
screen.draw_pixel(
238230
self.paddle[0] - 1,
239-
screen.y_height - 1,
231+
screen.height - 1,
240232
PIXEL_OFF,
241233
combine=False,
242234
)
243235
screen.draw_pixel(
244236
self.paddle[-1],
245-
screen.y_height - 1,
237+
screen.height - 1,
246238
PIXEL_ON,
247239
combine=False,
248240
)
@@ -262,19 +254,19 @@ def run(self):
262254

263255
screen.clear()
264256
screen.draw_text(
265-
(screen.x_width // 2) - 4, (screen.y_height // 2) - 8, "GAME OVER"
257+
(screen.width // 2) - 4, (screen.height // 2) - 8, "GAME OVER"
266258
)
267259
screen.draw_text(
268-
(screen.x_width // 2) - 4, (screen.y_height // 2) - 6, "---------"
260+
(screen.width // 2) - 4, (screen.height // 2) - 6, "---------"
269261
)
270262
screen.draw_text(
271-
(screen.x_width // 2) - 4,
272-
(screen.y_height // 2) - 4,
263+
(screen.width // 2) - 4,
264+
(screen.height // 2) - 4,
273265
"SCORE " + str(score),
274266
)
275267
screen.draw_text(
276-
(screen.x_width // 2) - 4,
277-
(screen.y_height // 2) - 2,
268+
(screen.width // 2) - 4,
269+
(screen.height // 2) - 2,
278270
"HISCORE " + str(hscore),
279271
)
280272
screen.push()
@@ -295,22 +287,22 @@ def init_screen(self, screen):
295287
self.paddle = [24]
296288

297289
if self.level == 1:
298-
self.line_right = screen.x_width - ARENA_START
290+
self.line_right = screen.width - ARENA_START
299291
self.line_left = ARENA_START - 1
300292

301-
self.ball = [screen.x_width // 2, screen.y_height // 2]
293+
self.ball = [screen.width // 2, screen.height // 2]
302294

303295
if self.level % 2 == 0:
304-
for pix in range(screen.y_height):
296+
for pix in range(screen.height):
305297
screen.draw_pixel(self.line_left, pix, 0x0)
306298
screen.draw_pixel(self.line_right, pix, 0x0)
307299
self.line_left = 13 - self.level
308-
self.line_right = (screen.x_width - ARENA_START) + self.level
300+
self.line_right = (screen.width - ARENA_START) + self.level
309301
else:
310302
self.rows = self.level + 2
311303

312-
screen.draw_vline(self.line_left, 0, screen.y_height, left=False)
313-
screen.draw_vline(self.line_right, 0, screen.y_height)
304+
screen.draw_vline(self.line_left, 0, screen.height, left=False)
305+
screen.draw_vline(self.line_right, 0, screen.height)
314306

315307
for row in range(self.rows):
316308
self.bricks[row] = []
@@ -331,10 +323,10 @@ def init_screen(self, screen):
331323
self.paddle.append(self.paddle[-1] + 1)
332324

333325
for val in range(self.line_left + 1, self.line_right):
334-
screen.draw_pixel(val, screen.y_height - 1, PIXEL_OFF)
326+
screen.draw_pixel(val, screen.height - 1, PIXEL_OFF)
335327

336328
for val in self.paddle:
337-
screen.draw_pixel(val, screen.y_height - 1, PIXEL_ON, combine=False)
329+
screen.draw_pixel(val, screen.height - 1, PIXEL_ON, combine=False)
338330

339331
screen.push()
340332

@@ -401,10 +393,10 @@ def ball_travel(self, is_left, is_down, spin, screen):
401393

402394
if is_down:
403395
# A possible conflict with ball trying to jump paddle
404-
if (screen.y_height - 1) - (self.ball[1] + spin) <= 0 and spin > 1:
396+
if (screen.height - 1) - (self.ball[1] + spin) <= 0 and spin > 1:
405397
for block in collide_field:
406398
if block[0] in self.paddle:
407-
self.ball[1] = screen.y_height - 2
399+
self.ball[1] = screen.height - 2
408400
is_down = False
409401
if self.paddle.index(block[0]) > len(self.paddle) // 2:
410402
is_left = False
@@ -433,7 +425,7 @@ def ball_travel(self, is_left, is_down, spin, screen):
433425

434426
if self.ball[1] < 0:
435427
self.ball[1] = 0
436-
elif self.ball[1] > screen.y_height - 1:
437-
self.ball[1] = screen.y_height - 1
428+
elif self.ball[1] > screen.height - 1:
429+
self.ball[1] = screen.height - 1
438430

439431
return is_left, is_down

0 commit comments

Comments
 (0)