Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Bunny Crossy
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
Bunny Dash
Bunny Crossy
Commits
6d0d2765
Commit
6d0d2765
authored
9 months ago
by
Simon Peter Marneros
Browse files
Options
Downloads
Patches
Plain Diff
car.java
parent
88adc7c0
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
Car.java
+54
-0
54 additions, 0 deletions
Car.java
with
54 additions
and
0 deletions
Car.java
0 → 100644
+
54
−
0
View file @
6d0d2765
import
java.awt.*
;
public
class
Car
{
private
int
x
,
y
,
speed
;
private
static
final
int
WIDTH
=
80
;
private
static
final
int
HEIGHT
=
40
;
private
Color
color
;
public
Car
(
int
x
,
int
y
,
int
speed
)
{
this
.
x
=
x
;
this
.
y
=
y
;
this
.
speed
=
speed
;
this
.
color
=
getRandomColor
();
}
public
void
move
()
{
x
+=
speed
;
}
public
boolean
checkCollision
(
int
bunnyX
,
int
bunnyY
,
int
bunnySize
)
{
return
x
<
bunnyX
+
bunnySize
&&
x
+
WIDTH
>
bunnyX
&&
y
<
bunnyY
+
bunnySize
&&
y
+
HEIGHT
>
bunnyY
;
}
public
int
getX
()
{
return
x
;
}
public
void
setX
(
int
x
)
{
this
.
x
=
x
;
}
public
int
getY
()
{
return
y
;
}
public
int
getSpeed
()
{
return
speed
;
}
public
void
increaseSpeed
()
{
speed
+=
speed
>
0
?
1
:
-
1
;
}
public
void
draw
(
Graphics
g
)
{
g
.
setColor
(
color
);
g
.
fillRect
(
x
,
y
,
WIDTH
,
HEIGHT
);
g
.
setColor
(
Color
.
BLACK
);
g
.
drawRect
(
x
,
y
,
WIDTH
,
HEIGHT
);
// Draw wheels
g
.
fillOval
(
x
+
10
,
y
+
HEIGHT
-
10
,
20
,
20
);
g
.
fillOval
(
x
+
WIDTH
-
30
,
y
+
HEIGHT
-
10
,
20
,
20
);
}
private
Color
getRandomColor
()
{
return
new
Color
(
(
int
)
(
Math
.
random
()
*
200
)
+
55
,
(
int
)
(
Math
.
random
()
*
200
)
+
55
,
(
int
)
(
Math
.
random
()
*
200
)
+
55
);
}
}
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