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
3464ea4f
Commit
3464ea4f
authored
1 year ago
by
Oscar Wiberg
Browse files
Options
Downloads
Patches
Plain Diff
Jump flyttad till player + cleanup
parent
5b0b4bf1
No related branches found
No related tags found
1 merge request
!1
Testb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/states/PlayState.java
+7
-68
7 additions, 68 deletions
src/states/PlayState.java
src/states/Player.java
+29
-24
29 additions, 24 deletions
src/states/Player.java
with
36 additions
and
92 deletions
src/states/PlayState.java
+
7
−
68
View file @
3464ea4f
package
states
;
import
testing.Tester
;
import
testing.Tester.Point
;
import
javafx.scene.canvas.GraphicsContext
;
import
javafx.scene.image.Image
;
import
javafx.scene.image.ImageView
;
import
javafx.scene.input.KeyCode
;
import
javafx.scene.input.KeyEvent
;
import
javafx.scene.paint.Color
;
import
javafx.scene.shape.Line
;
import
javafx.scene.text.Font
;
import
java.io.BufferedInputStream
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
...
...
@@ -43,14 +37,10 @@ public class PlayState extends GameState {
private
String
informationText
;
private
Color
bgColor
;
private
Color
fontColor
;
private
Double
playerPosX
=
Constants
.
screenWidth
/
2
-
(
Constants
.
playerWidth
/
2
);
private
Double
playerPosY
=
265.00
;
// private Image player;
private
Image
obstacle
;
private
Double
enemyPosX
=
-
100.00
;
private
Double
enemyPosY
=
250.00
;
private
boolean
up
=
false
;
private
boolean
down
=
false
;
private
Player
player
;
...
...
@@ -106,15 +96,8 @@ public class PlayState extends GameState {
model
.
switchState
(
new
MenuState
(
model
));
}
else
if
(
key
.
getCode
()
==
KeyCode
.
UP
)
{
// if (player.getPlayerY() != 265.00) {
// return;
// }
up
=
true
;
}
...
...
@@ -125,59 +108,15 @@ public class PlayState extends GameState {
enemyPosX
-=
10
;
if
(
up
)
{
player
.
moveUp
();
player
.
jump
();
}
// 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;
//
// }
//
// }
if
(
player
.
getPlayerY
()
==
265
)
{
up
=
false
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/states/Player.java
+
29
−
24
View file @
3464ea4f
package
states
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
constants.Constants
;
import
javafx.scene.image.Image
;
import
javafx.scene.image.ImageView
;
import
javafx.scene.input.KeyCode
;
import
javafx.scene.input.KeyEvent
;
public
class
Player
{
...
...
@@ -16,6 +17,7 @@ public class Player {
private
int
lives
=
3
;
private
Image
image
;
private
boolean
down
=
false
;
private
boolean
up
=
false
;
public
Player
(
String
playerImg
)
{
...
...
@@ -53,22 +55,32 @@ public class Player {
return
playerY
;
}
public
void
moveUp
()
{
// if (playerY > 110) {
playerY
-=
10
;
if
(
playerY
<=
110
)
{
down
=
true
;
}
// }
public
void
move
(
KeyEvent
key
)
{
if
(
key
.
getCode
()
==
KeyCode
.
UP
)
{
this
.
jump
();
up
=
true
;
}
}
public
void
jump
()
{
if
(!
down
)
{
playerY
-=
10
;
if
(
playerY
<=
110
)
{
down
=
true
;
}
}
if
(
down
)
{
playerY
+=
10
;
...
...
@@ -79,8 +91,8 @@ public class Player {
}
}
public
void
setPlayerX
(
double
playerX
)
{
this
.
playerX
=
playerX
;
...
...
@@ -92,11 +104,4 @@ public class Player {
}
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