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
5b0b4bf1
Commit
5b0b4bf1
authored
1 year ago
by
Oscar Wiberg
Browse files
Options
Downloads
Patches
Plain Diff
Försöker flytta över player move logik från playstate till player
parent
f4524412
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1
Testb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/states/PlayState.java
+54
-42
54 additions, 42 deletions
src/states/PlayState.java
src/states/Player.java
+43
-15
43 additions, 15 deletions
src/states/Player.java
with
97 additions
and
57 deletions
src/states/PlayState.java
+
54
−
42
View file @
5b0b4bf1
...
@@ -45,7 +45,7 @@ public class PlayState extends GameState {
...
@@ -45,7 +45,7 @@ public class PlayState extends GameState {
private
Color
fontColor
;
private
Color
fontColor
;
private
Double
playerPosX
=
Constants
.
screenWidth
/
2
-
(
Constants
.
playerWidth
/
2
);
private
Double
playerPosX
=
Constants
.
screenWidth
/
2
-
(
Constants
.
playerWidth
/
2
);
private
Double
playerPosY
=
265.00
;
private
Double
playerPosY
=
265.00
;
// private Image player;
// private Image player;
private
Image
obstacle
;
private
Image
obstacle
;
private
Double
enemyPosX
=
-
100.00
;
private
Double
enemyPosX
=
-
100.00
;
private
Double
enemyPosY
=
250.00
;
private
Double
enemyPosY
=
250.00
;
...
@@ -62,9 +62,9 @@ public class PlayState extends GameState {
...
@@ -62,9 +62,9 @@ public class PlayState extends GameState {
informationText
=
"Press Escape To Return To The Menu"
;
informationText
=
"Press Escape To Return To The Menu"
;
bgColor
=
Color
.
BEIGE
;
bgColor
=
Color
.
BEIGE
;
fontColor
=
Color
.
BLUE
;
fontColor
=
Color
.
BLUE
;
player
=
new
Player
(
Constants
.
playerImg
);
player
=
new
Player
(
Constants
.
playerImg
);
try
{
try
{
obstacle
=
new
Image
(
new
FileInputStream
(
Constants
.
enemyImg
));
obstacle
=
new
Image
(
new
FileInputStream
(
Constants
.
enemyImg
));
}
catch
(
FileNotFoundException
e
)
{
}
catch
(
FileNotFoundException
e
)
{
...
@@ -107,13 +107,13 @@ public class PlayState extends GameState {
...
@@ -107,13 +107,13 @@ public class PlayState extends GameState {
model
.
switchState
(
new
MenuState
(
model
));
model
.
switchState
(
new
MenuState
(
model
));
}
else
if
(
key
.
getCode
()
==
KeyCode
.
UP
)
{
}
else
if
(
key
.
getCode
()
==
KeyCode
.
UP
)
{
if
(
player
.
getPlayerY
()
!=
265.00
)
{
//
if (player.getPlayerY() != 265.00) {
return
;
//
return;
}
//
}
up
=
true
;
up
=
true
;
}
}
...
@@ -125,50 +125,62 @@ public class PlayState extends GameState {
...
@@ -125,50 +125,62 @@ public class PlayState extends GameState {
enemyPosX
-=
10
;
enemyPosX
-=
10
;
// if (up) {
//
// playerPosY -= 10;
//
// if (playerPosY <= 110) {
//
// up = false;
// down = true;
//
// }
//
// } else if (down) {
//
// playerPosY += 10;
//
// if (playerPosY == 265) {
//
// down = false;
//
// }
//
// }
if
(
up
)
{
player
.
moveUp
();
}
else
if
(
down
)
{
if
(
up
)
{
playerPosY
+=
10
;
if
(
player
PosY
==
265
)
{
player
.
moveUp
();
down
=
false
;
}
}
}
// if (up) {
//
//// up = false;
//
//
// player.setPlayerY(player.getPlayerY()-10);
//
// if (player.getPlayerY() <= 110) {
//
// up = false;
// down = true;
//
// }
//
// } else if (down) {
//
// playerPosY += 10;
// player.setPlayerY(player.getPlayerY()+10);
//
// if (player.getPlayerY() == 265) {
//
// down = false;
//
// }
//
// }
// if (up) {
//
// player.move();
//
//
// } else if (down) {
//
// playerPosY += 10;
//
// if (playerPosY == 265) {
//
// down = false;
//
// }
//
// }
}
}
// Here one would probably instead move the player and any
// Here one would probably instead move the player and any
// enemies / moving obstacles currently active.
// enemies / moving obstacles currently active.
...
...
This diff is collapsed.
Click to expand it.
src/states/Player.java
+
43
−
15
View file @
5b0b4bf1
...
@@ -9,14 +9,15 @@ import javafx.scene.image.ImageView;
...
@@ -9,14 +9,15 @@ import javafx.scene.image.ImageView;
import
javafx.scene.input.KeyCode
;
import
javafx.scene.input.KeyCode
;
public
class
Player
{
public
class
Player
{
private
double
playerX
=
(
Constants
.
screenWidth
-
Constants
.
playerWidth
)
/
2
;
private
double
playerX
=
(
Constants
.
screenWidth
-
Constants
.
playerWidth
)
/
2
;
private
double
playerY
=
265.00
;
private
double
playerY
=
265.00
;
private
int
score
=
0
;
private
int
score
=
0
;
private
int
lives
=
3
;
private
int
lives
=
3
;
private
Image
image
;
private
Image
image
;
private
boolean
down
=
false
;
public
Player
(
String
playerImg
)
{
public
Player
(
String
playerImg
)
{
try
{
try
{
...
@@ -53,22 +54,49 @@ public class Player {
...
@@ -53,22 +54,49 @@ public class Player {
}
}
public
void
moveUp
()
{
public
void
moveUp
()
{
playerY
-=
10
;
if
(
playerY
<=
110
)
{
return
;
// if (playerY > 110) {
// up = false;
// down = true;
playerY
-=
10
;
if
(
playerY
<=
110
)
{
down
=
true
;
}
// }
if
(
down
)
{
playerY
+=
10
;
if
(
playerY
==
265
)
{
down
=
false
;
}
}
}
}
public
void
setPlayerX
(
double
playerX
)
{
this
.
playerX
=
playerX
;
}
}
public
void
moveDown
()
{
public
void
setPlayerY
(
double
playerY
)
{
this
.
playerY
=
playerY
;
}
}
public
boolean
moveDown
(
boolean
down
)
{
return
down
;
}
}
}
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