-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscenehandler.lua
More file actions
78 lines (56 loc) · 2.84 KB
/
Copy pathscenehandler.lua
File metadata and controls
78 lines (56 loc) · 2.84 KB
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
_G.CURRENT_SCENE = "game"
_G.LAST_SCENE = ""
function LoadScene()
if CURRENT_SCENE == "game" then
--Begin scene setup for game
_G.ORIGINAL_ZOOM = 1 -- The original zoom, used as a default or for comparisons
_G.ZOOM = ORIGINAL_ZOOM -- The current zoom, used to determine the size of most things on screen
_G.ZOOM_MULT = ZOOM/ORIGINAL_ZOOM -- The value of ZOOM divided by ORIGINAL_ZOOM, used to get the intended size of things at a certain zoom
_G.ZOOM_LAGGED = ORIGINAL_ZOOM -- The zoom which will be used for rendering, it is ZOOM averaged over the last couple of frames to smooth the camera.
_G.CAMERA_OFFSET = vector.new(0,0)
_G.FOV_CHANGE_CALMER = 100
_G.FOV_CHANGE_LIMITER = function(fov) return math.max(5,fov) end
_G.GAME = ReturnGameTable()
love.graphics.setBackgroundColor(0.5, 0.5, 0.5)
--Changing the resolution while the game is running changes the player position, which is not ideal. At all. This is going to prevent this behaviour by changing the player position to account for it
_G.LAST_RES = RES
end
LAST_SCENE = CURRENT_SCENE
end
function UpdateScene(dt)
if CURRENT_SCENE == "game" then
CAMERA_POSITION = (CAMERA_OFFSET-GAME.player.state.position) -- 2D vector containing the X and Y position of the camera
PLAYER_SCREEN_POSITION = GAME.functions.getScreenPosition(GAME.player.state.position) -- Positon of the player as it appears on the screen, IE top left being 0,0 and the centre being RES/2
ZOOM = ORIGINAL_ZOOM -- I know its a bit (edit FUCK THAT, VERY) confusing but original zoom is copied to zoom so that the original value of 20 is not lost when changing zoom - i programmed it as i went along, okay?
while #GAME.enemies < 1 do
GAME.functions.SpawnEnemy()
end
-- Debug
if love.keyboard.isDown("down") then
ORIGINAL_ZOOM = ORIGINAL_ZOOM - 25*dt*ZOOM_MULT
end
if love.keyboard.isDown("up") then
ORIGINAL_ZOOM = ORIGINAL_ZOOM + 25*dt*ZOOM_MULT
end
--Kind of important
GAME.Progress(dt)
CAMERA_OFFSET, ZOOM_LAGGED = GAME.player.camera.Offset()
ZOOM_MULT = ZOOM_LAGGED/ORIGINAL_ZOOM
ZOOM_MULT_FOV = ZOOM - FovSizeCorrection()/ORIGINAL_ZOOM
--position_text = string.format("%s\n%s\n%s\n%s\n%s", GAME.player.state.position:floor(), GAME.player.state.speed:floor(), CAMERA_OFFSET:floor(), ZOOM_MULT, ZOOM)
end
end
function RenderScene()
if CURRENT_SCENE == "game" then
GAME.Render()
end
end
-- TODO CHANGE THIS ASAP
function ResChangeScene()
if CURRENT_SCENE == "game" then
GAME.player.state.position = GAME.player.state.position - PlayerOffsetAfterResChange()
end
end
function PlayerOffsetAfterResChange()
return ((RES - LAST_RES)/2)
end