Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
citius-invaders
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomás Teijeiro Campo
citius-invaders
Commits
0cdeb9aa
Commit
0cdeb9aa
authored
May 18, 2016
by
Tomás Teijeiro Campo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented Game Over functionality
parent
a2a89ad6
Pipeline
#651
skipped
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
6 deletions
+8
-6
game.py
game.py
+7
-5
objects.py
objects.py
+1
-1
No files found.
game.py
View file @
0cdeb9aa
...
...
@@ -53,6 +53,7 @@ class InvadersGame(sge.dsp.Game):
self
.
score
=
0
self
.
anim_sleep
=
None
self
.
last_gen
=
0
self
.
game_over
=
False
self
.
clock
=
Clock
()
def
show_hud
(
self
):
...
...
@@ -63,7 +64,7 @@ class InvadersGame(sge.dsp.Game):
self
.
current_room
.
objects
if
isinstance
(
o
,
objects
.
Invader
))
self
.
project_text
(
self
.
hud_font
,
hud_string
.
format
(
self
.
score
,
num_invaders
,
fps
),
5
,
5
,
anti_alias
=
False
)
if
num_invaders
>=
MAX_NINV
:
if
self
.
game_over
:
self
.
project_text
(
sge
.
gfx
.
Font
(
'minecraftia.ttf'
,
size
=
70
),
'Game
\n
Over'
,
RESX
/
2
,
RESY
/
2
-
140
,
halign
=
'center'
,
valign
=
'center'
)
...
...
@@ -87,7 +88,9 @@ class InvadersGame(sge.dsp.Game):
num_invaders
=
sum
(
1
for
o
in
self
.
current_room
.
objects
if
isinstance
(
o
,
objects
.
Invader
))
self
.
show_hud
()
self
.
last_gen
+=
time_passed
self
.
game_over
=
num_invaders
>=
MAX_NINV
if
not
self
.
game_over
:
self
.
last_gen
+=
time_passed
if
self
.
last_gen
>=
GENERATION_TIME
:
self
.
new_generation
()
elif
num_invaders
<=
MIN_NINV
:
...
...
@@ -100,12 +103,12 @@ class InvadersGame(sge.dsp.Game):
def
event_key_press
(
self
,
key
,
char
):
if
key
==
'f8'
:
sge
.
gfx
.
Sprite
.
from_screenshot
().
save
(
'screenshot
.jpg'
)
sge
.
gfx
.
Sprite
.
from_screenshot
().
save
(
time
.
strftime
(
'%Y-%m-%d_%H%M%S'
)
+
'
.jpg'
)
elif
key
==
'f11'
:
self
.
fullscreen
=
not
self
.
fullscreen
elif
key
==
'escape'
:
self
.
event_close
()
elif
key
in
(
'p'
,
'enter'
):
elif
not
self
.
game_over
and
key
in
(
'p'
,
'enter'
):
self
.
pause
()
def
event_close
(
self
):
...
...
@@ -113,7 +116,6 @@ class InvadersGame(sge.dsp.Game):
def
event_paused_step
(
self
,
time_passed
,
delta_mult
):
self
.
show_hud
()
if
self
.
pairs
:
#Draw the next cross operation
i1
,
i2
=
self
.
pairs
.
pop
()
...
...
objects.py
View file @
0cdeb9aa
...
...
@@ -147,7 +147,7 @@ class Player(sge.dsp.Object):
def
event_key_press
(
self
,
key
,
char
):
#Shooting
if
key
==
'space'
:
if
not
sge
.
game
.
game_over
and
key
==
'space'
:
#The number of invaders must be higher than the minimum allowed,
#and the number of bullets lower than the maximum
ninvaders
=
sum
(
1
for
o
in
sge
.
game
.
current_room
.
objects
...
...
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