Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson1_3
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9053dd7c
authored
May 20, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
446a7fa3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
15 deletions
Untitled-1.py.py
snake.py
Untitled-1.py.py
View file @
9053dd7c
...
...
@@ -7,30 +7,41 @@ apple=pygame.image.load("apple.png")
right
=
pygame
.
image
.
load
(
"right.png"
)
body
=
pygame
.
image
.
load
(
"body.png"
)
x
,
y
=
240
,
120
setheading
=
"r"
position
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
FPSCLOCK
=
pygame
.
time
.
Clock
()
while
True
:
for
event
in
pygame
.
event
.
get
():
print
(
event
.
type
)
print
(
event
)
if
event
.
type
==
locals
.
QUIT
:
exit
()
screen
.
blit
(
bg
,(
0
,
0
))
screen
.
blit
(
apple
,(
550
,
550
))
screen
.
blit
(
right
,(
x
,
y
))
x
+=
1.3
y
+=
1.3
screen
.
blit
(
body
,(
x
-
30
,
y
))
screen
.
blit
(
body
,(
x
-
60
,
y
))
screen
.
blit
(
body
,(
x
-
90
,
y
))
screen
.
blit
(
body
,(
x
-
120
,
y
))
pygame
.
display
.
update
()
FPSCLOCK
.
tick
(
60
)
screen
.
blit
(
apple
,(
550
,
550
))
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_DOWN
:
setheading
=
"d"
if
event
.
key
==
locals
.
K_UP
:
setheading
=
"u"
screen
.
blit
(
right
,(
x
,
y
))
for
i
in
range
(
len
(
position
)
-
2
,
-
1
,
-
1
):
screen
.
blit
(
body
,
position
[
i
])
if
setheading
==
"d"
:
y
+=
30
if
setheading
==
"r"
:
x
+=
30
position
.
append
((
x
,
y
))
position
.
pop
(
0
)
pygame
.
display
.
update
()
FPSCLOCK
.
tick
(
3
)
...
...
snake.py
View file @
9053dd7c
This diff is collapsed.
Click to expand it.
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