Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson3_diy4
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
af2db324
authored
2 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
9f3d4d2a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
13 deletions
snake.py
snake.py
View file @
af2db324
...
...
@@ -2,7 +2,7 @@ import pygame
from
pygame
import
locals
import
random
pygame
.
init
()
screen
=
pygame
.
display
.
set_mode
((
1320
,
96
0
))
screen
=
pygame
.
display
.
set_mode
((
660
,
48
0
))
FPSCLOCK
=
pygame
.
time
.
Clock
()
background
=
pygame
.
image
.
load
(
'bg.png'
)
right
=
pygame
.
image
.
load
(
'right.png'
)
...
...
@@ -11,7 +11,13 @@ body = pygame.image.load('body.png')
left
=
pygame
.
image
.
load
(
'left.png'
)
up
=
pygame
.
image
.
load
(
'up.png'
)
down
=
pygame
.
image
.
load
(
'down.png'
)
z
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
a
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
b
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
c
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
d
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
e
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
f
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
g
=
pygame
.
font
.
Font
(
'neuropol.ttf'
,
18
)
x
,
y
=
240
,
120
position
=
[(
180
,
90
),
(
180
,
120
),
(
210
,
120
),
(
x
,
y
)]
setheading
=
"right"
...
...
@@ -48,33 +54,35 @@ while True:
y
+=
30
position
.
append
((
x
,
y
))
if
x
==
a
and
y
==
b
:
a
=
random
.
randint
(
0
,
43
)
b
=
random
.
randint
(
0
,
31
)
a
=
random
.
randint
(
0
,
21
)
b
=
random
.
randint
(
0
,
15
)
a
*=
30
b
*=
30
score
+=
10
elif
x
==
c
and
y
==
d
:
c
=
random
.
randint
(
0
,
43
)
d
=
random
.
randint
(
0
,
31
)
c
=
random
.
randint
(
0
,
21
)
d
=
random
.
randint
(
0
,
15
)
c
*=
30
d
*=
30
score
+=
10
else
:
position
.
pop
(
0
)
if
x
<
0
or
x
>
1290
or
y
<
0
or
y
>
93
0
:
if
x
<
0
or
x
>
630
or
y
<
0
or
y
>
45
0
:
print
(
"Your score is:"
+
str
(
score
))
exit
()
screen
.
blit
(
background
,
(
0
,
0
))
screen
.
blit
(
background
,
(
661
,
0
))
screen
.
blit
(
background
,
(
0
,
481
))
screen
.
blit
(
background
,
(
661
,
481
))
screen
.
blit
(
background
,
(
1322
,
0
))
screen
.
blit
(
background
,
(
0
,
480
))
screen
.
blit
(
background
,
(
661
,
480
))
screen
.
blit
(
background
,
(
1322
,
480
))
screen
.
blit
(
snake_head
,
position
[
-
1
])
for
i
in
range
(
len
(
position
)
-
1
):
screen
.
blit
(
body
,
position
[
i
])
screen
.
blit
(
food
,
(
a
,
b
))
screen
.
blit
(
food
,
(
c
,
d
))
info
=
"Score:"
+
str
(
score
)
text
=
z
.
render
(
info
,
True
,(
0
,
0
,
0
))
a
=
"Score:"
+
str
(
score
)
text
=
a
.
render
(
z
,
True
,(
0
,
255
,
255
))
screen
.
blit
(
text
,(
540
,
10
))
pygame
.
display
.
update
()
FPSCLOCK
.
tick
(
5
)
\ No newline at end of file
FPSCLOCK
.
tick
(
score
/
10
+
3
)
\ No newline at end of file
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