Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
st7789_mpy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
st7789_mpy
Commits
800a3f97
Commit
800a3f97
authored
Dec 16, 2021
by
russhughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
toaster collision: adjust sprite if trailing not leading
parent
054aed01
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
30 deletions
+31
-30
examples/RP2/Waveshare-lcd-2/toasters/toasters.py
examples/RP2/Waveshare-lcd-2/toasters/toasters.py
+16
-15
examples/esp32_st7789/toasters/toasters.py
examples/esp32_st7789/toasters/toasters.py
+15
-15
No files found.
examples/RP2/Waveshare-lcd-2/toasters/toasters.py
View file @
800a3f97
...
...
@@ -26,12 +26,6 @@ def collide(a_col, a_row, a_width, a_height, b_col, b_row, b_width, b_height):
return
(
a_col
+
a_width
>=
b_col
and
a_col
<=
b_col
+
b_width
and
a_row
+
a_height
>=
b_row
and
a_row
<=
b_row
+
b_height
)
def
collision
(
sprites
):
''''return true if any sprites overlap'''
return
any
(
collide
(
a
.
col
,
a
.
row
,
a
.
width
,
a
.
height
,
b
.
col
,
b
.
row
,
b
.
width
,
b
.
height
)
for
a
,
b
in
zip
(
sprites
[::],
sprites
[
1
::]))
def
random_start
(
tft
,
sprites
,
bitmaps
,
num
):
'''
Return a random location along the top or right of the screen, if that location would overlaps
...
...
@@ -108,15 +102,22 @@ def main():
new_row
=
self
.
row
+
self
.
dir_row
# if new location collides with another sprite, change direction for 32 frames
if
any
(
collide
(
new_col
,
new_row
,
self
.
width
,
self
.
height
,
sprite
.
col
,
sprite
.
row
,
sprite
.
width
,
sprite
.
height
)
for
sprite
in
sprites
if
self
.
num
!=
sprite
.
num
):
self
.
iceberg
=
32
self
.
dir_col
=
-
1
self
.
dir_row
=
3
new_col
=
self
.
col
+
self
.
dir_col
new_row
=
self
.
row
+
self
.
dir_row
# if new location collides with another sprite, change direction for 32 frames
for
sprite
in
sprites
:
if
(
self
.
num
!=
sprite
.
num
and
collide
(
new_col
,
new_row
,
self
.
width
,
self
.
height
,
sprite
.
col
,
sprite
.
row
,
sprite
.
width
,
sprite
.
height
,
)
and
(
self
.
col
>
sprite
.
col
)):
self
.
iceberg
=
32
self
.
dir_col
=
-
1
self
.
dir_row
=
3
new_col
=
self
.
col
+
self
.
dir_col
new_row
=
self
.
row
+
self
.
dir_row
self
.
col
=
new_col
self
.
row
=
new_row
...
...
examples/esp32_st7789/toasters/toasters.py
View file @
800a3f97
...
...
@@ -24,12 +24,6 @@ def collide(a_col, a_row, a_width, a_height, b_col, b_row, b_width, b_height):
return
(
a_col
+
a_width
>=
b_col
and
a_col
<=
b_col
+
b_width
and
a_row
+
a_height
>=
b_row
and
a_row
<=
b_row
+
b_height
)
def
collision
(
sprites
):
''''return true if any sprites overlap'''
return
any
(
collide
(
a
.
col
,
a
.
row
,
a
.
width
,
a
.
height
,
b
.
col
,
b
.
row
,
b
.
width
,
b
.
height
)
for
a
,
b
in
zip
(
sprites
[::],
sprites
[
1
::]))
def
random_start
(
tft
,
sprites
,
bitmaps
,
num
):
'''
Return a random location along the top or right of the screen, if that location would overlaps
...
...
@@ -106,15 +100,21 @@ def main():
new_row
=
self
.
row
+
self
.
dir_row
# if new location collides with another sprite, change direction for 32 frames
if
any
(
collide
(
new_col
,
new_row
,
self
.
width
,
self
.
height
,
sprite
.
col
,
sprite
.
row
,
sprite
.
width
,
sprite
.
height
)
for
sprite
in
sprites
if
self
.
num
!=
sprite
.
num
):
self
.
iceberg
=
32
self
.
dir_col
=
-
1
self
.
dir_row
=
3
new_col
=
self
.
col
+
self
.
dir_col
new_row
=
self
.
row
+
self
.
dir_row
for
sprite
in
sprites
:
if
(
self
.
num
!=
sprite
.
num
and
collide
(
new_col
,
new_row
,
self
.
width
,
self
.
height
,
sprite
.
col
,
sprite
.
row
,
sprite
.
width
,
sprite
.
height
,
)
and
(
self
.
col
>
sprite
.
col
)):
self
.
iceberg
=
32
self
.
dir_col
=
-
1
self
.
dir_row
=
3
new_col
=
self
.
col
+
self
.
dir_col
new_row
=
self
.
row
+
self
.
dir_row
self
.
col
=
new_col
self
.
row
=
new_row
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment