Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
SWEN20003-2021S1-Wed-Week05
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
Xulin Yang
SWEN20003-2021S1-Wed-Week05
Commits
b9c75531
There was an error fetching the commit references. Please try again later.
Commit
b9c75531
authored
Mar 31, 2021
by
yangxvlin
Browse files
Options
Downloads
Patches
Plain Diff
copy from Q3
parent
68d145d4
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Q4.java
+50
-0
50 additions, 0 deletions
src/Q4.java
with
50 additions
and
0 deletions
src/Q4.java
0 → 100644
+
50
−
0
View file @
b9c75531
import
bagel.*
;
import
bagel.util.Point
;
/**
* Xulin Yang, 904904
*
* @create 2021-03-31 22:53
* description:
**/
public
class
Q4
extends
AbstractGame
{
private
static
final
String
PLAYER_IMAGE
=
"res/player.png"
;
private
static
final
String
BALL_IMAGE
=
"res/ball.png"
;
private
static
final
Point
PLAYER_POSITION
=
new
Point
(
200
,
350
);
private
static
final
Point
BALL_POSITION
=
new
Point
(
650
,
180
);
private
final
Image
playerImage
=
new
Image
(
PLAYER_IMAGE
);
private
final
Image
ballImage
=
new
Image
(
BALL_IMAGE
);
private
static
final
double
STEP_SIZE
=
2
;
private
double
playerX
=
10
;
// PLAYER_POSITION.x;
private
double
playerY
=
PLAYER_POSITION
.
y
;
private
static
final
double
SCORE_DISTANCE
=
20
;
private
final
Font
font
=
new
Font
(
"res/conformable.otf"
,
24
);
private
static
final
Point
FONT_POSITION
=
new
Point
(
32
,
32
);
public
static
void
main
(
String
[]
args
)
{
new
Q4
().
run
();
}
@Override
protected
void
update
(
Input
input
)
{
if
(
input
.
wasPressed
(
Keys
.
ESCAPE
))
{
System
.
out
.
println
(
"closed"
);
Window
.
close
();
}
if
(
new
Point
(
playerX
,
playerY
).
distanceTo
(
BALL_POSITION
)
<=
SCORE_DISTANCE
)
{
// System.out.println("Great job!");
font
.
drawString
(
"Great job!"
,
FONT_POSITION
.
x
,
FONT_POSITION
.
y
);
}
playerImage
.
draw
(
playerX
,
playerY
);
ballImage
.
draw
(
BALL_POSITION
.
x
,
BALL_POSITION
.
y
);
}
}
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