Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brick-breaker
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mkandel2
brick-breaker
Commits
5a894833
Commit
5a894833
authored
1 year ago
by
abhatta5
Browse files
Options
Downloads
Patches
Plain Diff
Make circle radius dynamic
parent
248bd0bb
No related branches found
No related tags found
1 merge request
!1
Game graphics
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/src/main/java/brickbreaker/Ball.java
+1
-1
1 addition, 1 deletion
app/src/main/java/brickbreaker/Ball.java
app/src/main/java/brickbreaker/GamePanel.java
+10
-6
10 additions, 6 deletions
app/src/main/java/brickbreaker/GamePanel.java
with
11 additions
and
7 deletions
app/src/main/java/brickbreaker/Ball.java
+
1
−
1
View file @
5a894833
...
...
@@ -11,7 +11,7 @@ package brickbreaker;
public
class
Ball
{
private
Vector
position
;
private
Vector
direction
;
p
rivate
int
radius
;
p
ublic
int
radius
;
public
Ball
(
int
posX
,
int
posY
,
int
dirX
,
int
dirY
,
int
radius
)
{
this
.
position
=
new
Vector
(
posX
,
posY
);
...
...
This diff is collapsed.
Click to expand it.
app/src/main/java/brickbreaker/GamePanel.java
+
10
−
6
View file @
5a894833
...
...
@@ -31,7 +31,7 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener {
public
GamePanel
()
{
this
.
balls
.
add
(
new
Ball
(
350
,
450
,
1
,
-
1
,
20
));
// Adjust the initial ball position and direction
this
.
balls
.
add
(
new
Ball
(
380
,
420
,
-
1
,
1
,
2
0
));
this
.
balls
.
add
(
new
Ball
(
380
,
420
,
-
1
,
1
,
5
0
));
this
.
totalBricks
=
rows
*
columns
;
map
=
new
GameMapBuilder
(
rows
,
columns
);
...
...
@@ -58,7 +58,7 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener {
graphics
.
fillRect
(
691
,
0
,
3
,
592
);
graphics
.
setColor
(
Color
.
blue
);
graphics
.
fillRect
(
paddle
,
550
,
100
,
1
2
);
graphics
.
fillRect
(
paddle
,
550
,
100
,
2
0
);
graphics
.
setColor
(
Color
.
RED
);
// ball color
Iterator
<
Ball
>
ballsIterator
=
balls
.
iterator
();
...
...
@@ -67,7 +67,7 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener {
Ball
ball
=
ballsIterator
.
next
();
Vector
ballPosition
=
ball
.
getPosition
();
if
(
ballPosition
.
y
>
5
7
0
)
{
if
(
ballPosition
.
y
>
5
6
0
)
{
ballsIterator
.
remove
();
continue
;
}
else
{
...
...
@@ -75,7 +75,7 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener {
}
graphics
.
setColor
(
Color
.
RED
);
// ball color
graphics
.
fillOval
(
ballPosition
.
x
,
ballPosition
.
y
,
20
,
20
);
graphics
.
fillOval
(
ballPosition
.
x
,
ballPosition
.
y
,
ball
.
radius
,
ball
.
radius
);
}
graphics
.
setColor
(
Color
.
black
);
...
...
@@ -87,6 +87,10 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener {
gameOver
(
graphics
,
"You Won"
,
color
);
}
if
(
balls
.
isEmpty
())
{
gameOver
(
graphics
,
"Game Over"
,
Color
.
BLACK
);
}
}
public
void
gameOver
(
Graphics
graphics
,
String
gameOverText
,
Color
color
)
{
...
...
@@ -106,7 +110,7 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener {
Vector
ballPosition
=
ball
.
getPosition
();
Vector
ballDirection
=
ball
.
getDirection
();
if
(
new
Rectangle
(
ballPosition
.
x
,
ballPosition
.
y
,
20
,
20
).
intersects
(
new
Rectangle
(
paddle
,
550
,
100
,
8
)))
{
if
(
new
Rectangle
(
ballPosition
.
x
,
ballPosition
.
y
,
ball
.
radius
,
ball
.
radius
).
intersects
(
new
Rectangle
(
paddle
,
550
,
100
,
8
)))
{
ballDirection
.
y
=
-
ballDirection
.
y
;
ball
.
setDirection
(
ballDirection
.
x
,
ballDirection
.
y
);
}
...
...
@@ -120,7 +124,7 @@ public class GamePanel extends JPanel implements KeyListener, ActionListener {
int
brickHeight
=
map
.
brickHeight
;
Rectangle
brickRect
=
new
Rectangle
(
brickX
,
brickY
,
brickWidth
,
brickHeight
);
Rectangle
ballRect
=
new
Rectangle
(
ballPosition
.
x
,
ballPosition
.
y
,
20
,
20
);
Rectangle
ballRect
=
new
Rectangle
(
ballPosition
.
x
,
ballPosition
.
y
,
ball
.
radius
,
ball
.
radius
);
if
(
ballRect
.
intersects
(
brickRect
))
{
...
...
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