Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
MG_Projects
jetpackjoyride
Commits
22c7f99b
Commit
22c7f99b
authored
Apr 27, 2019
by
Melissa Tjong
Browse files
.
parent
aa615bfa
Changes
12
Hide whitespace changes
Inline
Side-by-side
src/entities/Obstacle.java
View file @
22c7f99b
...
...
@@ -29,8 +29,11 @@ import project.Level1;
*/
public
class
Obstacle
extends
Entity
{
public
Obstacle
()
{
private
float
speed
;
public
Obstacle
(
float
s
)
{
super
();
this
.
speed
=
s
;
}
@Override
...
...
@@ -50,9 +53,10 @@ public class Obstacle extends Entity {
}
@Override
public
void
update
(
GameContainer
gc
,
int
delta
)
{
if
(
this
.
getEndX
()
>
0
)
{
x
-=
1
;
x
-=
speed
;
}
}
...
...
src/entities/Player.java
View file @
22c7f99b
...
...
@@ -37,6 +37,9 @@ public class Player extends Entity {
private
Image
risingImage
=
null
;
private
Image
fallingImage
=
null
;
private
boolean
isRising
=
false
;
private
boolean
isFalling
=
false
;
public
Player
()
{
super
();
}
...
...
@@ -57,20 +60,32 @@ public class Player extends Entity {
@Override
public
void
render
(
GameContainer
gc
,
Graphics
g
)
{
if
(!
isRising
&&
!
isFalling
)
{
this
.
getAnimation
().
draw
(
x
,
y
);
}
else
if
(
isRising
)
{
this
.
getRisingImage
().
draw
(
x
,
y
);
}
else
if
(
isFalling
)
{
this
.
getFallingImage
().
draw
(
x
,
y
);
}
}
public
void
update
(
GameContainer
gc
,
int
delta
)
{
Input
input
=
gc
.
getInput
();
if
(
input
.
isKeyDown
(
Input
.
KEY_SPACE
))
{
y
-=
0.75
;
isRising
=
true
;
}
else
{
y
+=
0.75
;
isRising
=
false
;
isFalling
=
true
;
}
if
(
y
>
HEIGHT
-
height
)
{
y
=
HEIGHT
-
(
height
);
isFalling
=
false
;
}
if
(
y
<
0
)
{
y
=
0
;
...
...
@@ -82,7 +97,7 @@ public class Player extends Entity {
public
void
init
()
{
width
=
100
;
height
=
100
;
x
=
Level1
.
WIDTH
/
2
;
x
=
Level1
.
WIDTH
/
6
;
y
=
(
float
)
(
Level1
.
HEIGHT
-
height
);
try
{
if
(
image
==
null
&&
!
sprite
)
{
...
...
src/project/GameOver.java
View file @
22c7f99b
...
...
@@ -65,6 +65,7 @@ public class GameOver extends BasicGameState {
if
(
input
.
isMousePressed
(
0
))
{
loseMusic
.
stop
();
game
.
getState
(
Main
.
MAINMENU
).
init
(
container
,
game
);
game
.
enterState
(
Main
.
MAINMENU
);
}
if
(!
loseMusic
.
playing
())
{
...
...
src/project/GameWin.java
View file @
22c7f99b
...
...
@@ -69,7 +69,7 @@ public class GameWin extends BasicGameState {
if
(
input
.
isMousePressed
(
0
))
{
winMusic
.
stop
();
game
.
enterState
(
Main
.
LOSE
);
game
.
enterState
(
Main
.
MAINMENU
);
}
if
(!
winMusic
.
playing
())
{
...
...
src/project/Level.java
View file @
22c7f99b
...
...
@@ -58,7 +58,7 @@ public abstract class Level extends BasicGameState {
public
static
int
pointCounter
;
private
String
meters
=
"M"
;
p
rivate
int
topScore
;
p
ublic
int
topScore
;
private
boolean
isRising
=
false
;
private
boolean
isFalling
=
false
;
...
...
src/project/Level1.java
View file @
22c7f99b
...
...
@@ -55,8 +55,8 @@ public class Level1 extends Level {
private
static
int
char_Width
=
100
;
private
static
int
char_Height
=
100
;
private
static
float
backgroundX2
=
(
float
)
WIDTH
;
private
static
float
backgroundX
=
(
float
)
0.0
;
private
static
float
backgroundX2
;
private
static
float
backgroundX
;
private
static
float
dX
=
(
float
)
1
;
private
String
meters
=
"M"
;
...
...
@@ -65,13 +65,14 @@ public class Level1 extends Level {
private
boolean
isRising
=
false
;
private
boolean
isFalling
=
false
;
Animation
backgroundAnimation
;
ArrayList
<
Laser
>
lasers
;
Laser
laser
;
Font
font
;
TrueTypeFont
ttf
;
private
static
final
int
spawnInterval
=
1000
;
private
static
final
int
spawnInterval
=
levelLength
/
5
;
public
int
getTopScore
()
{
return
topScore
;
...
...
@@ -94,6 +95,9 @@ public class Level1 extends Level {
container
.
setSmoothDeltas
(
true
);
pointCounter
=
0
;
backgroundX2
=
(
float
)
WIDTH
;
backgroundX
=
(
float
)
0.0
;
Image
city
=
new
Image
(
"Images/city.png"
);
city
=
city
.
getScaledCopy
(
WIDTH
+
55
,
HEIGHT
);
background
=
city
;
...
...
@@ -143,30 +147,18 @@ public class Level1 extends Level {
// sbg.enterState(Main.LOSE);
// }
if
(
input
.
isKeyDown
(
Input
.
KEY_SPACE
))
{
startY
-=
0.75
;
isRising
=
true
;
}
else
{
startY
+=
0.75
;
isRising
=
false
;
isFalling
=
true
;
}
if
(
startY
>
HEIGHT
-
(
char_Height
))
{
startY
=
HEIGHT
-
(
char_Height
);
isFalling
=
false
;
}
if
(
startY
<
0
)
{
startY
=
0
;
}
character
.
update
(
container
,
delta
);
if
(
pointCounter
%
spawnInterval
==
0
)
{
obstacles
.
add
(
new
Obstacle
());
if
(!((
int
)
((
pointCounter
/
levelLength
)
+
0.5
)
==
1
))
{
if
(
pointCounter
%
spawnInterval
==
0
)
{
obstacles
.
add
(
new
Obstacle
(
1
));
}
}
for
(
Obstacle
o
:
obstacles
)
{
o
.
update
(
container
,
delta
);
if
(
character
.
hitTest
(
o
))
{
topScore
=
pointCounter
/
20
;
sbg
.
getState
(
Main
.
LOSE
).
init
(
container
,
sbg
);
sbg
.
enterState
(
Main
.
LOSE
);
}
}
...
...
@@ -174,6 +166,7 @@ public class Level1 extends Level {
pointCounter
+=
1
;
if
((
pointCounter
%
levelLength
==
0
))
{
mainMusic
.
stop
();
sbg
.
getState
(
Main
.
LVL2
).
init
(
container
,
sbg
);
sbg
.
enterState
(
Main
.
LVL2
);
}
character
.
update
(
container
,
delta
);
...
...
@@ -191,7 +184,6 @@ public class Level1 extends Level {
if
(
backgroundX2
>
WIDTH
)
{
g
.
drawImage
(
background
,
(
float
)
(
WIDTH
-
backgroundX
),
0
,
null
);
}
if
(!
mainMusic
.
playing
())
{
mainMusic
.
loop
();
}
...
...
@@ -202,30 +194,12 @@ public class Level1 extends Level {
ttf
.
drawString
(
Level
.
WIDTH
-
70
,
0
,
"Level 1"
,
Color
.
black
);
g
.
drawString
(
"Char x: "
+
character
.
x
,
WIDTH
-
100
,
20
);
g
.
drawString
(
"Char y: "
+
character
.
y
,
WIDTH
-
100
,
40
);
g
.
drawString
(
"laser x:"
+
laser
.
x
,
WIDTH
-
100
,
60
);
g
.
drawString
(
"laser y:"
+
laser
.
y
,
WIDTH
-
100
,
80
);
Input
input
=
container
.
getInput
();
if
(
character
.
hasSprite
())
{
if
(!
isRising
&&
!
isFalling
)
{
character
.
getAnimation
().
draw
(
startX
,
startY
);
}
else
if
(
isRising
)
{
character
.
getRisingImage
().
draw
(
startX
,
startY
);
}
else
if
(
isFalling
)
{
character
.
getFallingImage
().
draw
(
startX
,
startY
);
}
}
else
{
character
.
getImage
().
draw
(
startX
,
startY
);
if
(
input
.
isKeyDown
(
Input
.
KEY_SPACE
))
{
character
.
render
(
container
,
g
);
f
ireImage
.
draw
(
startX
+
10
,
startY
+
80
);
}
f
or
(
Obstacle
o
:
obstacles
)
{
o
.
render
(
container
,
g
);
}
for
(
Obstacle
o
:
obstacles
)
{
o
.
render
(
container
,
g
);
...
...
src/project/Level2.java
View file @
22c7f99b
...
...
@@ -16,8 +16,10 @@
package
project
;
import
entities.Laser
;
import
entities.Obstacle
;
import
entities.Player
;
import
java.awt.Font
;
import
java.util.ArrayList
;
import
org.newdawn.slick.Animation
;
import
org.newdawn.slick.Color
;
import
org.newdawn.slick.GameContainer
;
...
...
@@ -29,6 +31,8 @@ import org.newdawn.slick.SlickException;
import
org.newdawn.slick.SpriteSheet
;
import
org.newdawn.slick.TrueTypeFont
;
import
org.newdawn.slick.state.StateBasedGame
;
import
static
project
.
Level
.
WIDTH
;
import
static
project
.
Level
.
pointCounter
;
/**
*
...
...
@@ -44,6 +48,8 @@ public class Level2 extends Level {
private
SpriteSheet
xeonSheet
=
null
;
private
Animation
playerAnimation
;
ArrayList
<
Obstacle
>
obstacles
=
new
ArrayList
<
Obstacle
>();
private
float
startY
=
(
float
)
(
HEIGHT
-
char_Height
);
private
float
startX
=
WIDTH
/
6
;
...
...
@@ -57,23 +63,15 @@ public class Level2 extends Level {
private
String
meters
=
"M"
;
private
int
topScore
;
private
boolean
isRising
=
false
;
private
boolean
isFalling
=
false
;
private
static
final
int
spawnInterval
=
levelLength
/
10
;
Laser
laser
;
Font
font
;
TrueTypeFont
ttf
;
public
int
getTopScore
()
{
return
topScore
;
}
public
void
setTopScore
(
int
topScore
)
{
this
.
topScore
=
topScore
;
}
public
Level2
(
int
state
)
{
super
(
state
);
}
...
...
@@ -129,26 +127,25 @@ public class Level2 extends Level {
character
.
getAnimation
().
update
(
delta
);
}
if
(
input
.
isKeyDown
(
Input
.
KEY_SPACE
))
{
startY
-=
0.75
;
isRising
=
true
;
character
.
update
(
container
,
delta
);
if
(!((
int
)
((
pointCounter
/
levelLength
)
+
0.5
)
==
2
))
{
if
(
pointCounter
%
spawnInterval
==
0
)
{
obstacles
.
add
(
new
Obstacle
(
1
));
}
}
else
{
startY
+=
0.75
;
isRising
=
false
;
isFalling
=
true
;
for
(
Obstacle
o
:
obstacles
)
{
o
.
update
(
container
,
delta
);
if
(
character
.
hitTest
(
o
))
{
topScore
=
pointCounter
/
20
;
sbg
.
getState
(
Main
.
LOSE
).
init
(
container
,
sbg
);
sbg
.
enterState
(
Main
.
LOSE
);
}
}
if
(
startY
>
HEIGHT
-
(
char_Height
))
{
startY
=
HEIGHT
-
(
char_Height
);
isFalling
=
false
;
}
if
(
startY
<
0
)
{
startY
=
0
;
}
pointCounter
+=
1
;
if
((
pointCounter
%
levelLength
==
0
))
{
mainMusic
.
stop
();
sbg
.
getState
(
Main
.
LVL3
).
init
(
container
,
sbg
);
sbg
.
enterState
(
Main
.
LVL3
);
}
}
...
...
@@ -172,28 +169,16 @@ public class Level2 extends Level {
//g.setColor(Color.black);
g
.
drawString
(
Integer
.
toString
(
pointCounter
/
20
)
+
meters
,
0
,
0
);
g
.
drawString
(
Integer
.
toString
(
getTopScore
())
+
meters
,
0
,
20
);
g
.
drawString
(
Integer
.
toString
(
topScore
)
+
meters
,
0
,
20
);
ttf
.
drawString
(
Level
.
WIDTH
-
70
,
0
,
"Level 2"
,
Color
.
black
);
Input
input
=
container
.
getInput
();
if
(
character
.
hasSprite
())
{
if
(!
isRising
&&
!
isFalling
)
{
character
.
getAnimation
().
draw
(
startX
,
startY
);
}
else
if
(
isRising
)
{
character
.
getRisingImage
().
draw
(
startX
,
startY
);
}
else
if
(
isFalling
)
{
character
.
getFallingImage
().
draw
(
startX
,
startY
);
}
}
else
{
character
.
getImage
().
draw
(
startX
,
startY
);
if
(
input
.
isKeyDown
(
Input
.
KEY_SPACE
))
{
character
.
render
(
container
,
g
);
f
ireImage
.
draw
(
startX
+
10
,
startY
+
80
);
}
f
or
(
Obstacle
o
:
obstacles
)
{
o
.
render
(
container
,
g
);
}
//laser.image.draw(100, 100);
//xeonSheet.draw();
...
...
src/project/Level3.java
View file @
22c7f99b
...
...
@@ -16,8 +16,10 @@
package
project
;
import
entities.Laser
;
import
entities.Obstacle
;
import
entities.Player
;
import
java.awt.Font
;
import
java.util.ArrayList
;
import
org.newdawn.slick.Animation
;
import
org.newdawn.slick.Color
;
import
org.newdawn.slick.GameContainer
;
...
...
@@ -29,6 +31,8 @@ import org.newdawn.slick.SlickException;
import
org.newdawn.slick.SpriteSheet
;
import
org.newdawn.slick.TrueTypeFont
;
import
org.newdawn.slick.state.StateBasedGame
;
import
static
project
.
Level
.
WIDTH
;
import
static
project
.
Level
.
pointCounter
;
/**
*
...
...
@@ -44,6 +48,8 @@ public class Level3 extends Level {
private
SpriteSheet
xeonSheet
=
null
;
private
Animation
playerAnimation
;
ArrayList
<
Obstacle
>
obstacles
=
new
ArrayList
<
Obstacle
>();
private
float
startY
=
(
float
)
(
HEIGHT
-
char_Height
);
private
float
startX
=
WIDTH
/
6
;
...
...
@@ -57,11 +63,11 @@ public class Level3 extends Level {
private
String
meters
=
"M"
;
private
int
topScore
;
private
boolean
isRising
=
false
;
private
boolean
isFalling
=
false
;
private
static
final
int
spawnInterval
=
levelLength
/
5
;
Laser
laser
;
Font
font
;
TrueTypeFont
ttf
;
...
...
@@ -122,26 +128,25 @@ public class Level3 extends Level {
character
.
getAnimation
().
update
(
delta
);
}
if
(
input
.
isKeyDown
(
Input
.
KEY_SPACE
))
{
startY
-=
0.75
;
isRising
=
true
;
character
.
update
(
container
,
delta
);
if
(!((
int
)
((
pointCounter
/
levelLength
)
+
0.5
)
==
3
))
{
if
(
pointCounter
%
spawnInterval
==
0
)
{
obstacles
.
add
(
new
Obstacle
(
1.5f
));
}
}
else
{
startY
+=
0.75
;
isRising
=
false
;
isFalling
=
true
;
for
(
Obstacle
o
:
obstacles
)
{
o
.
update
(
container
,
delta
);
if
(
character
.
hitTest
(
o
))
{
topScore
=
pointCounter
/
20
;
sbg
.
getState
(
Main
.
LOSE
).
init
(
container
,
sbg
);
sbg
.
enterState
(
Main
.
LOSE
);
}
}
if
(
startY
>
HEIGHT
-
(
char_Height
))
{
startY
=
HEIGHT
-
(
char_Height
);
isFalling
=
false
;
}
if
(
startY
<
0
)
{
startY
=
0
;
}
pointCounter
+=
1
;
if
((
pointCounter
%
levelLength
==
0
))
{
mainMusic
.
stop
();
sbg
.
getState
(
Main
.
LVL4
).
init
(
container
,
sbg
);
sbg
.
enterState
(
Main
.
LVL4
);
}
}
...
...
@@ -164,31 +169,17 @@ public class Level3 extends Level {
}
g
.
drawString
(
Integer
.
toString
(
pointCounter
/
20
)
+
meters
,
0
,
0
);
g
.
drawString
(
Integer
.
toString
(
getT
opScore
()
)
+
meters
,
0
,
20
);
g
.
drawString
(
Integer
.
toString
(
t
opScore
)
+
meters
,
0
,
20
);
ttf
.
drawString
(
Level
.
WIDTH
-
70
,
0
,
"Level 3"
,
Color
.
black
);
Input
input
=
container
.
getInput
();
if
(
character
.
hasSprite
())
{
if
(!
isRising
&&
!
isFalling
)
{
character
.
getAnimation
().
draw
(
startX
,
startY
);
}
else
if
(
isRising
)
{
character
.
getRisingImage
().
draw
(
startX
,
startY
);
}
else
if
(
isFalling
)
{
character
.
getFallingImage
().
draw
(
startX
,
startY
);
}
}
else
{
character
.
getImage
().
draw
(
startX
,
startY
);
if
(
input
.
isKeyDown
(
Input
.
KEY_SPACE
))
{
character
.
render
(
container
,
g
);
f
ireImage
.
draw
(
startX
+
10
,
startY
+
80
);
}
f
or
(
Obstacle
o
:
obstacles
)
{
o
.
render
(
container
,
g
);
}
//laser.image.draw(100, 100);
//xeonSheet.draw();
}
}
}
src/project/Level4.java
View file @
22c7f99b
...
...
@@ -16,8 +16,10 @@
package
project
;
import
entities.Laser
;
import
entities.Obstacle
;
import
entities.Player
;
import
java.awt.Font
;
import
java.util.ArrayList
;
import
org.newdawn.slick.Animation
;
import
org.newdawn.slick.Color
;
import
org.newdawn.slick.GameContainer
;
...
...
@@ -29,6 +31,7 @@ import org.newdawn.slick.SlickException;
import
org.newdawn.slick.SpriteSheet
;
import
org.newdawn.slick.TrueTypeFont
;
import
org.newdawn.slick.state.StateBasedGame
;
import
static
project
.
Level
.
WIDTH
;
/**
*
...
...
@@ -44,6 +47,8 @@ public class Level4 extends Level {
private
SpriteSheet
xeonSheet
=
null
;
private
Animation
playerAnimation
;
ArrayList
<
Obstacle
>
obstacles
=
new
ArrayList
<
Obstacle
>();
private
float
startY
=
(
float
)
(
HEIGHT
-
char_Height
);
private
float
startX
=
WIDTH
/
6
;
...
...
@@ -55,14 +60,13 @@ public class Level4 extends Level {
private
static
float
backgroundX
=
(
float
)
0.0
;
private
static
float
dX
=
(
float
)
1
;
private
int
pointCounter
=
0
;
private
String
meters
=
"M"
;
private
int
topScore
;
private
boolean
isRising
=
false
;
private
boolean
isFalling
=
false
;
private
static
final
int
spawnInterval
=
levelLength
/
10
;
Laser
laser
;
Font
font
;
TrueTypeFont
ttf
;
...
...
@@ -122,26 +126,25 @@ public class Level4 extends Level {
character
.
getAnimation
().
update
(
delta
);
}
if
(
input
.
isKeyDown
(
Input
.
KEY_SPACE
))
{
startY
-=
0.75
;
isRising
=
true
;
character
.
update
(
container
,
delta
);
if
(!((
int
)
((
pointCounter
/
levelLength
)
+
0.5
)
==
4
))
{
if
(
pointCounter
%
spawnInterval
==
0
)
{
obstacles
.
add
(
new
Obstacle
(
1.5f
));
}
}
else
{
startY
+=
0.75
;
isRising
=
false
;
isFalling
=
true
;
for
(
Obstacle
o
:
obstacles
)
{
o
.
update
(
container
,
delta
);
if
(
character
.
hitTest
(
o
))
{
topScore
=
pointCounter
/
20
;
sbg
.
getState
(
Main
.
LOSE
).
init
(
container
,
sbg
);
sbg
.
enterState
(
Main
.
LOSE
);
}
}
if
(
startY
>
HEIGHT
-
(
char_Height
))
{
startY
=
HEIGHT
-
(
char_Height
);
isFalling
=
false
;
}
if
(
startY
<
0
)
{
startY
=
0
;
}
pointCounter
+=
1
;
if
((
pointCounter
%
levelLength
==
0
))
{
mainMusic
.
stop
();
sbg
.
getState
(
Main
.
LVL5
).
init
(
container
,
sbg
);
sbg
.
enterState
(
Main
.
LVL5
);
}
}
...
...
@@ -165,32 +168,19 @@ public class Level4 extends Level {
//g.setColor(Color.black);
g
.
drawString
(
Integer
.
toString
(
pointCounter
/
20
)
+
meters
,
0
,
0
);
g
.
drawString
(
Integer
.
toString
(
getT
opScore
()
)
+
meters
,
0
,
20
);
g
.
drawString
(
Integer
.
toString
(
t
opScore
)
+
meters
,
0
,
20
);
ttf
.
drawString
(
Level
.
WIDTH
-
70
,
0
,
"Level 4"
,
Color
.
black
);
Input
input
=
container
.
getInput
();
if
(
character
.
hasSprite
())
{
if
(!
isRising
&&
!
isFalling
)
{
character
.
getAnimation
().
draw
(
startX
,
startY
);
}
else
if
(
isRising
)
{
character
.
getRisingImage
().
draw
(
startX
,
startY
);
}
else
if
(
isFalling
)
{
character
.
getFallingImage
().
draw
(
startX
,
startY
);
}
}
else
{
character
.
getImage
().
draw
(
startX
,
startY
);
if
(
input
.
isKeyDown
(
Input
.
KEY_SPACE
))
{
character
.
render
(
container
,
g
);
f
ireImage
.
draw
(
startX
+
10
,
startY
+
80
);
}
f
or
(
Obstacle
o
:
obstacles
)
{
o
.
render
(
container
,
g
);
}
//laser.image.draw(100, 100);
//xeonSheet.draw();
}
}
}
src/project/Level5.java
View file @
22c7f99b
...
...
@@ -16,8 +16,10 @@
package
project
;
import
entities.Laser
;
import
entities.Obstacle
;
import
entities.Player
;
import
java.awt.Font
;
import
java.util.ArrayList
;
import
org.newdawn.slick.Animation
;
import
org.newdawn.slick.Color
;
import
org.newdawn.slick.GameContainer
;
...
...
@@ -29,6 +31,7 @@ import org.newdawn.slick.SlickException;
import
org.newdawn.slick.SpriteSheet
;
import
org.newdawn.slick.TrueTypeFont
;
import
org.newdawn.slick.state.StateBasedGame
;
import
static
project
.
Level
.
WIDTH
;
/**
*
...
...
@@ -44,6 +47,8 @@ public class Level5 extends Level {
private
SpriteSheet
xeonSheet
=
null
;