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
91440a2a
Commit
91440a2a
authored
6 years ago
by
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
https://gitlab.cas.mcmaster.ca/hameea1/se3xa3
parents
4d9578c2
6eff3f9a
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/Snake_2.o_Demo.py
+20
-20
20 additions, 20 deletions
BlankProjectTemplate/src/Snake_2.o_Demo.py
with
20 additions
and
20 deletions
BlankProjectTemplate/src/Snake_2.o_Demo.py
+
20
−
20
View file @
91440a2a
## Author: Usman Irfan, Andy Hameed
# This module will be used to control snake body movements and gameplay
## @file Snake_2.o.py
# @author Andy Hameed, Usman Irfan
# @brief implements gameplay and connects the different components of the game
# @date 11/09/2018
import
pygame
from
random
import
randint
#initializing PyGame and setting game window dimensions
pygame
.
init
()
#setting width and size of window to screenSize
screenSize
=
500
win
=
pygame
.
display
.
set_mode
((
screenSize
,
screenSize
))
pygame
.
display
.
set_caption
(
"
My Game
"
)
pygame
.
display
.
set_caption
(
"
Snake 2.o
"
)
#Define color constants
white
=
(
255
,
255
,
255
)
...
...
@@ -18,27 +18,26 @@ red = (255,0,0)
blue
=
(
0
,
0
,
255
)
black
=
(
0
,
0
,
0
)
#width1, size1 correspond to constant width and size for the food block
#width and size change over time as the snake consumes food
width
,
width1
=
20
,
20
# can replace with size - one number
size
,
size1
=
20
,
20
size
=
20
# One size for all block created for snake
# One size for all blocks created for snake
size
=
20
#velocity and score
vel
=
10
score
=
0
x
=
randint
(
0
,
screenSize
-
size
)
y
=
randint
(
0
,
screenSize
-
size
)
#initial x and y coordinates of the snake
x_init
=
randint
(
0
,
screenSize
-
size
)
y_init
=
randint
(
0
,
screenSize
-
size
)
speed
=
40
# 0 gives (- direction)
# 1 gives (+ direction)
direction
=
0
# 0 - x-axis , 1 - y-axis
axis
=
0
location
=
[]
food_x
=
randint
(
0
,
screenSize
-
size
)
...
...
@@ -96,8 +95,8 @@ while run:
#consumption of food block
if
(
abs
(
x
-
food_x
)
<
15
and
abs
(
y
-
food_y
)
<
15
):
score
+=
1
food_x
=
randint
(
0
,
screenSize
-
size
1
)
food_y
=
randint
(
0
,
screenSize
-
size
1
)
food_x
=
randint
(
0
,
screenSize
-
size
)
food_y
=
randint
(
0
,
screenSize
-
size
)
location
=
[
food_x
,
food_y
]
## --------------------------DELETE --------------------------
...
...
@@ -106,15 +105,16 @@ while run:
size
+=
20
else
:
size
+=
20
print
(
'
score =
'
,
score
)
##---------------------------DELETE----------------------------
print
(
'
score =
'
,
score
)
win
.
fill
(
white
)
#Draw food item
pygame
.
draw
.
rect
(
win
,
blue
,
(
location
[
0
],
location
[
1
],
size
1
,
size
1
))
pygame
.
draw
.
rect
(
win
,
blue
,
(
location
[
0
],
location
[
1
],
size
,
size
))
#Draw snake
pygame
.
draw
.
rect
(
win
,
red
,
(
x
,
y
,
size
,
size
))
...
...
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