Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
vishnukap-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
Vishnudutt Kappagantula
vishnukap-project-1
Commits
864ddd93
Commit
864ddd93
authored
3 years ago
by
roguecomp
Browse files
Options
Downloads
Patches
Plain Diff
Added collision detection logic
parent
7dc8f20b
Branches
master
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Bird.java
+3
-3
3 additions, 3 deletions
src/Bird.java
src/Pipe.java
+21
-5
21 additions, 5 deletions
src/Pipe.java
src/ShadowFlap.java
+3
-1
3 additions, 1 deletion
src/ShadowFlap.java
with
27 additions
and
9 deletions
src/Bird.java
+
3
−
3
View file @
864ddd93
...
@@ -2,14 +2,14 @@ import bagel.Image;
...
@@ -2,14 +2,14 @@ import bagel.Image;
public
class
Bird
{
public
class
Bird
{
/* positive means moving up, negative means moving down */
/* positive means moving up, negative means moving down */
public
double
velocity
;
public
double
velocity
=
0
;
private
static
int
frameCounterSinceStart
=
0
;
private
static
int
frameCounterSinceStart
=
1
;
public
Image
birdWingUp
=
new
Image
(
"res/birdWingUp.png"
);
public
Image
birdWingUp
=
new
Image
(
"res/birdWingUp.png"
);
public
Image
birdWingDown
=
new
Image
(
"res/birdWingDown.png"
);
public
Image
birdWingDown
=
new
Image
(
"res/birdWingDown.png"
);
public
final
double
acceleration
=
0.4
;
public
final
double
acceleration
=
0.4
;
public
final
double
terminalVelocity
=
10
;
public
final
double
terminalVelocity
=
-
10
;
public
final
double
x
=
200
;
public
final
double
x
=
200
;
public
double
y
=
350
;
public
double
y
=
350
;
...
...
This diff is collapsed.
Click to expand it.
src/Pipe.java
+
21
−
5
View file @
864ddd93
import
bagel.*
;
import
bagel.DrawOptions
;
import
bagel.Image
;
import
bagel.Window
;
import
bagel.util.Point
;
import
bagel.util.Rectangle
;
public
class
Pipe
{
public
class
Pipe
{
private
final
double
velocity
=
-
5
;
private
final
double
velocity
=
-
5
;
private
double
pos
=
Window
.
getWidth
();
/* x-coord at spawn */
private
double
pos
=
Window
.
getWidth
();
/* x-coord at spawn */
private
final
int
pixelGap
=
168
;
private
final
int
pixelGap
=
168
;
public
Point
centrePipe1
,
centrePipe2
;
/* the higher this value the higher the pipe gap spawns, vice versa */
/* the higher this value the higher the pipe gap spawns, vice versa */
private
final
int
initialY
=
50
;
/* y-value of pipe at spawn */
private
final
int
initialY
=
50
;
/* y-value of pipe at spawn */
private
Image
pipeImage
=
new
Image
(
"res/pipe.png"
);
private
Image
pipeImage1
=
new
Image
(
"res/pipe.png"
);
private
Image
pipeImage2
=
new
Image
(
"res/pipe.png"
);
private
Rectangle
rectPipe1
,
rectPipe2
;
public
void
Pipe
()
{
public
void
Pipe
()
{
}
}
public
void
Render
()
{
public
void
Render
(
Rectangle
bird
)
{
/* upside down pipe */
/* upside down pipe */
this
.
pipeImage
.
draw
(
this
.
pos
,
-
this
.
initialY
);
this
.
pipeImage1
.
draw
(
this
.
pos
,
-
this
.
initialY
);
centrePipe1
=
new
Point
(
this
.
pos
,
-
this
.
initialY
);
rectPipe1
=
this
.
pipeImage1
.
getBoundingBoxAt
(
centrePipe1
);
/* straight up pipe */
/* straight up pipe */
DrawOptions
options
=
new
DrawOptions
();
DrawOptions
options
=
new
DrawOptions
();
this
.
pipeImage
.
draw
(
this
.
pos
,
Window
.
getHeight
()
-
this
.
initialY
+
this
.
pixelGap
,
this
.
pipeImage
2
.
draw
(
this
.
pos
,
Window
.
getHeight
()
-
this
.
initialY
+
this
.
pixelGap
,
options
.
setRotation
(
Math
.
PI
));
options
.
setRotation
(
Math
.
PI
));
centrePipe2
=
new
Point
(
this
.
pos
,
Window
.
getHeight
()
-
this
.
initialY
+
this
.
pixelGap
);
rectPipe2
=
this
.
pipeImage2
.
getBoundingBoxAt
(
centrePipe2
);
if
(
rectPipe2
.
intersects
(
bird
))
{
System
.
out
.
println
(
"COLLISION!\n"
);
}
this
.
pos
+=
this
.
velocity
;
this
.
pos
+=
this
.
velocity
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/ShadowFlap.java
+
3
−
1
View file @
864ddd93
import
bagel.*
;
import
bagel.*
;
import
bagel.util.Point
;
/**
/**
* Skeleton Code for SWEN20003 Project 1, Semester 2, 2021
* Skeleton Code for SWEN20003 Project 1, Semester 2, 2021
...
@@ -51,7 +52,8 @@ public class ShadowFlap extends AbstractGame {
...
@@ -51,7 +52,8 @@ public class ShadowFlap extends AbstractGame {
};
};
bird
.
Render
();
bird
.
Render
();
pipe
.
Render
();
Point
birdPos
=
new
Point
(
bird
.
x
,
bird
.
y
);
pipe
.
Render
(
bird
.
birdWingDown
.
getBoundingBoxAt
(
birdPos
));
}
}
else
if
(
gameState
==
"outOfBounds"
)
{
else
if
(
gameState
==
"outOfBounds"
)
{
Background
.
draw
(
Window
.
getWidth
()
/
2.0
,
Window
.
getHeight
()
/
2.0
);
Background
.
draw
(
Window
.
getWidth
()
/
2.0
,
Window
.
getHeight
()
/
2.0
);
...
...
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