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
3f3330ee
Commit
3f3330ee
authored
6 years ago
by
Hameed Andy
Browse files
Options
Downloads
Patches
Plain Diff
Game Window, Snake body & movement
parent
6dcf9cc9
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/POC_Demo/Snake_2.o_Demo.py
+70
-0
70 additions, 0 deletions
BlankProjectTemplate/POC_Demo/Snake_2.o_Demo.py
with
70 additions
and
0 deletions
BlankProjectTemplate/POC_Demo/Snake_2.o_Demo.py
0 → 100644
+
70
−
0
View file @
3f3330ee
#standard set up
import
pygame
pygame
.
init
()
#setting width and height of window
win
=
pygame
.
display
.
set_mode
((
500
,
500
))
pygame
.
display
.
set_caption
(
"
My Game
"
)
white
=
(
255
,
255
,
255
)
black
=
(
0
,
0
,
0
)
x
=
50
y
=
50
width
=
40
height
=
40
vel
=
10
speed
=
40
# 0 - (- direction) , 1 - (+ direction)
direction
=
0
# 0 - x-axis , 1 - y-axis
axis
=
0
run
=
True
def
changeXY
(
x
,
y
,
axis
,
direction
):
if
not
(
axis
):
x
+=
vel
*
direction
## else:
## y += vel*direction
while
run
:
pygame
.
time
.
delay
(
speed
)
#create a delay to prevent any unwanted behaviour
#events are anything that happens from the user
#we loop through the list of events that happen by the user's actions
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
pygame
.
QUIT
:
run
=
False
#Each event type has an integer assigned to it. KEYDOWN has the code 2
if
event
.
type
==
pygame
.
KEYDOWN
:
if
(
event
.
key
==
pygame
.
K_LEFT
):
axis
=
0
;
direction
=-
1
if
(
event
.
key
==
pygame
.
K_RIGHT
):
axis
=
0
;
direction
=
1
if
(
event
.
key
==
pygame
.
K_UP
):
axis
=
1
;
direction
=-
1
if
(
event
.
key
==
pygame
.
K_DOWN
):
axis
=
1
;
direction
=
1
#Snake moving depending on axis and direction
if
(
axis
):
y
+=
vel
*
direction
else
:
x
+=
vel
*
direction
win
.
fill
(
white
)
#all colors are defined in RGB with Pygame
pygame
.
draw
.
rect
(
win
,(
255
,
0
,
0
),
(
x
,
y
,
width
,
height
))
#we have to update the display to see the drawing of our object. Since it does
#not automatically update
pygame
.
display
.
update
()
#Quit the game
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