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
da07e987
authored
Apr 28, 2022
by
anshve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
ffee3f2b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
0 deletions
PongSource/main.lua
PongSource/main.lua
0 → 100644
View file @
da07e987
require
'src/Dependencies'
-- love.load is a constructor what called just once at the beginning of the game
function
love
.
load
()
math.randomseed
(
os.time
())
love
.
graphics
.
setDefaultFilter
(
'nearest'
,
'nearest'
)
love
.
window
.
setTitle
(
TITLE
)
gSounds
=
{
[
'paddle_hit'
]
=
love
.
audio
.
newSource
(
'sounds/paddle_hit.wav'
,
'static'
),
[
'point_scored'
]
=
love
.
audio
.
newSource
(
'sounds/point_scored.wav'
,
'static'
),
[
'wall_hit'
]
=
love
.
audio
.
newSource
(
'sounds/wall_hit.wav'
,
'static'
),
[
'select'
]
=
love
.
audio
.
newSource
(
'sounds/select.wav'
,
'static'
)
}
gStateMachine
=
StateMachine
{
[
'menu'
]
=
function
()
return
MenuState
()
end
,
[
'serve'
]
=
function
()
return
ServeState
()
end
,
[
'play'
]
=
function
()
return
PlayState
()
end
,
[
'victory'
]
=
function
()
return
VictoryState
()
end
,
}
gFonts
=
{
[
'small'
]
=
love
.
graphics
.
newFont
(
'fonts/font.ttf'
,
8
),
[
'medium'
]
=
love
.
graphics
.
newFont
(
'fonts/font.ttf'
,
16
),
[
'large'
]
=
love
.
graphics
.
newFont
(
'fonts/font.ttf'
,
32
)
}
love
.
graphics
.
setFont
(
gFonts
[
'small'
])
gTextures
=
{
[
'background-1'
]
=
love
.
graphics
.
newImage
(
'graphics/background-1.jpg'
),
[
'background-2'
]
=
love
.
graphics
.
newImage
(
'graphics/background-2.jpg'
),
[
'background-3'
]
=
love
.
graphics
.
newImage
(
'graphics/background-3.jpg'
),
}
push
:
setupScreen
(
VIRTUAL_WIDTH
,
VIRTUAL_HEIGHT
,
WINDOW_WIDTH
,
WINDOW_HEIGHT
,
{
vsync
=
true
,
fullscreen
=
false
,
resizable
=
true
})
gStateMachine
:
change
(
'menu'
,
{})
love
.
keyboard
.
keysPressed
=
{}
end
-- love.resize called whenever we change the dimensions of our window
function
love
.
resize
(
w
,
h
)
push
:
resize
(
w
,
h
)
end
-- love.update called every frame
function
love
.
update
(
dt
)
gStateMachine
:
update
(
dt
)
if
love
.
keyboard
.
wasPressed
(
'escape'
)
then
love
.
event
.
quit
()
end
love
.
keyboard
.
keysPressed
=
{}
end
-- love.keypressed is a callback that processes key strokes as they happen, just once
function
love
.
keypressed
(
key
)
love
.
keyboard
.
keysPressed
[
key
]
=
true
end
-- love.keyboard.wasPressed is a custom function that will let us test for individual keystrokes outside of the default `love.keypressed` callback
function
love
.
keyboard
.
wasPressed
(
key
)
if
love
.
keyboard
.
keysPressed
[
key
]
then
return
true
else
return
false
end
end
-- love.draw called each frame after update to draw all game objects
function
love
.
draw
()
push
:
apply
(
'start'
)
gStateMachine
:
render
()
push
:
apply
(
'end'
)
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