diff --git a/Conceptual/List of comment tags.txt b/Conceptual/List of comment tags.txt index 491d6749..af51c83d 100644 --- a/Conceptual/List of comment tags.txt +++ b/Conceptual/List of comment tags.txt @@ -12,4 +12,6 @@ Tags: [DEMO3] - Something to be done by Demo 3. [FIX] - Code that needs to somehow be fixed. [WIP] - Code that is a work in progress and should not be removed or messed with except by its author (or with permission). -[HARDCODED] - Marks code that is hardcoded and should be made more flexible in the future. \ No newline at end of file +[HARDCODE] or [HARDCODED] - Marks code that is hardcoded and should be made more flexible in the future. +[TEMPORARY] - Code that will eventually be deleted +[CLEANUP] - Code that's nasty that needs to be cleaned up \ No newline at end of file diff --git a/Resources/Scripts/Modes/Demo3.lua b/Resources/Scripts/Modes/Demo3.lua index eb2343bc..16809416 100644 --- a/Resources/Scripts/Modes/Demo3.lua +++ b/Resources/Scripts/Modes/Demo3.lua @@ -45,8 +45,6 @@ end mouse_movement = false mousePos = vec(0, 0) mouseStart = 0 -cameraRatioOrig = nil -cameraRatioT = cameraRatio function init () start_time = mode_manager.time() @@ -138,40 +136,40 @@ function update () --]] --[[ this structure needs to be removed - if cameraRatioNum > 5 and cameraChanging == false then + if cameraRatio.num > 5 and cameraChanging == false then -- this is constantly modified, but not done smoothly, so it looks bad - if cameraRatioNum == 6 then + if cameraRatio.num == 6 then local diff = { x = math.abs(computerShip.physicsObject.position.x - playerShip.physicsObject.position.x) + computerShip.size.x / 2, y = math.abs(computerShip.physicsObject.position.y - playerShip.physicsObject.position.y) + computerShip.size.y / 2 } - cameraRatioOrig = cameraRatio + cameraRatio.orig = cameraRatio.curr if (math.abs(hypot1(diff) / hypot1(camera)) > 0.5) then cameraChanging = true x = 0.6 timeInterval = 0.6 - cameraRatioOrig = cameraRatio + cameraRatio.orig = cameraRatio.curr else if diff.x == 0 or diff.y == 0 or aspectRatio == 0 then - cameraRatio = 2 + cameraRatio.curr = 2 else - cameraRatio = (440) / (hypot1(diff) * 2) + cameraRatio.curr = (440) / (hypot1(diff) * 2) end end else - print("DONT DO EET") -- temp error message because cameraRatioNum is greater than 5 but not equal to 6, somehow + print("DONT DO EET") -- temp error message because cameraRatio.num is greater than 5 but not equal to 6, somehow end - if cameraRatio > 2 then - cameraRatio = 2 + if cameraRatio.curr > 2 then + cameraRatio.curr = 2 end - if (cameraRatio < 1 / 8 and cameraRatioOrig > 1 / 8) or (cameraRatio > 1 / 8 and cameraRatioOrig < 1 / 8) then + if (cameraRatio.curr < 1 / 8 and cameraRatio.orig > 1 / 8) or (cameraRatio.curr > 1 / 8 and cameraRatio.orig < 1 / 8) then sound.play("ZoomChange") end - camera = { w = 640 / cameraRatio, h } + camera = { w = 640 / cameraRatio.curr, h } camera.h = camera.w / aspectRatio shipAdjust = .045 * camera.w - arrowLength = ARROW_LENGTH / cameraRatio - arrowVar = ARROW_VAR / cameraRatio - arrowDist = ARROW_DIST / cameraRatio + arrowLength = ARROW_LENGTH / cameraRatio.curr + arrowVar = ARROW_VAR / cameraRatio.curr + arrowDist = ARROW_DIST / cameraRatio.curr end--]] if cameraChanging == true then @@ -179,20 +177,20 @@ function update () if x < 0 then x = 0 cameraChanging = false - playerShip.beam.width = cameraRatio + playerShip.beam.width = cameraRatio.curr soundJustPlayed = false end if x >= 0 then - cameraRatio = cameraRatioOrig + cameraRatioOrig * multiplier * math.pow(math.abs((x - timeInterval) / timeInterval), 2) --[[* (((x - timeInterval) * (x - timeInterval) * math.sqrt(math.abs(x - timeInterval))) / (timeInterval * timeInterval * math.sqrt(math.abs(timeInterval))))--]] - -- print(cameraRatio, timeInterval) + cameraRatio.curr = cameraRatio.orig + cameraRatio.orig * multiplier * math.pow(math.abs((x - timeInterval) / timeInterval), 2) --[[* (((x - timeInterval) * (x - timeInterval) * math.sqrt(math.abs(x - timeInterval))) / (timeInterval * timeInterval * math.sqrt(math.abs(timeInterval))))--]] + -- print(cameraRatio.curr, timeInterval) end - camera = { w = 640 / cameraRatio, h } + camera = { w = 640 / cameraRatio.curr, h } camera.h = camera.w / aspectRatio shipAdjust = .045 * camera.w - arrowLength = ARROW_LENGTH / cameraRatio - arrowVar = ARROW_VAR / cameraRatio - arrowDist = ARROW_DIST / cameraRatio - if (cameraRatio < 1 / 8 and cameraRatioOrig > 1 / 8) or (cameraRatio > 1 / 8 and cameraRatioOrig < 1 / 8) then + arrowLength = ARROW_LENGTH / cameraRatio.curr + arrowVar = ARROW_VAR / cameraRatio.curr + arrowDist = ARROW_DIST / cameraRatio.curr + if (cameraRatio.curr < 1 / 8 and cameraRatio.orig > 1 / 8) or (cameraRatio.curr > 1 / 8 and cameraRatio.orig < 1 / 8) then if soundJustPlayed == false then sound.play("ZoomChange") soundJustPlayed = true @@ -420,7 +418,7 @@ function render () else warpStatus = 0.0 end - graphics.begin_warp(warpStatus, (2.5*math.pi) - math.atan2(playerShip.physicsObject.velocity.x, playerShip.physicsObject.velocity.y), cameraRatio) + graphics.begin_warp(warpStatus, (2.5*math.pi) - math.atan2(playerShip.physicsObject.velocity.x, playerShip.physicsObject.velocity.y), cameraRatio.curr) -- extract camera coordinates from here during update() and place finalized numbers here graphics.set_camera(-playerShip.physicsObject.position.x + shipAdjust - (camera.w / 2.0), -playerShip.physicsObject.position.y - (camera.h / 2.0), -playerShip.physicsObject.position.x + shipAdjust + (camera.w / 2.0), -playerShip.physicsObject.position.y + (camera.h / 2.0)) graphics.draw_starfield(3.4) @@ -448,7 +446,7 @@ function render () graphics.draw_line({ x = i * GRID_DIST_BLUE, y = -60000 }, { x = i * GRID_DIST_BLUE, y = 60000 }, 1, ClutColour(4, 8)) end else - if cameraRatio > 1 / 8 then + if cameraRatio.curr > 1 / 8 then graphics.draw_line({ x = -60000, y = -i * GRID_DIST_BLUE }, { x = 60000, y = -i * GRID_DIST_BLUE }, 1, ClutColour(4, 11)) graphics.draw_line({ x = -60000, y = i * GRID_DIST_BLUE }, { x = 60000, y = i * GRID_DIST_BLUE }, 1, ClutColour(4, 11)) graphics.draw_line({ x = -i * GRID_DIST_BLUE, y = -60000 }, { x = -i * GRID_DIST_BLUE, y = 60000 }, 1, ClutColour(4, 11)) @@ -464,7 +462,7 @@ function render () function drawPlanet(planet) - if cameraRatio > 1 / 8 then + if cameraRatio.curr > 1 / 8 then local planetCoord = graphics.sprite_dimensions("Planets/" .. planet.image) graphics.draw_sprite("Planets/" .. planet.image, planet.position, planetCoord, 1) else @@ -484,7 +482,7 @@ function render () ------------------]]-- if computerShip ~= nil then if computerShip.life > 0 then - if cameraRatio > 1 / 8 then + if cameraRatio.curr > 1 / 8 then graphics.draw_sprite("Ships/Gaitori/Carrier", computerShip.physicsObject.position, computerShip.size, computerShip.physicsObject.angle) else graphics.draw_rdia(computerShip.physicsObject.position, 60, ClutColour(16, 1) ) @@ -493,7 +491,7 @@ function render () -- This explosion code is a hack. We need a way to deal with explosions in a better method. -- Let's figure it out when we get Sfiera's data if computerShip ~= nil then - if cameraRatio > 1 / 8 then + if cameraRatio.curr > 1 / 8 then graphics.draw_sprite(bestExplosion.image, computerShip.physicsObject.position, bestExplosion.size, frame / 6 * math.pi) end if frame == 0 then @@ -510,7 +508,7 @@ function render () if otherShip ~= nil then num = 1 while otherShip[num] ~= nil do - if cameraRatio > 1 / 8 then + if cameraRatio.curr > 1 / 8 then if otherShip[num].name ~= "Transport" then graphics.draw_sprite(otherShip[num].image, otherShip[num].physicsObject.position, otherShip[num].size, otherShip[num].physicsObject.angle) else @@ -558,7 +556,7 @@ function render () graphics.end_warp() - if cameraRatio > 1 / 8 then + if cameraRatio.curr > 1 / 8 then graphics.draw_sprite(playerShip.image, playerShip.physicsObject.position, playerShip.size, playerShip.physicsObject.angle) else graphics.draw_rtri(playerShip.physicsObject.position, 60) diff --git a/Resources/Scripts/Modes/Demo4.lua b/Resources/Scripts/Modes/Demo4.lua index d9d4cee8..963602ab 100644 --- a/Resources/Scripts/Modes/Demo4.lua +++ b/Resources/Scripts/Modes/Demo4.lua @@ -15,7 +15,7 @@ import('Physics') import('Effects') mdown = false -mrad = MOUSE_RADIUS / cameraRatio +mrad = MOUSE_RADIUS / cameraRatio.curr aimMethod = "smart" function init() @@ -291,7 +291,7 @@ function render() CameraToObject(scen.playerShip) - graphics.begin_warp(scen.playerShip.warp.factor,scen.playerShip.physics.angle, cameraRatio) + graphics.begin_warp(scen.playerShip.warp.factor,scen.playerShip.physics.angle, cameraRatio.curr) graphics.draw_starfield(3.4) graphics.draw_starfield(1.8) @@ -299,8 +299,8 @@ function render() graphics.draw_starfield(-0.3) graphics.draw_starfield(-0.9) - -- DEBUG version, keep: - -- graphics.end_warp(scen.playerShip.warp.factor, scen.playerShip.physics.angle, cameraRatio, scen.playerShip.physics.position) + -- DEBUG version, keep: + -- graphics.end_warp(scen.playerShip.warp.factor, scen.playerShip.physics.angle, cameraRatio.curr, scen.playerShip.physics.position) graphics.end_warp() DrawGrid() @@ -525,7 +525,7 @@ function DrawObject(o) end end else - if cameraRatio >= 1 / 4 then + if cameraRatio.curr >= 1 / 4 then if o.type == "animation" then graphics.draw_sprite_frame(o.gfx.sprite, o.physics.position, o.gfx.dimensions, Animate(o)) else -- Rotational @@ -542,7 +542,7 @@ function DrawObject(o) color = ClutColour(16,1) end - local iconScale = 1.0/cameraRatio + local iconScale = 1.0 / cameraRatio.curr if o.base["tiny-shape"] == "solid-square" then graphics.draw_rbox(o.physics.position, o.base["tiny-size"] * iconScale, color) elseif o.base["tiny-shape"] == "plus" then diff --git a/Resources/Scripts/Modules/Camera.lua b/Resources/Scripts/Modules/Camera.lua index 2b937445..26982e54 100644 --- a/Resources/Scripts/Modules/Camera.lua +++ b/Resources/Scripts/Modules/Camera.lua @@ -3,10 +3,23 @@ WINDOW.width, WINDOW.height = window.size() panels = { left = { width = 128, height = 768, center = { x = -WINDOW.width / 2, y = 0 } }, right = { width = 32, height = 768, center = { x = WINDOW.width / 2, y = 0 } } } -cameraRatio = 1 -cameraRatioTarget = 1 +--[[ + [CR CONVERT] + cameraRatio.curr - cameraRatio.curr + cameraRatio.target - cameraRatio.target + ??? - cameraRatio.num +--]] + +cameraRatio = { curr = 1, orig = 1, num = 2, target = 1 } +-- how this works when not zooming: curr = target = CAMERA_RATIO_OPTIONS[num] +-- when moving, zooming from curr = CAMERA_RATIO_OPTIONS[num] to target, set num +-- to the proper value once we reachy the target + +-- should I add a function that checks to make sure that the camera ratio is the +-- same as the target, and adjusting if not? [ADAM] [TODO] + aspectRatio = WINDOW.width / WINDOW.height -camera = { w = WINDOW.width / cameraRatio, h } +camera = { w = WINDOW.width / cameraRatio.curr, h } camera.h = camera.w / aspectRatio shipAdjust = .045 * camera.w timeInterval = 1 @@ -26,56 +39,55 @@ CAMERA_RATIO_OPTIONS = { function() -- Zoom to 2:1 return 2 end, + function() -- Zoom to 1:1 return 1 end, + function() -- Zoom to 1:2 return 1/2 end, - function() -- + + function() -- Zoom to 1:4 return 1/4 end, - function() + + function() -- Zoom to 1:16 return 1/16 end, + function() -- zoom to nearest hostile object return 1/8 -- [TEMP] [ADAM] [DEMO3] need to make the algorithm for this end, + function() -- zoom to nearest object return 1/9 -- [TEMP] [ADAM] [DEMO3] need to make the algorithm for this end, + function() -- zoom to all return 1/10 -- [TEMP] [ADAM] [DEMO3] need to make the algorithm for this end } -CAMERA_RATIO = { curr = 1, num = 2, target = 1 } --- how this works when not zooming: curr = target = CAMERA_RATIO_OPTIONS[num] --- when moving, zooming from curr = CAMERA_RATIO_OPTIONS[num] to target, set num --- to the proper value once we reachy the target - --- should I add a function that checks to make sure that the camera ratio is the --- same as the target, and adjusting if not? [ADAM] [TODO] - function CameraInterpolate(dt) -- note: this function now controlls both quadratic zooming and snap zooming (not good from a code design philosophy) if cameraChanging == true then zoomTime = zoomTime - dt if zoomTime < 0 then zoomTime = 0 cameraChanging = false --- scen.playerShip.weapon.beam.width = cameraRatio +-- scen.playerShip.weapon.beam.width = cameraRatio.curr soundJustPlayed = false end if zoomTime >= 0 then - cameraRatio = cameraRatioOrig + cameraRatioOrig * multiplier * math.pow(math.abs((timeInterval - zoomTime) / timeInterval), 2) --[[* (((x - timeInterval) * (x - timeInterval) * math.sqrt(math.abs(x - timeInterval))) / (timeInterval * timeInterval * math.sqrt(math.abs(timeInterval))))--]] + cameraRatio.curr = cameraRatio.orig + cameraRatio.orig * multiplier * math.pow(math.abs((timeInterval - zoomTime) / timeInterval), 2) --[[* (((x - timeInterval) * (x - timeInterval) * math.sqrt(math.abs(x - timeInterval))) / (timeInterval * timeInterval * math.sqrt(math.abs(timeInterval))))--]] end - camera = { w = WINDOW.width / cameraRatio, h } + camera = { w = WINDOW.width / cameraRatio.curr, h } camera.h = camera.w / aspectRatio shipAdjust = .045 * camera.w - arrowLength = ARROW_LENGTH / cameraRatio - arrowVar = ARROW_VAR / cameraRatio - arrowDist = ARROW_DIST / cameraRatio - if (cameraRatio < 1 / 4 and cameraRatioOrig > 1 / 4) or (cameraRatio > 1 / 4 and cameraRatioOrig < 1 / 4) then + arrowLength = ARROW_LENGTH / cameraRatio.curr + arrowVar = ARROW_VAR / cameraRatio.curr + arrowDist = ARROW_DIST / cameraRatio.curr + if (cameraRatio.curr < 1 / 4 and cameraRatio.orig > 1 / 4) or (cameraRatio.curr > 1 / 4 and cameraRatio.orig < 1 / 4) then if soundJustPlayed == false then sound.play("ZoomChange") soundJustPlayed = true @@ -100,13 +112,13 @@ end function CameraSnap() if cameraChanging == true then - cameraRatio = cameraRatioTarget - camera = { w = WINDOW.width / cameraRatio, h } + cameraRatio.curr = cameraRatio.target + camera = { w = WINDOW.width / cameraRatio.curr, h } camera.h = camera.w / aspectRatio shipAdjust = .045 * camera.w - arrowLength = ARROW_LENGTH / cameraRatio - arrowVar = ARROW_VAR / cameraRatio - arrowDist = ARROW_DIST / cameraRatio + arrowLength = ARROW_LENGTH / cameraRatio.curr + arrowVar = ARROW_VAR / cameraRatio.curr + arrowDist = ARROW_DIST / cameraRatio.curr end end @@ -114,20 +126,20 @@ end function InstantCamera(zoomLevel) zoomLevel = zoomLevel or 1 -- optional arguments, huzzah print(zoomLevel, "ZOOM LEVEL") - CAMERA_RATIO.target = CAMERA_RATIO_OPTIONS[zoomLevel]() -- currently, no error checking - CAMERA_RATIO.curr = CAMERA_RATIO.target + cameraRatio.target = CAMERA_RATIO_OPTIONS[zoomLevel]() -- currently, no error checking + cameraRatio.curr = cameraRatio.target ChangeCamAndWindow() UpdateWindow() end function ChangeCamAndWindow() - camera = { w = WINDOW.width / CAMERA_RATIO.curr, h } + camera = { w = WINDOW.width / cameraRatio.curr, h } camera.h = camera.w / aspectRatio shipAdjust = .045 * camera.w - arrowLength = ARROW_LENGTH / CAMERA_RATIO.curr - arrowVar = ARROW_VAR / CAMERA_RATIO.curr - arrowDist = ARROW_DIST / CAMERA_RATIO.curr + arrowLength = ARROW_LENGTH / cameraRatio.curr + arrowVar = ARROW_VAR / cameraRatio.curr + arrowDist = ARROW_DIST / cameraRatio.curr end function CameraToObject(object) diff --git a/Resources/Scripts/Modules/GlobalVars.lua b/Resources/Scripts/Modules/GlobalVars.lua index 0e90c730..791f716f 100644 --- a/Resources/Scripts/Modules/GlobalVars.lua +++ b/Resources/Scripts/Modules/GlobalVars.lua @@ -3,6 +3,12 @@ import('AresCLUT') import('data') import('Camera') +--[[ + [TODO] + This file needs to be better split into chunks so that the information is + decipherable. +--]] + RELEASE_BUILD = mode_manager.is_release() WARP_TIME = 1.2 diff --git a/Resources/Scripts/Modules/Interfaces.lua b/Resources/Scripts/Modules/Interfaces.lua index bb4c929b..f09ad955 100644 --- a/Resources/Scripts/Modules/Interfaces.lua +++ b/Resources/Scripts/Modules/Interfaces.lua @@ -316,10 +316,10 @@ radar = { top = 237, left = panels.left.center.x - 58, bottom = 127, right = pan function DrawRadar() graphics.draw_box(radar.top, radar.left, radar.bottom, radar.right, 0, ClutColour(5, 13)) -- background (dark green) - if cameraRatio <= 1 / 8 then + if cameraRatio.curr <= 1 / 8 then graphics.draw_box(radar.top, radar.left, radar.bottom, radar.right, 1, ClutColour(5, 11)) -- foreground (light green with edge) else - boxSize = (cameraRatio * 8 - 1) / cameraRatio / 16 + boxSize = (cameraRatio.curr * 8 - 1) / cameraRatio.curr / 16 graphics.draw_box(radar.top - radar.length * boxSize, radar.left + radar.width * boxSize, radar.bottom + radar.length * boxSize, radar.right - radar.width * boxSize, 0, ClutColour(5, 11)) end @@ -591,25 +591,25 @@ function DrawMouse1() else ship = scen.playerShip.physics.position - realPos.x = (mousePos.x - ship.x + shipAdjust) * cameraRatio - realPos.y = (mousePos.y - ship.y) * cameraRatio + realPos.x = (mousePos.x - ship.x + shipAdjust) * cameraRatio.curr + realPos.y = (mousePos.y - ship.y) * cameraRatio.curr if realPos.x > panels.right.center.x - panels.right.width / 2 - 10 then - mousePos.x = (panels.right.center.x - panels.right.width / 2 - 10) / cameraRatio - shipAdjust + ship.x + mousePos.x = (panels.right.center.x - panels.right.width / 2 - 10) / cameraRatio.curr - shipAdjust + ship.x elseif realPos.x < panels.left.center.x + panels.left.width / 2 then - mousePos.x = (panels.right.center.x + panels.right.width / 2) / cameraRatio - shipAdjust + ship.x + mousePos.x = (panels.right.center.x + panels.right.width / 2) / cameraRatio.curr - shipAdjust + ship.x end if realPos.y > WINDOW.height / 2 - 10 then - mousePos.y = (WINDOW.height / 2 - 10) / cameraRatio + ship.y + mousePos.y = (WINDOW.height / 2 - 10) / cameraRatio.curr + ship.y elseif realPos.y < -WINDOW.height / 2 + 10 then - mousePos.y = (-WINDOW.height / 2 + 10) / cameraRatio + ship.y + mousePos.y = (-WINDOW.height / 2 + 10) / cameraRatio.curr + ship.y end - graphics.draw_line({ x = - camera.w / 2 + ship.x, y = mousePos.y }, { x = mousePos.x - 20 / cameraRatio, y = mousePos.y }, 1.0, ClutColour(4, 8)) - graphics.draw_line({ x = camera.w / 2 + ship.x, y = mousePos.y }, { x = mousePos.x + 20 / cameraRatio, y = mousePos.y }, 1.0, ClutColour(4, 8)) - graphics.draw_line({ x = mousePos.x, y = -camera.h / 2 + ship.y }, { x = mousePos.x, y = mousePos.y - 20 / cameraRatio }, 1.0, ClutColour(4, 8)) - graphics.draw_line({ x = mousePos.x, y = camera.h / 2 + ship.y }, { x = mousePos.x, y = mousePos.y + 20 / cameraRatio }, 1.0, ClutColour(4, 8)) + graphics.draw_line({ x = - camera.w / 2 + ship.x, y = mousePos.y }, { x = mousePos.x - 20 / cameraRatio.curr, y = mousePos.y }, 1.0, ClutColour(4, 8)) + graphics.draw_line({ x = camera.w / 2 + ship.x, y = mousePos.y }, { x = mousePos.x + 20 / cameraRatio.curr, y = mousePos.y }, 1.0, ClutColour(4, 8)) + graphics.draw_line({ x = mousePos.x, y = -camera.h / 2 + ship.y }, { x = mousePos.x, y = mousePos.y - 20 / cameraRatio.curr }, 1.0, ClutColour(4, 8)) + graphics.draw_line({ x = mousePos.x, y = camera.h / 2 + ship.y }, { x = mousePos.x, y = mousePos.y + 20 / cameraRatio.curr }, 1.0, ClutColour(4, 8)) end end @@ -654,7 +654,7 @@ function DrawGrid() graphics.draw_line({ x = grid_x, y = scen.playerShip.physics.position.y - (camera.h / 2.0) }, { x = grid_x, y = scen.playerShip.physics.position.y + (camera.h / 2.0) }, 1, ClutColour(14, 9)) end else - if cameraRatio > 1 / 8 then + if cameraRatio.curr > 1 / 8 then graphics.draw_line({ x = grid_x, y = scen.playerShip.physics.position.y - (camera.h / 2.0) }, { x = grid_x, y = scen.playerShip.physics.position.y + (camera.h / 2.0) }, 1, ClutColour(4, 11)) end end @@ -671,7 +671,7 @@ function DrawGrid() graphics.draw_line({ x = scen.playerShip.physics.position.x - shipAdjust - (camera.w / 2.0), y = grid_y }, { x = scen.playerShip.physics.position.x - shipAdjust + (camera.w / 2.0), y = grid_y }, 1, ClutColour(14, 9)) end else - if cameraRatio > 1 / 8 then + if cameraRatio.curr > 1 / 8 then graphics.draw_line({ x = scen.playerShip.physics.position.x - shipAdjust - (camera.w / 2.0), y = grid_y }, { x = scen.playerShip.physics.position.x - shipAdjust + (camera.w / 2.0), y = grid_y }, 1, ClutColour(4, 11)) end end diff --git a/Resources/Scripts/Modules/KeyboardControl.lua b/Resources/Scripts/Modules/KeyboardControl.lua index 9d66e266..dcb77dcc 100644 --- a/Resources/Scripts/Modules/KeyboardControl.lua +++ b/Resources/Scripts/Modules/KeyboardControl.lua @@ -174,7 +174,7 @@ end function DoScaleIn(step) --[[ with all due respect this code is nasty local MAX_POW = 1 - local cameraPow = math.log(cameraRatioTarget)/math.log(2) + local cameraPow = math.log(cameraRatio.target)/math.log(2) if step == nil then if MAX_POW > math.floor(cameraPow) then cameraPow = math.floor(cameraPow) + 1 @@ -185,22 +185,22 @@ function DoScaleIn(step) local newRatio = 2^cameraPow - if newRatio ~= cameraRatio then + if newRatio ~= cameraRatio.curr then cameraChanging = true - cameraRatioTarget = newRatio - cameraRatioOrig = cameraRatio + cameraRatio.target = newRatio + cameraRatio.orig = cameraRatio.curr cameraSnap = false --if(zoomTime == 0) then -- prevents zoom speed from resetting if zoom setting is changed mid-zoom. zoomTime = timeInterval * 1 * (step or 0.5) --end - multiplier = (newRatio - cameraRatioOrig)/cameraRatioOrig + multiplier = (newRatio - cameraRatio.orig)/cameraRatio.orig end--]] if not RELEASE_BUILD then -- do instant change - if CAMERA_RATIO.num ~= 1 then - InstantCamera(CAMERA_RATIO.num - 1) - CAMERA_RATIO.num = CAMERA_RATIO.num - 1 + if cameraRatio.num ~= 1 then + InstantCamera(cameraRatio.num - 1) + cameraRatio.num = cameraRatio.num - 1 end else -- do ease-in (to be implemented later) @@ -212,7 +212,7 @@ end function DoScaleOut(step) --[[ with all due respect this code is nasty local MIN_POW = -6 - local cameraPow = math.log(cameraRatioTarget)/math.log(2) + local cameraPow = math.log(cameraRatio.target)/math.log(2) if step == nil then if MIN_POW < math.ceil(cameraPow) then cameraPow = math.ceil(cameraPow) - 1 @@ -223,22 +223,22 @@ function DoScaleOut(step) local newRatio = 2^cameraPow - if newRatio ~= cameraRatio then + if newRatio ~= cameraRatio.curr then cameraChanging = true - cameraRatioTarget = newRatio - cameraRatioOrig = cameraRatio + cameraRatio.target = newRatio + cameraRatio.orig = cameraRatio.curr cameraSnap = false --if(zoomTime == 0) then zoomTime = timeInterval * 2 * (step or 0.5) --end - multiplier = (newRatio - cameraRatio)/cameraRatio + multiplier = (newRatio - cameraRatio.curr)/cameraRatio.curr end--]] if not RELEASE_BUILD then -- do instant change - if CAMERA_RATIO.num ~= #CAMERA_RATIO_OPTIONS then - InstantCamera(CAMERA_RATIO.num + 1) - CAMERA_RATIO.num = CAMERA_RATIO.num + 1 + if cameraRatio.num ~= #CAMERA_RATIO_OPTIONS then + InstantCamera(cameraRatio.num + 1) + cameraRatio.num = cameraRatio.num + 1 end else -- do ease-in (to be implemented later) @@ -297,42 +297,42 @@ function DoTransferControl() end function DoZoom1_1() - if cameraRatioTarget ~= 1 then + if cameraRatio.target ~= 1 then cameraChanging = true - cameraRatioOrig = cameraRatio + cameraRatio.orig = cameraRatio.curr zoomTime = timeInterval - cameraRatioTarget = 1 - multiplier = (1 - cameraRatio) / cameraRatio + cameraRatio.target = 1 + multiplier = (1 - cameraRatio.curr) / cameraRatio.curr end end function DoZoom1_2() - if cameraRatioTarget ~= 1/2 then + if cameraRatio.target ~= 1/2 then cameraChanging = true - cameraRatioOrig = cameraRatio + cameraRatio.orig = cameraRatio.curr zoomTime = timeInterval - cameraRatioTarget = 1/2 - multiplier = (1/2 - cameraRatio) / cameraRatio + cameraRatio.target = 1/2 + multiplier = (1/2 - cameraRatio.curr) / cameraRatio.curr end end function DoZoom1_4() - if cameraRatioTarget ~= 1/4 then + if cameraRatio.target ~= 1/4 then cameraChanging = true - cameraRatioOrig = cameraRatio + cameraRatio.orig = cameraRatio.curr zoomTie = timeInterval - cameraRatioNum = 1/4 - multiplier = (1/4 - cameraRatio) / cameraRatio + cameraRatio.num = 1/4 + multiplier = (1/4 - cameraRatio.curr) / cameraRatio.curr end end function DoZoom1_16() - if cameraRatioTarget ~= 1/16 then + if cameraRatio.target ~= 1/16 then cameraChanging = true - cameraRatioOrig = cameraRatio + cameraRatio.orig = cameraRatio.curr zoomTime = timeInterval - cameraRatioTarget = 1/16 - multiplier = (1/16 - cameraRatio) / cameraRatio + cameraRatio.target = 1/16 + multiplier = (1/16 - cameraRatio.curr) / cameraRatio.curr end end @@ -345,7 +345,7 @@ function DoZoomHostile() -- zoomRadius = WINDOW.height -- end -- --- if cameraRatioNum ~= 6 then +-- if cameraRatio.num ~= 6 then --local diff = { x = computerShip.physicsObject.position.x - scen.playerShip.physicsObject.position.x, y = computerShip.physicsObject.position.y - scen.playerShip.physicsObject.position.y } -- local calculatedRatio = 0 -- @@ -354,8 +354,8 @@ function DoZoomHostile() -- else -- calculatedRatio = 640 / (diff.x * 2) -- end - cameraRatioOrig = cameraRatio - cameraRatioTarget = 1 / 4 + cameraRatio.orig = cameraRatio.curr + cameraRatio.target = 1 / 4 cameraSnap = true cameraChanging = true -- end