Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
javaProj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Oscar Wiberg
javaProj
Commits
a7fef7c6
Commit
a7fef7c6
authored
5 months ago
by
Oscar Wiberg
Browse files
Options
Downloads
Patches
Plain Diff
bomb droppen fungerar
parent
b668950d
No related branches found
No related tags found
1 merge request
!2
Newmode
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/states/Bomb.java
+1
-1
1 addition, 1 deletion
src/states/Bomb.java
src/states/FlyingEnemy.java
+4
-0
4 additions, 0 deletions
src/states/FlyingEnemy.java
src/states/PlayState.java
+15
-23
15 additions, 23 deletions
src/states/PlayState.java
with
20 additions
and
24 deletions
src/states/Bomb.java
+
1
−
1
View file @
a7fef7c6
...
@@ -8,7 +8,7 @@ import javafx.scene.image.Image;
...
@@ -8,7 +8,7 @@ import javafx.scene.image.Image;
public
class
Bomb
{
public
class
Bomb
{
private
double
startX
;
private
double
startX
;
private
double
posY
=
10
0
;
private
double
posY
=
5
0
;
private
Image
image
;
private
Image
image
;
public
Bomb
(
double
bombDropX
,
String
bombImg
)
{
public
Bomb
(
double
bombDropX
,
String
bombImg
)
{
...
...
This diff is collapsed.
Click to expand it.
src/states/FlyingEnemy.java
+
4
−
0
View file @
a7fef7c6
...
@@ -48,6 +48,10 @@ public class FlyingEnemy extends Antagonist{
...
@@ -48,6 +48,10 @@ public class FlyingEnemy extends Antagonist{
return
null
;
return
null
;
}
}
public
void
resetBombDrop
()
{
bombDropped
=
false
;
}
@Override
@Override
public
boolean
playerAntagonistCollision
(
Player
player
)
{
public
boolean
playerAntagonistCollision
(
Player
player
)
{
...
...
This diff is collapsed.
Click to expand it.
src/states/PlayState.java
+
15
−
23
View file @
a7fef7c6
...
@@ -180,35 +180,26 @@ public class PlayState extends GameState {
...
@@ -180,35 +180,26 @@ public class PlayState extends GameState {
g
.
drawImage
(
flyingEnemy
.
getImage
(),
flyingEnemy
.
getX
(),
flyingEnemy
.
getY
(),
Constants
.
enemyWidth
,
Constants
.
enemyHeight
);
g
.
drawImage
(
flyingEnemy
.
getImage
(),
flyingEnemy
.
getX
(),
flyingEnemy
.
getY
(),
Constants
.
enemyWidth
,
Constants
.
enemyHeight
);
// If the flying enemy has passed the screen, drop a bomb (now always drops on the first pass)
if
(
flyingEnemy
.
getX
()
<
0
-
Constants
.
enemyWidth
)
{
flyingEnemy
.
setAntagonistX
(
Constants
.
screenWidth
);
// Reset the enemy's position
player
.
updatePasses
(
1
);
System
.
out
.
println
(
"Before dropBomb, bomb is: "
+
bomb
);
// Drop the bomb if it hasn't been dropped already
if
(
bomb
==
null
)
{
bomb
=
flyingEnemy
.
dropBomb
();
// Call the method in FlyingEnemy to drop the bomb
// System.out.println("Bomb dropped at X: " + bomb.getX() + ", Y: " + bomb.getY());
}
if
(
player
.
getPasses
()
%
5
==
0
)
{
if
(
flyingEnemy
.
getX
()
<
0
-
Constants
.
enemyWidth
)
{
movingSpeed
+=
2
;
flyingEnemy
.
setAntagonistX
(
Constants
.
screenWidth
);
// Reset the enemy's position
}
player
.
updatePasses
(
1
);
}
// Render the bomb if it exists
// Reset bomb drop flag to allow the next bomb drop
if
(
bomb
!=
null
)
{
flyingEnemy
.
resetBombDrop
();
g
.
drawImage
(
bomb
.
getImage
(),
bomb
.
getX
(),
bomb
.
getY
(),
Constants
.
bombWidth
,
Constants
.
bombHeight
);
if
(
player
.
getPasses
()
%
5
==
0
)
{
movingSpeed
+=
2
;
}
}
// Render the bomb if it exists
if
(
bomb
!=
null
)
{
g
.
drawImage
(
bomb
.
getImage
(),
bomb
.
getX
(),
bomb
.
getY
(),
Constants
.
bombWidth
,
Constants
.
bombHeight
);
}
}
}
}
...
@@ -284,6 +275,7 @@ public class PlayState extends GameState {
...
@@ -284,6 +275,7 @@ public class PlayState extends GameState {
// enemy.setAntagonistX(enemy.getX()-10);
// enemy.setAntagonistX(enemy.getX()-10);
// enemy.setAntagonistX(enemy.getX()-movingSpeed);
// enemy.setAntagonistX(enemy.getX()-movingSpeed);
flyingEnemy
.
setAntagonistX
(
flyingEnemy
.
getX
()
-
movingSpeed
);
flyingEnemy
.
setAntagonistX
(
flyingEnemy
.
getX
()
-
movingSpeed
);
Bomb
droppedBomb
=
flyingEnemy
.
dropBomb
();
Bomb
droppedBomb
=
flyingEnemy
.
dropBomb
();
if
(
droppedBomb
!=
null
)
{
if
(
droppedBomb
!=
null
)
{
...
...
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