Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
togfoxy committed Oct 18, 2021
1 parent 95fd4f7 commit d822bf8
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 24 deletions.
2 changes: 2 additions & 0 deletions source/createobjects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function createobjects.CreateLander()
Lander.vy = 0
Lander.engineOn = false
Lander.landed = false
Lander.wealth = 0
Lander.mass = {}
table.insert(Lander.mass, 100) -- base mass of lander

Expand All @@ -36,6 +37,7 @@ function createobjects.CreateObject(intType, intXValue)
mybase.objecttype = intType -- 2 = a fuel base
mybase.fuelqty = 0
mybase.active = true
mybase.paid = false -- set true when lander lands and pays player. Ensures bases only pay once

if intType == 2 then
mybase.fuelqty = 15
Expand Down
21 changes: 17 additions & 4 deletions source/drawobjects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,23 @@ local function DrawOffscreenIndicator(worldoffset)

end

local function DrawWealth()

love.graphics.setNewFont(20)
love.graphics.print("$" .. garrLanders[1].wealth, gintScreenWidth - 100, 15)


end

function HUD.draw(worldoffset)

DrawFuelIndicator()

-- offscreen indicator
DrawOffscreenIndicator(worldoffset)

DrawWealth()

end

local function DrawSurface(worldoffset)
Expand Down Expand Up @@ -110,16 +120,21 @@ local function DrawObjects(worldoffset)
end
if objectvalue == 2 then
if garrGround[xvalue - worldoffset] ~= nil then
love.graphics.draw(garrImages[2], xvalue - worldoffset, garrGround[xvalue] - garrImages[2]:getHeight())

local drawingx = xvalue - worldoffset
local drawingy = garrGround[xvalue] - garrImages[2]:getHeight()

love.graphics.draw(garrImages[2], drawingx, drawingy)
gLandingLightsAnimation:draw(garrSprites[1], drawingx + (garrImages[2]:getWidth() - 10 ), drawingy + garrImages[2]:getHeight()) -- the -10 bit is a small adjustment as the png file is not quite right
end
end
end

end
end

local function DrawDebug()

love.graphics.setNewFont(14)
love.graphics.print("Mass = " .. cf.round(fun.GetLanderMass(),2), 5, 15)
love.graphics.print("Fuel = " .. cf.round(garrLanders[1].fuel,2), 5, 30)
love.graphics.print("Mass ratio: " .. cf.round(garrMassRatio,2), 125,15)
Expand All @@ -146,8 +161,6 @@ local function DrawWallPaper()
love.graphics.draw(garrImages[3],0,0)
end



function drawobjects.DrawWorld()
-- draw the spaceship and flame and other bits

Expand Down
27 changes: 16 additions & 11 deletions source/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ function functions.GetMoreTerrain(intAmountToCreate)
end

-- reapply smoothing around the base
for i = groundtablesize + 1, groundtablesize + intAmountToCreate do
if garrObjects[i] ~= nil then
fun.CreateBase(garrObjects[i],i)
end
end
-- for i = groundtablesize + 1, groundtablesize + intAmountToCreate do
-- if garrObjects[i] ~= nil then
-- fun.CreateBase(garrObjects[i],i)
-- end
-- end
end

function functions.GetLanderMass()
Expand Down Expand Up @@ -86,7 +86,6 @@ function functions.SaveGame()

end


function functions.LoadGame()

local savedir = love.filesystem.getSource()
Expand Down Expand Up @@ -115,20 +114,26 @@ function functions.GetDistanceToClosestBase(intBaseType)
-- if there are no bases (impossible) then the distance value returned will be -1
-- note: if distance is a negative value then the Lander has not yet passed the base

local closestdistance = -1
local closestdistance = 0
local closestbase = {}
local absdist
local dist

for k,v in pairs(garrObjects) do
if v.objecttype == intBaseType then
local dist = math.abs(garrLanders[1].x - v.x)
if closestdistance < 0 or dist <= closestdistance then
closestdistance = dist
absdist = math.abs(garrLanders[1].x - (v.x + 85)) -- the + bit is an offset to calculate the landing pad and not the image
dist = (garrLanders[1].x - (v.x + 85)) -- same but without the math.abs
if closestdistance == 0 or absdist <= closestdistance then
closestdistance = absdist
closestbase = v
end
end
end

-- now we have the closest base, work out the distance to the landing pad for that base
local realdist = garrLanders[1].x - (closestbase.x + 85) -- the + bit is an offset to calculate the landing pad and not the image

return garrLanders[1].x - closestbase.x, closestbase
return realdist, closestbase

end

Expand Down
Binary file added source/ground.dat
Binary file not shown.
Binary file added source/landers.dat
Binary file not shown.
51 changes: 43 additions & 8 deletions source/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ bitser = require 'bitser'
nativefs = require("nativefs")
-- https://github.com/megagrump/nativefs

anim8 = require 'anim8'
-- https://github.com/kikito/anim8

