Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GamesDevGame
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
christopher.spray
GamesDevGame
Commits
61e871d8
Commit
61e871d8
authored
Apr 30, 2020
by
christopher.spray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FINAL final push
parent
a94fec03
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
56 deletions
+35
-56
bandit.cpython-36.pyc
__pycache__/bandit.cpython-36.pyc
+0
-0
observer.cpython-36.pyc
__pycache__/observer.cpython-36.pyc
+0
-0
bandit.py
bandit.py
+0
-3
game.py
game.py
+29
-50
observer.py
observer.py
+6
-3
No files found.
__pycache__/bandit.cpython-36.pyc
View file @
61e871d8
No preview for this file type
__pycache__/observer.cpython-36.pyc
View file @
61e871d8
No preview for this file type
bandit.py
View file @
61e871d8
...
...
@@ -17,8 +17,6 @@ class Bandit(pygame.sprite.Sprite):
self
.
image
.
set_colorkey
(
WHITE
)
#set transparency to white
self
.
rect
=
self
.
image
.
get_rect
()
#get the rect for the img
self
.
rect
.
center
=
(
window_height
/
2
,
window_width
/
2
)
#place in center of screen
#self.rect.y = randint(0, window_height-self.rect.width)
#self.rect.x = randint(0, window_height-self.rect.width)
self
.
speed
=
speedAI
self
.
playerRef
=
player
self
.
observer
=
observer
...
...
@@ -66,7 +64,6 @@ class Bandit(pygame.sprite.Sprite):
if
totalDiff
<
self
.
rect
.
width
and
otherBandit
.
playerDist
()
<
self
.
playerDist
():
self
.
stopped
=
True
self
.
stoppedTimer
=
time
.
time
()
print
(
"STOPPED"
)
if
self
.
stopped
and
time
.
time
()
>
self
.
stoppedTimer
+
self
.
stopWaitLength
:
self
.
stopped
=
False
...
...
game.py
View file @
61e871d8
...
...
@@ -28,9 +28,11 @@ rightPressed = False
bulletFired
=
False
bulletFiredTime
=
0
bulletFireRate
=
0.333
gameWon
=
False
gameLost
=
False
#
pygame.mixer.music.load('music.mp3')
#
pygame.mixer.music.play(-1)
pygame
.
mixer
.
music
.
load
(
'music.mp3'
)
pygame
.
mixer
.
music
.
play
(
-
1
)
pygame
.
display
.
set_caption
(
"Cowboy Shooter"
)
screenSize
=
(
window_width
,
window_height
)
...
...
@@ -71,29 +73,9 @@ spriteGroupWall.add(wallBotRightVer)
player
=
Cowboy
(
window_width
,
window_height
,
speed
)
observer
=
ai_observer
(
maxBandits
)
#bandit1 = Bandit(player, window_height, window_width, speedAI)
enemiesOnScreen
=
0
#for i in range (maxBandits):
# if(enemiesOnScreen <5):
# enemiesOnScreen += 1
# b = Bandit(player, window_height, window_width, speedAI, observer,spriteGroupAI)
# spriteGroupAI.add(b)
# else:
spriteGroup
.
add
(
player
)
#-------------------------------------------------------------
#BULLETS
#-------------------------------------------------------------
upCollide
=
False
downCollide
=
False
leftCollide
=
False
...
...
@@ -187,12 +169,16 @@ while run is True:
if
time
.
time
()
>
bulletFiredTime
+
bulletFireRate
:
bulletFired
=
False
if
(
enemiesOnScreen
<
5
):
enemiesOnScreen
+=
1
b
=
Bandit
(
player
,
window_height
,
window_width
,
speedAI
,
observer
,
spriteGroupAI
,
spriteGroupWall
,
enemiesOnScreen
)
spriteGroupAI
.
add
(
b
)
else
:
pass
;
if
not
observer
.
gameWon
and
not
gameLost
:
if
(
enemiesOnScreen
<
5
):
enemiesOnScreen
+=
1
b
=
Bandit
(
player
,
window_height
,
window_width
,
speedAI
,
observer
,
spriteGroupAI
,
spriteGroupWall
,
enemiesOnScreen
)
spriteGroupAI
.
add
(
b
)
else
:
pass
;
elif
enemiesOnScreen
<=
0
and
not
gameLost
:
winText
=
font
.
render
(
"GAME WON"
,
True
,
(
0
,
0
,
0
))
screen
.
blit
(
winText
,
(
350
,
350
))
#-------------------------------------------------------------
#COLLISIONS
...
...
@@ -204,7 +190,8 @@ while run is True:
observer
.
notify_enemy_died
()
enemiesOnScreen
-=
1
if
(
player
.
health
<=
0
):
run
=
False
gameLost
=
True
#run = False
for
b
in
spriteGroupAI
:
...
...
@@ -213,23 +200,6 @@ while run is True:
b
.
kill
()
enemiesOnScreen
-=
1
#Checking if player hits wall
# playerHitWall = pygame.sprite.spritecollide(player, spriteGroupWall, False) #if player collides with any wall
# if playerHitWall:
# if wPressed:
# upCollide = True
# elif aPressed:
# leftCollide = True
# elif sPressed:
# downCollide = True
# elif dPressed:
# rightCollide = True
# else:
# upCollide = False
# leftCollide = False
# downCollide = False
# rightCollide = False
#checking if bullets hit the bandits
bulletHitBandit
=
pygame
.
sprite
.
groupcollide
(
spriteGroupBullet
,
spriteGroupAI
,
True
,
True
)
if
bulletHitBandit
:
...
...
@@ -248,17 +218,26 @@ while run is True:
healthText
=
font
.
render
(
"Health: x"
+
str
(
player
.
health
),
True
,
(
0
,
0
,
0
))
#-------------------------------------------------------------
spriteGroup
.
update
(
window_width
,
window_height
)
#calls all the update functions in all sprites
spriteGroupAI
.
update
()
spriteGroupWall
.
update
()
spriteGroupBullet
.
update
()
spriteGroup
.
draw
(
screen
)
spriteGroupAI
.
draw
(
screen
)
if
not
gameLost
:
spriteGroup
.
update
(
window_width
,
window_height
)
#calls all the update functions in all sprites
spriteGroupAI
.
update
()
spriteGroup
.
draw
(
screen
)
spriteGroupAI
.
draw
(
screen
)
spriteGroupWall
.
draw
(
screen
)
spriteGroupBullet
.
draw
(
screen
)
screen
.
blit
(
enemiesLeftText
,
(
5
,
5
))
screen
.
blit
(
healthText
,
(
575
,
3
))
if
gameLost
:
lostText
=
font
.
render
(
"YOU LOSE"
,
True
,
(
0
,
0
,
0
))
screen
.
blit
(
lostText
,
(
350
,
350
))
pygame
.
display
.
flip
()
observer.py
View file @
61e871d8
...
...
@@ -4,10 +4,13 @@ class ai_observer():
def
__init__
(
self
,
maxBandits
):
self
.
enemiesRemaining
=
maxBandits
self
.
gameWon
=
False
def
notify_enemy_died
(
self
):
self
.
enemiesRemaining
-=
1
print
(
"enemies remaining:"
,
self
.
enemiesRemaining
)
if
self
.
enemiesRemaining
<=
0
:
game
.
run
==
False
self
.
gameWon
=
True
else
:
self
.
enemiesRemaining
-=
1
print
(
"enemies remaining:"
,
self
.
enemiesRemaining
)
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