Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
se3xa3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hameed Andy
se3xa3
Commits
1dc2254c
Commit
1dc2254c
authored
6 years ago
by
Usman Irfan
Browse files
Options
Downloads
Patches
Plain Diff
added comments
parent
2bb10026
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
BlankProjectTemplate/src/Gameplay.py
+21
-12
21 additions, 12 deletions
BlankProjectTemplate/src/Gameplay.py
with
21 additions
and
12 deletions
BlankProjectTemplate/src/Gameplay.py
+
21
−
12
View file @
1dc2254c
...
...
@@ -16,9 +16,9 @@ vel = 10
global
a
a
=
0
#defining a list to keep track of snake's head
snake_loc
=
[]
#defining a list to update snanke's length
snake_loc
=
[]
#variable to increment snake's length, initially it would be 1
snake_length
=
1
...
...
@@ -96,7 +96,9 @@ while run:
if
(
abs
(
x
-
food_location
[
0
])
<
15
and
abs
(
y
-
food_location
[
1
])
<
15
):
score
+=
10
print
(
score
)
snake_length
+=
5
#increment the length by 3 unit every time
snake_length
+=
3
...
...
@@ -105,27 +107,34 @@ while run:
#consumption of food block
food
.
redraw_food
(
x
,
y
,
food_location
,
screenSize
)
snake_top
=
[]
snake_top
.
append
(
x
)
snake_top
.
append
(
y
)
snake_loc
.
append
(
snake_top
)
snake_head
=
[]
snake_head
.
append
(
x
)
snake_head
.
append
(
y
)
snake_loc
.
append
(
snake_head
)
snake_blocks
=
len
(
snake_loc
)
#Draw food item
food
.
draw_food
(
food_location
)
if
(
len
(
snake_loc
))
>
snake_length
:
if
snake_blocks
>
snake_length
:
#keep updating the new block
del
snake_loc
[
0
]
'''
Logic for updating the length is taken from:
CodeWithHarry, CodeWithHarry. “Snakes Game: Length Increment Logic - Python Game Development Using Pygame In Hindi #17.”
YouTube, YouTube, 2 Oct. 2018,
www.youtube.com/watch?v=mkGJb0W03DM&index=17&list=PLu0W_9lII9ailUQcxEPZrWgDoL36BtPYb.
'''
#food.update_score(x,y,food_location, score)
#Draw snake
snake
.
draw
(
snake_loc
)
#update display
pygame
.
display
.
update
()
print
(
snake_head
,
'
\n
'
)
print
(
snake_loc
)
pygame
.
quit
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment