Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
anshve
/
PongGame
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
453f708c
authored
Apr 28, 2022
by
anshve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
ad1538c2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
PongSource/src/Ball.lua
PongSource/src/Ball.lua
0 → 100644
View file @
453f708c
Ball
=
Class
{}
function
Ball
:
init
(
x
,
y
,
width
,
height
)
self
.
x
=
x
self
.
y
=
y
self
.
width
=
width
self
.
height
=
height
self
.
dy
=
math.random
(
-
50
,
50
)
end
function
Ball
:
collides
(
box
)
if
self
.
x
>
box
.
x
+
box
.
width
or
self
.
x
+
self
.
width
<
box
.
x
then
return
false
end
if
self
.
y
>
box
.
y
+
box
.
height
or
self
.
y
+
self
.
height
<
box
.
y
then
return
false
end
return
true
end
function
Ball
:
reset
()
self
.
x
=
VIRTUAL_WIDTH
/
2
-
2
self
.
y
=
VIRTUAL_HEIGHT
/
2
-
2
self
.
dy
=
math.random
(
-
50
,
50
)
*
1
.
5
end
function
Ball
:
update
(
dt
)
-- ball hits upper or lower boundary, when bounce the ball
if
self
.
y
<=
0
then
self
.
dy
=
-
self
.
dy
self
.
y
=
0
gSounds
[
'wall_hit'
]:
play
()
elseif
self
.
y
>=
VIRTUAL_HEIGHT
-
4
then
self
.
dy
=
-
self
.
dy
self
.
y
=
VIRTUAL_HEIGHT
-
4
gSounds
[
'wall_hit'
]:
play
()
end
self
.
x
=
self
.
x
+
self
.
dx
*
dt
*
1
.
3
self
.
y
=
self
.
y
+
self
.
dy
*
dt
*
1
.
3
end
function
Ball
:
render
()
love
.
graphics
.
setColor
({
1
,
1
,
1
,
1
})
love
.
graphics
.
rectangle
(
'fill'
,
self
.
x
,
self
.
y
,
4
,
4
)
-- renders the ball
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment