Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Erik.Ingebrigtsen
Proggy Gonzales
Commits
2347346e
Commit
2347346e
authored
Feb 28, 2022
by
Hannah.Morken
Browse files
Bakgrunn scroller
parent
a8c5f8b2
Changes
7
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
2347346e
...
...
@@ -86,7 +86,15 @@
</execution>
</executions>
</plugin>
</plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<source>
16
</source>
<target>
16
</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
...
...
res/graphics/bakgrunn.jpg
0 → 100644
View file @
2347346e
8.6 KB
src/main/java/core/GamePanel.java
View file @
2347346e
package
core
;
import
java.awt.Color
;
import
java.awt.Dimension
;
import
java.awt.Graphics
;
import
java.awt.Graphics2D
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
import
java.io.IOException
;
import
javax.swing.JPanel
;
import
javax.imageio.ImageIO
;
import
javax.swing.*
;
import
entity.Background
;
import
entity.Player
;
import
tile.TileLoader
;
...
...
@@ -28,14 +29,14 @@ public class GamePanel extends JPanel implements Runnable{
KeyHandler
keyH
=
new
KeyHandler
();
Thread
gameThread
;
Player
player
=
new
Player
(
this
,
keyH
);
Background
bg
=
new
Background
(
this
,
keyH
);
TileLoader
loader
=
new
TileLoader
(
this
);
public
GamePanel
()
{
this
.
setPreferredSize
(
new
Dimension
(
screenWidth
,
screenHeight
));
this
.
setBackground
(
Color
.
DARK_GRAY
);
//
this.setBackground(Color.DARK_GRAY);
this
.
setDoubleBuffered
(
true
);
this
.
addKeyListener
(
keyH
);
this
.
setFocusable
(
true
);
...
...
@@ -125,18 +126,22 @@ public class GamePanel extends JPanel implements Runnable{
public
void
update
()
{
bg
.
update
();
player
.
update
();
}
public
void
jump
()
{
player
.
jump
();
}
public
void
paintComponent
(
Graphics
g
)
{
super
.
paintComponent
(
g
);
Graphics2D
g2
=
(
Graphics2D
)
g
;
bg
.
draw
(
g2
);
loader
.
draw
(
g2
);
player
.
draw
(
g2
);
...
...
src/main/java/entity/Background.java
0 → 100644
View file @
2347346e
package
entity
;
import
core.KeyHandler
;
import
javax.imageio.ImageIO
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
import
java.io.IOException
;
import
core.GamePanel
;
public
class
Background
extends
Entity
{
GamePanel
gp
;
KeyHandler
keyH
;
public
Background
(
GamePanel
gp
,
KeyHandler
keyH
)
{
this
.
gp
=
gp
;
this
.
keyH
=
keyH
;
setDefaultValues
();
getImage
();
}
public
void
setDefaultValues
()
{
x
=
0
;
y
=
0
;
speed
=
3
;
direction
=
"down"
;
}
public
void
getImage
()
{
try
{
bakgrunn
=
ImageIO
.
read
(
getClass
().
getResourceAsStream
(
"/graphics/bakgrunn.jpg"
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
void
update
()
{
if
(
keyH
.
leftPressed
==
true
||
keyH
.
rightPressed
==
true
)
{
if
(
keyH
.
leftPressed
==
true
)
{
direction
=
"left"
;
x
+=
speed
;
}
else
if
(
keyH
.
rightPressed
==
true
)
{
direction
=
"right"
;
x
-=
speed
;
}
}
}
public
void
draw
(
Graphics2D
g2
)
{
g2
.
drawImage
(
bakgrunn
,
x
,
y
,
1000
,
700
,
null
);
}
}
src/main/java/entity/Entity.java
View file @
2347346e
...
...
@@ -9,7 +9,7 @@ public class Entity {
public
int
speed
;
public
BufferedImage
up1
,
up2
,
down1
,
down2
,
left1
,
left2
,
right1
,
right2
;
public
BufferedImage
up1
,
up2
,
down1
,
down2
,
left1
,
left2
,
right1
,
right2
,
bakgrunn
;
public
String
direction
;
//brukes til å skape animasjon på spiller og fiender
...
...
src/main/java/entity/Player.java
View file @
2347346e
...
...
@@ -60,7 +60,7 @@ public class Player extends Entity{
right1
=
ImageIO
.
read
(
getClass
().
getResourceAsStream
(
"/player/Guy_right-1.png"
));
right2
=
ImageIO
.
read
(
getClass
().
getResourceAsStream
(
"/player/Guy_right-2.png"
));
bakgrunn
=
ImageIO
.
read
(
getClass
().
getResourceAsStream
(
"/graphics/bakgrunn.jpg"
));
}
catch
(
IOException
e
)
{
...
...
@@ -86,11 +86,11 @@ public class Player extends Entity{
}
else
if
(
keyH
.
leftPressed
==
true
)
{
direction
=
"left"
;
x
-=
speed
;
//
x-= speed;
}
else
if
(
keyH
.
rightPressed
==
true
)
{
direction
=
"right"
;
x
+=
speed
;
//
x+= speed;
}
// oppdaterer bilde som blir brukt til player
...
...
@@ -124,6 +124,8 @@ public class Player extends Entity{
public
void
draw
(
Graphics2D
g2
)
{
// g2.setColor(Color.white);
// g2.fillRect(x, y, gp.tileSize, gp.tileSize);
//g2.drawImage(bakgrunn, 0,0, 1000, 700, null);
BufferedImage
image
=
null
;
switch
(
direction
)
{
...
...
src/test/java/playerTest/MovementTest.java
View file @
2347346e
package
playerTest
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
/*
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import org.junit.jupiter.api.Test;
...
...
@@ -56,4 +56,4 @@ public class MovementTest {
}
}
}
*/
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment