Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson2_diy2
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
7fca05dd
authored
Aug 28, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
4695645d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
51 deletions
snake.py
src=http___c-ssl.duitang.com_uploads_item_201911_02_20191102145142_obpiz.thumb.1000_0.png&refer=http___c-ssl.duitang(1).jpg
snake.py
View file @
7fca05dd
import
pygame
from
pygame
import
locals
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
1056
,
591
))
FPS
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'src=http___img.3dmgame.com_uploads_images_news_20210702_1625220279_673168.jpg&refer=http___img.3dmgame.webp'
)
right
=
pygame
.
image
.
load
(
'
right.png'
)
food
=
pygame
.
image
.
load
(
'034c0f3479e3bda807cb8c83ed7a201d(1).jpg'
)
body
=
pygame
.
image
.
load
(
'body.png'
)
left
=
pygame
.
image
.
load
(
'left.png'
)
up
=
pygame
.
image
.
load
(
'up.png'
)
down
=
pygame
.
image
.
load
(
'down.png'
)
x
,
y
=
240
,
120
pos
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
set
=
'right'
snake_head
=
right
while
True
:
for
event
in
pygame
.
event
.
get
():
print
(
event
)
if
event
.
type
==
locals
.
QUIT
:
exit
()
elif
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_d
and
set
!=
'left'
:
set
=
'right'
snake_head
=
right
if
event
.
key
==
locals
.
K_a
and
set
!=
'right'
:
set
=
'left'
snake_head
=
left
if
event
.
key
==
locals
.
K_w
and
set
!=
'down'
:
set
=
'up'
snake_head
=
up
if
event
.
key
==
locals
.
K_s
and
set
!=
'up'
:
set
=
'down'
snake_head
=
down
if
set
==
'right'
:
x
+=
30
elif
set
==
'left'
:
x
-=
30
elif
set
==
'up'
:
y
-=
30
else
:
y
+=
30
pos
.
append
((
x
,
y
))
pos
.
pop
(
0
)
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
right
,
pos
[
-
1
])
for
i
in
range
(
len
(
pos
)
-
1
):
screen
.
blit
(
body
,
pos
[
i
])
screen
.
blit
(
food
,(
480
,
210
))
pygame
.
display
.
update
()
import
pygame
from
pygame
import
locals
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
1056
,
591
))
FPS
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'src=http___img.3dmgame.com_uploads_images_news_20210702_1625220279_673168.jpg&refer=http___img.3dmgame.webp'
)
right
=
pygame
.
image
.
load
(
'
src=http___c-ssl.duitang.com_uploads_item_201911_02_20191102145142_obpiz.thumb.1000_0.png&refer=http___c-ssl.duitang(1).jpg'
)
food
=
pygame
.
image
.
load
(
'034c0f3479e3bda807cb8c83ed7a201d(1).jpg'
)
body
=
pygame
.
image
.
load
(
'body.png'
)
left
=
pygame
.
image
.
load
(
'left.png'
)
up
=
pygame
.
image
.
load
(
'up.png'
)
down
=
pygame
.
image
.
load
(
'down.png'
)
x
,
y
=
240
,
120
pos
=
[(
180
,
90
),(
180
,
120
),(
210
,
120
),(
x
,
y
)]
set
=
'right'
snake_head
=
right
while
True
:
for
event
in
pygame
.
event
.
get
():
print
(
event
)
if
event
.
type
==
locals
.
QUIT
:
exit
()
elif
event
.
type
==
locals
.
KEYDOWN
:
if
event
.
key
==
locals
.
K_d
and
set
!=
'left'
:
set
=
'right'
snake_head
=
right
if
event
.
key
==
locals
.
K_a
and
set
!=
'right'
:
set
=
'left'
snake_head
=
left
if
event
.
key
==
locals
.
K_w
and
set
!=
'down'
:
set
=
'up'
snake_head
=
up
if
event
.
key
==
locals
.
K_s
and
set
!=
'up'
:
set
=
'down'
snake_head
=
down
if
set
==
'right'
:
x
+=
30
elif
set
==
'left'
:
x
-=
30
elif
set
==
'up'
:
y
-=
30
else
:
y
+=
30
pos
.
append
((
x
,
y
))
pos
.
pop
(
0
)
screen
.
blit
(
background
,(
0
,
0
))
screen
.
blit
(
right
,
pos
[
-
1
])
for
i
in
range
(
len
(
pos
)
-
1
):
screen
.
blit
(
body
,
pos
[
i
])
screen
.
blit
(
food
,(
480
,
210
))
pygame
.
display
.
update
()
FPS
.
tick
(
5
)
\ No newline at end of file
src=http___c-ssl.duitang.com_uploads_item_201911_02_20191102145142_obpiz.thumb.1000_0.png&refer=http___c-ssl.duitang(1).jpg
0 → 100644
View file @
7fca05dd
1.72 KB
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