-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
130 lines (78 loc) · 2.76 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
-- some import stuff :
local Config = require "config"
local Control = require "control"
local Ball = require 'ball'
local Game = require "game"
local Paddle = require "paddle"
local Menu = require 'gui'
-- used to check if we are in debug mode :
local lldebugger = nil
if arg[2] == "debug" then
lldebugger = require("lldebugger").start()
end
-- This is called once when the game start :
function love.load()
love.window.setMode(Config.Window.width, Config.Window.height, {vsync = true})
-- Game default settings :
love.graphics.setNewFont(Config.GameScreen.fontSize)
love.window.setTitle(Config.Window.title)
-- Get game size :
Config.Window.width = love.graphics.getWidth()
Config.Window.height = love.graphics.getHeight()
-- Setup Player :
Paddle.defaultPos()
-- Setup Score :
Config.Player.score = 0
Config.IA.score = 0
-- Setup Paddle limit zone :
Config.Paddle.topLimit = Config.Paddle.padding;
Config.Paddle.bottomLimit = Config.Window.height - Config.Paddle.height - Config.Paddle.padding;
-- Setup Ball :
Ball.defaultPos()
-- Setup Limit Zone UI :
Config.LimitZoneUI.posX = Config.Window.width / 2 - Config.LimitZoneUI.width /2
Config.LimitZoneUI.posY = 0
Config.LimitZoneUI.height = Config.Window.height
end
-- This is call every frame to render thing on screen :
function love.draw()
-- Score :
Game.showUI()
-- Player :
love.graphics.rectangle("fill", Config.Player.posX, Config.Player.posY, Config.Paddle.width, Config.Paddle.height);
-- IA :
love.graphics.rectangle("fill", Config.IA.posX, Config.IA.posY, Config.Paddle.width, Config.Paddle.height);
-- Ball :
love.graphics.circle("fill", Config.Ball.posX, Config.Ball.posY, Config.Ball.radius)
-- Draw Menu :
Menu.draw()
end
-- This is call every frame usefull for logic like input control, game object movement ...
function love.update(dt)
-- Update the game focus mode :
Config.hasWindowFocus = love.window.hasFocus();
-- Control the input logic action :
Control.inputLogic(dt)
-- Check if the window lost focus then we show the pause menu :
if not Config.hasWindowFocus then
Config.isPaused = true
Menu.isVisible = true
end
if not Config.isPaused and not Menu.isVisible then
-- Check for collision :
Paddle.onCollisionEnter()
-- Update the velocity of the ball :
Ball.move(dt)
-- Update the IA :
Paddle.move(dt)
end
end
-- > used to show off error on debug mode :
local love_errorhandler = love.errhand
function love.errorhandler(msg)
if lldebugger then
error(msg, 2)
else
return love_errorhandler(msg)
end
end