Skip to content

Commit 0d1e259

Browse files
authored
Merge pull request #1997 from FoamyGuy/neko_version_fix
fix neko cat for 7.1.1
2 parents db94ff9 + a4a3628 commit 0d1e259

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

CircuitPython_Neko_Cat/code.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class NekoAnimatedSprite(displayio.TileGrid):
4545
# Minimum time to stop and scratch in seconds. larger time means scratch for longer
4646
CONFIG_MIN_SCRATCH_TIME = 2
4747

48+
TILE_WIDTH = 32
49+
TILE_HEIGHT = 32
50+
4851
# State object indexes
4952
_ID = 0
5053
_ANIMATION_LIST = 1
@@ -234,23 +237,23 @@ def moving_to(self, new_moving_to):
234237
_clamped_y = new_moving_to[1]
235238

236239
# if x location of new value is within 1/2 tile size of left edge of display
237-
if new_moving_to[0] < self.tile_width // 2 + 1:
240+
if new_moving_to[0] < self.TILE_WIDTH // 2 + 1:
238241
# override x to 1/2 tile size away from the left edge of display
239-
_clamped_x = self.tile_width // 2 + 1
242+
_clamped_x = self.TILE_WIDTH // 2 + 1
240243

241244
# if x location of new value is within 1/2 tile size of right edge of display
242-
if new_moving_to[0] > self._display_size[0] - self.tile_width // 2 - 1:
245+
if new_moving_to[0] > self._display_size[0] - self.TILE_WIDTH // 2 - 1:
243246
# override x to 1/2 tile size away from right edge of display
244-
_clamped_x = self._display_size[0] - self.tile_width // 2 - 1
247+
_clamped_x = self._display_size[0] - self.TILE_WIDTH // 2 - 1
245248

246249
# if y location of new value is within 1/2 tile size of top edge of display
247-
if new_moving_to[1] < self.tile_height // 2 + 1:
250+
if new_moving_to[1] < self.TILE_HEIGHT // 2 + 1:
248251
# override y to 1/2 tile size away from top edge
249-
_clamped_y = self.tile_height // 2 + 1
252+
_clamped_y = self.TILE_HEIGHT // 2 + 1
250253
# if y location of new value is within 1/2 tile size of bottom edge of display
251-
if new_moving_to[1] > self._display_size[1] - self.tile_height // 2 - 1:
254+
if new_moving_to[1] > self._display_size[1] - self.TILE_HEIGHT // 2 - 1:
252255
# override y to 1/2 tile size away from bottom edge
253-
_clamped_y = self._display_size[1] - self.tile_height // 2 - 1
256+
_clamped_y = self._display_size[1] - self.TILE_HEIGHT // 2 - 1
254257

255258
# update the moving to target location
256259
self._moving_to = (_clamped_x, _clamped_y)
@@ -335,7 +338,7 @@ def center_point(self):
335338
336339
:return tuple: x/y location of Neko's current center point:
337340
"""
338-
return (self.x + self.tile_width // 2, self.y + self.tile_height // 2)
341+
return (self.x + self.TILE_WIDTH // 2, self.y + self.TILE_HEIGHT // 2)
339342

340343
def update(self):
341344
# pylint: disable=too-many-branches,too-many-statements
@@ -353,9 +356,9 @@ def update(self):
353356
if self.moving_to:
354357

355358
# if the x of the target location is between the left and right edges of Neko
356-
if self.x < self.moving_to[0] < self.x + self.tile_width:
359+
if self.x < self.moving_to[0] < self.x + self.TILE_WIDTH:
357360
# if the y of the target location is between top and bottom edges of Neko
358-
if self.y < self.moving_to[1] < self.y + self.tile_height:
361+
if self.y < self.moving_to[1] < self.y + self.TILE_HEIGHT:
359362
# change to either sleeping or cleaning states
360363
self.current_state = random.choice(
361364
(self.STATE_CLEANING, self.STATE_SLEEPING)
@@ -480,7 +483,7 @@ def update(self):
480483
if (
481484
0
482485
<= (self.x + self.current_state[self._MOVEMENT_STEP][0])
483-
< (self._display_size[0] - self.tile_width)
486+
< (self._display_size[0] - self.TILE_WIDTH)
484487
):
485488

486489
# move the cat horizontally by current state step size x
@@ -489,7 +492,7 @@ def update(self):
489492
else: # we ran into a side wall
490493
if self.x > self.CONFIG_STEP_SIZE:
491494
# ran into right wall
492-
self.x = self._display_size[0] - self.tile_width - 1
495+
self.x = self._display_size[0] - self.TILE_WIDTH - 1
493496
# change state to scratching right
494497
self.current_state = self.STATE_SCRATCHING_RIGHT
495498
else:
@@ -503,7 +506,7 @@ def update(self):
503506
if (
504507
0
505508
<= (self.y + self.current_state[self._MOVEMENT_STEP][1])
506-
< (self._display_size[1] - self.tile_height)
509+
< (self._display_size[1] - self.TILE_HEIGHT)
507510
):
508511

509512
# move the cat vertically by current state step size y
@@ -512,7 +515,7 @@ def update(self):
512515
else: # ran into top or bottom wall
513516
if self.y > self.CONFIG_STEP_SIZE:
514517
# ran into bottom wall
515-
self.y = self._display_size[1] - self.tile_height - 1
518+
self.y = self._display_size[1] - self.TILE_HEIGHT - 1
516519
# change state to scratching down
517520
self.current_state = self.STATE_SCRATCHING_DOWN
518521
else:
@@ -570,8 +573,8 @@ def update(self):
570573
neko = NekoAnimatedSprite(animation_time=ANIMATION_TIME)
571574

572575
# put Neko in center of display
573-
neko.x = display.width // 2 - neko.tile_width // 2
574-
neko.y = display.height // 2 - neko.tile_height // 2
576+
neko.x = display.width // 2 - neko.TILE_WIDTH // 2
577+
neko.y = display.height // 2 - neko.TILE_HEIGHT // 2
575578

576579
# add neko to main_group
577580
main_group.append(neko)

0 commit comments

Comments
 (0)