Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Y
yixcai-project-1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yixin Cai
yixcai-project-1
Commits
8b11a552
Commit
8b11a552
authored
Apr 23, 2021
by
Yixin Cai
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parent
1bcf9fe5
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
bagel.iml
+0
-26
0 additions, 26 deletions
bagel.iml
src/Background.java
+1
-0
1 addition, 0 deletions
src/Background.java
src/Entity.java
+5
-2
5 additions, 2 deletions
src/Entity.java
src/Player.java
+5
-2
5 additions, 2 deletions
src/Player.java
src/ShadowTreasure.java
+6
-9
6 additions, 9 deletions
src/ShadowTreasure.java
with
17 additions
and
39 deletions
bagel.iml
deleted
100644 → 0
+
0
−
26
View file @
1bcf9fe5
<?xml version="1.0" encoding="UTF-8"?>
<module
org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule=
"true"
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
LANGUAGE_LEVEL=
"JDK_14"
>
<output
url=
"file://$MODULE_DIR$/target/classes"
/>
<output-test
url=
"file://$MODULE_DIR$/target/test-classes"
/>
<content
url=
"file://$MODULE_DIR$"
>
<sourceFolder
url=
"file://$MODULE_DIR$/src"
isTestSource=
"false"
/>
<excludeFolder
url=
"file://$MODULE_DIR$/target"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
<orderEntry
type=
"library"
name=
"Maven: io.github.eleanor-em:bagel:1.9.3"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: org.lwjgl:lwjgl:3.2.2"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: org.lwjgl:lwjgl-assimp:3.2.2"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: org.lwjgl:lwjgl-glfw:3.2.2"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: org.lwjgl:lwjgl-openal:3.2.2"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: org.lwjgl:lwjgl-opengl:3.2.2"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: org.lwjgl:lwjgl-stb:3.2.2"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: org.lwjgl:lwjgl:natives-macos:3.2.2"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: org.lwjgl:lwjgl-assimp:natives-macos:3.2.2"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: org.lwjgl:lwjgl-glfw:natives-macos:3.2.2"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: org.lwjgl:lwjgl-openal:natives-macos:3.2.2"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: org.lwjgl:lwjgl-opengl:natives-macos:3.2.2"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Maven: org.lwjgl:lwjgl-stb:natives-macos:3.2.2"
level=
"project"
/>
</component>
</module>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Background.java
+
1
−
0
View file @
8b11a552
...
...
@@ -7,6 +7,7 @@ public class Background{
this
.
image
=
new
Image
(
image
);
}
// to draw the background of game
public
void
drawBackground
(){
image
.
drawFromTopLeft
(
0
,
0
);
}
...
...
This diff is collapsed.
Click to expand it.
src/Entity.java
+
5
−
2
View file @
8b11a552
...
...
@@ -7,32 +7,35 @@ public class Entity {
private
double
PositionY
;
private
final
Image
image
;
// set up entity
public
Entity
(
double
PositionX
,
double
PositionY
,
String
image
){
this
.
image
=
new
Image
(
image
);
this
.
PositionX
=
PositionX
;
this
.
PositionY
=
PositionY
;
};
// to draw the entity in game
public
void
drawEntity
(){
this
.
image
.
draw
(
this
.
getPositionX
(),
this
.
getPositionY
());
}
// get position
public
double
getPositionX
(){
return
this
.
PositionX
;
}
public
double
getPositionY
(){
return
this
.
PositionY
;
}
// set up position
public
void
setPositionX
(
double
x
){
this
.
PositionX
=
x
;
}
public
void
setPositionY
(
double
y
){
this
.
PositionY
=
y
;
}
// calculate the distance between two entity
public
double
distanceFrom
(
Entity
ohterEntity
){
double
dx
=
this
.
getPositionX
()
-
ohterEntity
.
getPositionX
();
double
dy
=
this
.
getPositionY
()
-
ohterEntity
.
getPositionY
();
...
...
This diff is collapsed.
Click to expand it.
src/Player.java
+
5
−
2
View file @
8b11a552
public
class
Player
extends
Entity
{
private
int
energyLevel
;
private
static
final
int
stepSize
=
10
;
// set up the player
public
Player
(
double
PositionX
,
double
PositionY
,
String
image
,
int
energyLevel
)
{
super
(
PositionX
,
PositionY
,
image
);
this
.
energyLevel
=
energyLevel
;
}
// get energy level from player
public
int
getEnergyLevel
()
{
return
this
.
energyLevel
;
}
// set energy level
public
void
setEnergyLevel
(
int
energyLeve
){
this
.
energyLevel
=
energyLeve
;
}
// check meet to other entity
public
boolean
meet
(
Entity
entity
){
if
(
this
.
distanceFrom
(
entity
)
<
50
){
return
true
;
...
...
@@ -24,6 +26,7 @@ public class Player extends Entity {
return
false
;
}
// move to other entity
public
void
moveTo
(
Entity
entity
){
double
xd
=
(
entity
.
getPositionX
()
-
this
.
getPositionX
())/
this
.
distanceFrom
(
entity
);
double
yd
=
(
entity
.
getPositionY
()
-
this
.
getPositionY
())/
this
.
distanceFrom
(
entity
);
...
...
This diff is collapsed.
Click to expand it.
src/ShadowTreasure.java
+
6
−
9
View file @
8b11a552
...
...
@@ -16,7 +16,7 @@ public class ShadowTreasure extends AbstractGame {
private
static
DecimalFormat
df
=
new
DecimalFormat
(
"0.00"
);
//
//
Set up the attributes for game
private
Player
player
;
private
Zambie
zambie
;
private
Sandwich
sandwich
;
...
...
@@ -42,20 +42,16 @@ public class ShadowTreasure extends AbstractGame {
try
(
BufferedReader
file
=
new
BufferedReader
(
new
FileReader
(
filename
))){
String
[]
newLine
=
file
.
readLine
().
split
(
","
);
//read each row from file and set up the entities and background
this
.
player
=
new
Player
(
Double
.
parseDouble
(
newLine
[
1
]),
Double
.
parseDouble
(
newLine
[
2
]),
"res/images/player.png"
,
Integer
.
parseInt
(
newLine
[
3
]));
newLine
=
file
.
readLine
().
split
(
","
);
this
.
zambie
=
new
Zambie
(
Double
.
parseDouble
(
newLine
[
1
]),
Double
.
parseDouble
(
newLine
[
2
]),
"res/images/zombie.png"
);
newLine
=
file
.
readLine
().
split
(
","
);
this
.
sandwich
=
new
Sandwich
(
Double
.
parseDouble
(
newLine
[
1
]),
Double
.
parseDouble
(
newLine
[
2
]),
"res/images/sandwich.png"
);
this
.
background
=
new
Background
(
"res/images/background.png"
);
this
.
font
=
new
Font
(
"res/font/DejaVuSans-Bold.ttf"
,
20
);
// draw the attributes and energy level
this
.
background
.
drawBackground
();
this
.
player
.
drawEntity
();
this
.
zambie
.
drawEntity
();
...
...
@@ -74,6 +70,8 @@ public class ShadowTreasure extends AbstractGame {
@Override
public
void
update
(
Input
input
)
{
// Logic to update the game, as per specification must go here
// draw the attributes and energy level
this
.
background
.
drawBackground
();
this
.
player
.
drawEntity
();
this
.
zambie
.
drawEntity
();
...
...
@@ -82,6 +80,7 @@ public class ShadowTreasure extends AbstractGame {
}
this
.
font
.
drawString
(
"energy:"
+
this
.
player
.
getEnergyLevel
(),
20
,
760
);
// follow the interaction logic and update energy in each tick, than output the location and energy level
if
(
this
.
countFrame
==
10
){
if
(
this
.
player
.
meet
(
this
.
zambie
)){
this
.
player
.
setEnergyLevel
(
this
.
player
.
getEnergyLevel
()
-
3
);
...
...
@@ -94,13 +93,11 @@ public class ShadowTreasure extends AbstractGame {
}
else
{
printInfo
(
this
.
player
.
getPositionX
(),
this
.
player
.
getPositionY
(),
this
.
player
.
getEnergyLevel
());
}
if
(
this
.
player
.
getEnergyLevel
()
>=
3
){
this
.
player
.
moveTo
(
this
.
zambie
);
}
else
{
this
.
player
.
moveTo
(
this
.
sandwich
);
}
this
.
countFrame
=
0
;
}
this
.
countFrame
+=
1
;
...
...
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