gintScreenWidth = 1024-- 1920
gintScreenHeight = 768-- 1080
garrCurrentScreen = {}
Expand All @@ -29,6 +32,7 @@ garrLanders = {}
garrGround = {} -- stores the y value for the ground so that garrGround[Lander.x] = a value from 0 -> gintScreenHeight
garrObjects = {} -- stores an object that needs to be drawn so that garrObjects[xvalue] = an object to be drawn on the ground
garrImages = {}
garrSprites = {} -- spritesheets
garrSound = {}

gintOriginX = cf.round(gintScreenWidth / 2,0) -- this is the start of the world and the origin that we track as we scroll the terrain left and right
Expand Down Expand Up @@ -99,12 +103,11 @@ local function MoveShip(Lander, dt)
end
end



local function RefuelLander(objBase)
local function RefuelLander(objBase, dt)
-- drain fuel from the base and add it to the lander
-- objBase is an object/table item from garrObjects

local refuelamt = math.min(objBase.fuelqty, (garrLanders[1].fueltanksize - garrLanders[1].fuel))
local refuelamt = math.min(objBase.fuelqty, (garrLanders[1].fueltanksize - garrLanders[1].fuel), dt)

objBase.fuelqty = objBase.fuelqty - refuelamt
garrLanders[1].fuel = garrLanders[1].fuel + refuelamt
Expand All @@ -114,7 +117,21 @@ local function RefuelLander(objBase)

end

local function CheckForContact(Lander)
local function PayLander(objBase, fltDist)
-- pay some wealth based on distance to the base
-- objBase is an object/table item from garrObjects
-- fltDist is the distance from the base

local dist = math.abs(fltDist)
if objBase.paid == false then
garrLanders[1].wealth = cf.round(garrLanders[1].wealth + (100 - dist),0)
garrSound[4]:play()
objBase.paid = true
end

end

local function CheckForContact(Lander,dt)
-- see if lander has contacted the ground

local LanderXValue = cf.round(Lander.x)
Expand All @@ -133,9 +150,14 @@ local function CheckForContact(Lander)
if Lander.vy > 0 then Lander.vy = 0 end

-- see if landed near a fuel base
-- bestdist could be a negative number meaning not yet past the base (but maybe really close to it)
local bestdist, bestbase = fun.GetDistanceToClosestBase(2) -- 2 = type of base = fuel
if bestdist <= 125 and bestdist > 0 then
RefuelLander(bestbase)

-- bestbase is an object/table item
if bestdist >= -80 and bestdist <= 40 then
RefuelLander(bestbase,dt)
PayLander(bestbase, bestdist)

end

else
Expand Down Expand Up @@ -186,16 +208,27 @@ function love.load()
-- capture the 'normal' mass of the lander into a global variable
gintDefaultMass = fun.GetLanderMass()

-- stills/images
garrImages[1] = love.graphics.newImage("/Assets/tower.png")
garrImages[2] = love.graphics.newImage("/Assets/gastank.png")
garrImages[3] = love.graphics.newImage("/Assets/Background-4.png")
garrImages[4] = love.graphics.newImage("/Assets/engine.png")
garrImages[5] = love.graphics.newImage("/Assets/ship.png")

-- spritesheets and animations
garrSprites[1] = love.graphics.newImage("assets/landinglights.png")
gGridLandingLights = anim8.newGrid(64, 8, garrSprites[1]:getWidth(), garrSprites[1]:getHeight()) -- frame width, frame height
gLandingLightsAnimation = anim8.newAnimation(gGridLandingLights(1,'1-4'), 0.5) -- column 1, rows 1 -> 4


garrSound[1] = love.audio.newSource("Assets/wind.wav", "static")
garrSound[2] = love.audio.newSource("Assets/387232__steaq__badge-coin-win.wav", "static")
garrSound[3] = love.audio.newSource("Assets/Galactic-Pole-Position.mp3", "stream")
garrSound[3]:setVolume(0.25)
garrSound[4] = love.audio.newSource("Assets/387232__steaq__badge-coin-win.wav", "static")

-- fonts
font20 = love.graphics.newFont(20) -- the number denotes the font size

Slab.Initialize(args)

Expand Down Expand Up @@ -254,7 +287,9 @@ function love.update(dt)

PlaySoundEffects()

CheckForContact(garrLanders[1])
CheckForContact(garrLanders[1], dt)

gLandingLightsAnimation:update(dt)
end


Expand Down
2 changes: 1 addition & 1 deletion source/menus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local menus = {}

function menus.DrawMainMenu()
local intSlabWidth = 205 -- the width of the main menu slab. Change this to change appearance.
local intSlabHeight = 325 -- the height of the main menu slab
local intSlabHeight = 350 -- the height of the main menu slab
local fltSlabWindowX = love.graphics.getWidth() / 2 - intSlabWidth / 2
local fltSlabWindowY = love.graphics.getHeight() / 2 - intSlabHeight / 2

Expand Down
Binary file added source/objects.dat
Binary file not shown.

0 comments on commit d822bf8

Please sign in to comment.