Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson2_diy1
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
03264861
authored
Dec 14, 2020
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
8cb2b0e2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
7 deletions
snake.py
snake.py
View file @
03264861
...
@@ -4,20 +4,47 @@ pygame.init()
...
@@ -4,20 +4,47 @@ pygame.init()
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
FPSC
=
pygame
.
time
.
Clock
()
FPSC
=
pygame
.
time
.
Clock
()
x
,
y
=
240
,
120
x
,
y
=
240
,
120
pos
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
background
=
pygame
.
image
.
load
(
'bg.png'
)
background
=
pygame
.
image
.
load
(
'bg.png'
)
right
=
pygame
.
image
.
load
(
'right.png'
)
right
=
pygame
.
image
.
load
(
'right.png'
)
left
=
pygame
.
image
.
load
(
'left.png'
)
up
=
pygame
.
image
.
load
(
'up.png'
)
down
=
pygame
.
image
.
load
(
'down.png'
)
food
=
pygame
.
image
.
load
(
'apple.png'
)
food
=
pygame
.
image
.
load
(
'apple.png'
)
body
=
pygame
.
image
.
load
(
'body.png'
)
body
=
pygame
.
image
.
load
(
'body.png'
)
SH
=
"right"
s_h
=
right
while
True
:
while
True
:
for
event
in
pygame
.
event
.
get
():
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
if
event
.
type
==
locals
.
QUIT
:
exit
()
exit
()
x
+=
30
if
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_RIGHT
and
SH
!=
"left"
:
SH
=
"right"
s_h
=
right
if
event
.
key
==
locals
.
K_RIGHT
and
SH
!=
"right"
:
SH
=
"left"
s_h
=
left
if
event
.
key
==
locals
.
K_RIGHT
and
SH
!=
"down"
:
SH
=
"up"
s_h
=
up
if
event
.
key
==
locals
.
K_RIGHT
and
SH
!=
"up"
:
SH
=
"down"
s_h
=
down
if
SH
==
"right"
:
x
=
x
+
30
if
SH
==
"left"
:
x
=
x
-
30
if
SH
==
"up"
:
y
=
y
-
30
if
SH
==
"down"
:
y
=
y
+
30
pos
.
append
((
x
,
y
))
pos
.
pop
(
0
)
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
right
,
(
240
,
120
))
screen
.
blit
(
right
,
pos
[
-
1
])
screen
.
blit
(
body
,
(
210
,
120
))
for
i
in
range
(
len
(
pos
)
-
1
):
screen
.
blit
(
body
,
(
180
,
120
))
screen
.
blit
(
body
,
pos
[
i
])
screen
.
blit
(
body
,
(
180
,
90
))
screen
.
blit
(
food
,
(
360
,
300
))
screen
.
blit
(
food
,
(
360
,
300
))
pygame
.
display
.
update
()
pygame
.
display
.
update
()
FPSC
=
tick
(
3
)
FPSC
.
tick
(
1
)
\ No newline at end of file
\ No newline at end of file
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