Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
FP Asteroids
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Edwin
FP Asteroids
Compare revisions
a899887ffd5ba40ec5c7636f2ac2eeb06a7dee3b to b378de7df41a7513e2bea086a33d3f7ee7cf7bec
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
9562850/fp-asteroids
Select target project
No results found
b378de7df41a7513e2bea086a33d3f7ee7cf7bec
Select Git revision
Branches
main
meteor
Swap
Target
9562850/fp-asteroids
Select target project
9562850/fp-asteroids
1 result
a899887ffd5ba40ec5c7636f2ac2eeb06a7dee3b
Select Git revision
Branches
main
meteor
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (3)
bullets destroy meteors and give score
· 65cadab9
Boris
authored
4 months ago
65cadab9
Merge branch 'main' of
https://git.science.uu.nl/9562850/fp-asteroids
· 140bbe68
Boris
authored
4 months ago
140bbe68
small error fixed
· b378de7d
Boris
authored
4 months ago
b378de7d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Controller.hs
+29
-2
29 additions, 2 deletions
src/Controller.hs
src/Model.hs
+1
-1
1 addition, 1 deletion
src/Model.hs
src/highscores.txt
+1
-0
1 addition, 0 deletions
src/highscores.txt
with
31 additions
and
3 deletions
src/Controller.hs
View file @
b378de7d
...
...
@@ -16,8 +16,8 @@ step secs gstate@(GameState{screen = MainMenu}) = do -- retrieve highscores
scores
<-
highscoresFromFile
return
gstate
{
highscores
=
scores
}
step
secs
gstate
=
-- Normal tick
checkDeath
$
checkPowerupCollision
$
applyKeys
$
tickNotification
$
tickPowerup
$
tickMeteors
secs
$
tick
secs
gstate
=
-- Normal tick
checkDeath
$
checkPowerupCollision
$
applyKeys
$
tickNotification
$
tickPowerup
$
tickMeteors
secs
$
checkBulletCollision
$
tick
secs
gstate
-- Handle all the logic not directly influenced by the user
tick
::
Float
->
GameState
->
GameState
...
...
@@ -305,6 +305,33 @@ updateBullet secs (Bullet (x,y) angle speed) = do
let
(
rx
,
ry
)
=
(
cos
angle
,
sin
angle
)
let
(
x'
,
y'
)
=
(
x
+
secs
*
speed
*
rx
,
y
+
secs
*
speed
*
ry
)
Bullet
(
x'
,
y'
)
angle
speed
-- Function to get the collision radius based on meteor size
collisionRadius
::
Int
->
Float
collisionRadius
size
=
case
size
of
1
->
20
2
->
40
3
->
60
_
->
20
-- Default case, assuming size 1 if size is not 1, 2, or 3
checkBulletCollision
::
GameState
->
GameState
checkBulletCollision
gstate
@
(
GameState
{
spaceShip
,
meteors
,
player
})
=
let
shipBullets
=
bullets
spaceShip
playerScore
=
score
player
(
newMeteors
,
remainingBullets
,
newScore
)
=
foldl
handleCollision
(
[]
,
shipBullets
,
playerScore
)
meteors
in
gstate
{
meteors
=
newMeteors
,
spaceShip
=
spaceShip
{
bullets
=
remainingBullets
},
player
=
(
player
{
score
=
newScore
})
}
handleCollision
::
([
Meteor
],
[
Bullet
],
Score
)
->
Meteor
->
([
Meteor
],
[
Bullet
],
Score
)
handleCollision
(
remainingMeteors
,
remainingBullets
,
score
)
meteor
=
let
(
collidedBullets
,
nonCollidedBullets
)
=
partition
(
\
(
Bullet
loc
_
_
)
->
collidesWith
(
collisionRadius
(
size
meteor
))
loc
(
coordinates
meteor
))
remainingBullets
in
if
null
collidedBullets
then
(
meteor
:
remainingMeteors
,
remainingBullets
,
score
)
else
case
size
meteor
of
1
->
(
remainingMeteors
,
nonCollidedBullets
,
score
+
100
)
2
->
(
meteor
{
size
=
size
meteor
-
1
}
:
remainingMeteors
,
nonCollidedBullets
,
score
+
50
)
3
->
(
meteor
{
size
=
size
meteor
-
1
}
:
remainingMeteors
,
nonCollidedBullets
,
score
+
20
)
anyBulletCollides
::
[
Bullet
]
->
Meteor
->
Bool
anyBulletCollides
bullets
meteor
=
any
(
\
(
Bullet
loc
_
_
)
->
collidesWith
(
collisionRadius
(
size
meteor
))
loc
(
coordinates
meteor
))
bullets
translateMeteor
::
Float
->
Meteor
->
Meteor
translateMeteor
secs
(
Meteor
(
x
,
y
)
angle
speed
lives
)
=
do
...
...
This diff is collapsed.
Click to expand it.
src/Model.hs
View file @
b378de7d
...
...
@@ -30,7 +30,7 @@ data Specifications = Specs {
}
type
Size
=
Int
data
Meteor
=
Meteor
Location
Orientation
Velocity
Size
data
Meteor
=
Meteor
{
coordinates
::
Location
,
directoin
::
Orientation
,
pace
::
Velocity
,
size
::
Size
}
data
UFO
=
UFO
Location
Orientation
Velocity
Bullet
type
Score
=
Int
type
Name
=
String
...
...
This diff is collapsed.
Click to expand it.
src/highscores.txt
View file @
b378de7d
("Player", 410)
("Player", 10)
("Gerda", 9)
("Billy", 2)
This diff is collapsed.
Click to expand it.