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
c1f94e23
Commit
c1f94e23
authored
1 year ago
by
Oscar Wiberg
Browse files
Options
Downloads
Patches
Plain Diff
skickas till meny när spelarens liv är slut
parent
db23ebc3
No related branches found
No related tags found
1 merge request
!1
Testb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/constants/Constants.java
+2
-2
2 additions, 2 deletions
src/constants/Constants.java
src/main/Main.java
+3
-1
3 additions, 1 deletion
src/main/Main.java
src/states/PlayState.java
+16
-5
16 additions, 5 deletions
src/states/PlayState.java
src/states/Player.java
+2
-2
2 additions, 2 deletions
src/states/Player.java
with
23 additions
and
10 deletions
src/constants/Constants.java
+
2
−
2
View file @
c1f94e23
...
...
@@ -21,8 +21,8 @@ public interface Constants {
/*
* Define the size of the window
*/
final
double
screenWidth
=
1000
;
final
double
screenHeight
=
500
;
final
int
screenWidth
=
1000
;
final
int
screenHeight
=
500
;
// Player
...
...
This diff is collapsed.
Click to expand it.
src/main/Main.java
+
3
−
1
View file @
c1f94e23
...
...
@@ -50,7 +50,9 @@ public class Main extends Application {
gameStage
.
setWidth
(
Constants
.
screenWidth
);
gameStage
.
setHeight
(
Constants
.
screenHeight
);
GameModel
model
=
new
GameModel
();
GameFrame
frame
=
new
GameFrame
(
model
,
1000
,
800
);
// GameFrame frame = new GameFrame(model, 1000, 800);
GameFrame
frame
=
new
GameFrame
(
model
,
Constants
.
screenWidth
,
Constants
.
screenHeight
);
Scene
gameScene
=
new
Scene
(
frame
);
final
double
targetFps
=
50.0
;
// Calculate frequency in nano seconds
...
...
This diff is collapsed.
Click to expand it.
src/states/PlayState.java
+
16
−
5
View file @
c1f94e23
...
...
@@ -6,6 +6,7 @@ import javafx.scene.input.KeyCode;
import
javafx.scene.input.KeyEvent
;
import
javafx.scene.paint.Color
;
import
javafx.scene.text.Font
;
import
javafx.scene.text.Text
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
...
...
@@ -35,12 +36,14 @@ public class PlayState extends GameState {
* a way to make this more general and not duplicate variables?
*/
private
String
informationText
;
private
String
livesleft
;
private
Color
bgColor
;
private
Color
fontColor
;
private
boolean
up
=
false
;
private
Player
player
;
private
Enemy
enemy
;
private
boolean
collided
=
false
;
private
MenuState
menu
;
/* Class only used for testing */
...
...
@@ -48,12 +51,15 @@ public class PlayState extends GameState {
public
PlayState
(
GameModel
model
)
{
super
(
model
);
informationText
=
"Press Escape To Return To The Menu"
;
informationText
=
"Press Escape \nTo Return To The Menu"
;
livesleft
=
"Lives left: "
;
bgColor
=
Color
.
BEIGE
;
fontColor
=
Color
.
BLUE
;
player
=
new
Player
(
Constants
.
playerImg
);
enemy
=
new
Enemy
(
Constants
.
enemyImg
);
// menu = new MenuState(model);
}
...
...
@@ -66,13 +72,14 @@ public class PlayState extends GameState {
g
.
setFill
(
fontColor
);
g
.
setFont
(
new
Font
(
30
));
// Big letters
g
.
fillText
(
informationText
,
Constants
.
screenWidth
/
3
,
Constants
.
screenHeight
/
3
);
g
.
fillText
(
livesleft
+
player
.
getLives
(),
0
,
30
);
g
.
fillText
(
informationText
,
Constants
.
screenWidth
-
300
,
30
);
g
.
setStroke
(
Color
.
BLACK
);
g
.
setLineWidth
(
1
);
g
.
setLineDashes
(
2
);
g
.
strokeLine
(
Constants
.
screenWidth
,
350
,
0
,
350
);
if
(
enemy
.
getEnemyX
()
<
0
-
Constants
.
enemyWidth
)
{
enemy
.
setEnemyX
(
Constants
.
screenWidth
);
}
...
...
@@ -145,9 +152,13 @@ public class PlayState extends GameState {
// // System.out.println("helo");
if
((
player
.
getPlayerY
()
+
60
)
>=
enemy
.
getEnemyY
()
)
{
collided
=
true
;
System
.
out
.
println
(
"fäk"
);
// System.out.println("fäk");
if
(
Integer
.
valueOf
(
player
.
getLives
())
==
0
)
{
menu
=
new
MenuState
(
model
);
model
.
switchState
(
menu
);
}
player
.
decreaseLives
();
System
.
out
.
println
(
player
.
getLives
());
//
System.out.println(player.getLives());
}
// System.out.println("slipped by enemy");
...
...
This diff is collapsed.
Click to expand it.
src/states/Player.java
+
2
−
2
View file @
c1f94e23
...
...
@@ -52,8 +52,8 @@ public class Player {
}
public
in
t
getLives
()
{
return
this
.
lives
;
public
Str
in
g
getLives
()
{
return
Integer
.
toString
(
this
.
lives
)
;
}
...
...
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