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
fb6b7dce
authored
Apr 28, 2022
by
anshve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
fa477dab
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
0 deletions
PongSource/src/states/ServeState.lua
PongSource/src/states/ServeState.lua
0 → 100644
View file @
fb6b7dce
ServeState
=
Class
{
__includes
=
BaseState
}
function
ServeState
:
enter
(
params
)
paddle1
=
params
.
paddle1
paddle2
=
params
.
paddle2
-- decide which players will serve
servingPlayer
=
math.random
(
2
)
==
1
and
1
or
2
if
params
.
ball
==
nil
then
ball
=
Ball
(
VIRTUAL_WIDTH
/
2
-
2
,
VIRTUAL_HEIGHT
/
2
-
2
,
4
,
4
)
if
servingPlayer
==
1
then
ball
.
dx
=
-
100
else
ball
.
dx
=
100
end
else
ball
=
params
.
ball
if
ball
.
dx
==
-
100
then
servingPlayer
=
1
else
servingPlayer
=
2
end
end
self
.
background
=
params
.
background
self
.
mode
=
params
.
mode
self
.
maxScore
=
params
.
maxScore
end
function
ServeState
:
update
(
dt
)
if
love
.
keyboard
.
wasPressed
(
'enter'
)
or
love
.
keyboard
.
wasPressed
(
'return'
)
then
gStateMachine
:
change
(
'play'
,
{
mode
=
self
.
mode
,
background
=
self
.
background
,
maxScore
=
self
.
maxScore
,
paddle1
=
paddle1
,
paddle2
=
paddle2
,
ball
=
ball
})
end
end
function
ServeState
:
render
()
if
self
.
background
==
0
then
love
.
graphics
.
clear
(
40
/
255
,
45
/
255
,
52
/
255
,
1
)
else
local
backgroundName
=
'background-'
..
self
.
background
local
backgroundWidth
=
gTextures
[
backgroundName
]:
getWidth
()
local
backgroundHeight
=
gTextures
[
backgroundName
]:
getHeight
()
love
.
graphics
.
draw
(
gTextures
[
backgroundName
],
0
,
0
,
0
,
VIRTUAL_WIDTH
/
(
backgroundWidth
-
1
),
VIRTUAL_HEIGHT
/
(
backgroundHeight
-
1
))
end
love
.
graphics
.
setFont
(
gFonts
[
'large'
])
self
:
drawTextWithShadow
(
paddle1
:
getScore
(),
-
100
,
200
)
self
:
drawTextWithShadow
(
paddle2
:
getScore
(),
100
,
200
)
love
.
graphics
.
setFont
(
gFonts
[
'small'
])
self
:
drawTextWithShadow
(
"Player "
..
tostring
(
servingPlayer
)
..
"'s turn!"
,
0
,
20
)
self
:
drawTextWithShadow
(
"Press Enter to Serve!"
,
0
,
30
)
paddle1
:
render
()
paddle2
:
render
()
ball
:
render
()
end
function
ServeState
:
drawTextWithShadow
(
text
,
x
,
y
)
love
.
graphics
.
setColor
(
34
/
255
,
32
/
255
,
52
/
255
,
255
/
255
)
love
.
graphics
.
printf
(
text
,
x
+
2
,
y
+
1
,
VIRTUAL_WIDTH
,
'center'
)
love
.
graphics
.
printf
(
text
,
x
+
1
,
y
+
1
,
VIRTUAL_WIDTH
,
'center'
)
love
.
graphics
.
printf
(
text
,
x
+
0
,
y
+
1
,
VIRTUAL_WIDTH
,
'center'
)
love
.
graphics
.
printf
(
text
,
x
+
1
,
y
+
2
,
VIRTUAL_WIDTH
,
'center'
)
love
.
graphics
.
setColor
(
1
,
1
,
1
,
1
)
love
.
graphics
.
printf
(
text
,
x
,
y
,
VIRTUAL_WIDTH
,
'center'
)
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