GameScene = Object.extend(Object) function GameScene:new() end function GameScene:init() GameScene:playerChanged(currentPlayer) movementDelta = 0 pSystem = love.graphics.newParticleSystem(boosterParticle,128) pSystem:setParticleLifetime(0,0.6) pSystem:setLinearAcceleration(0,20,0,25) pSystem:setSpeed(40,50) pSystem:setRotation(10,20) pSystem:setSpin(10,20) pSystem:setRadialAcceleration(10,20) pSystem:setTangentialAcceleration(10,20) pSystem:setSizeVariation(0.3) pSystem:setSizes(1,0.9,0.8,0.7,0.5,0.3,0.1,0.05) pSystem:setColors( 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,0.8, 1,1,1,0.6, 1,1,1,0.5, 1,1,1,0.4, 1,1,1,0.3 ) currentPlanet:init() currentPlanet:draw() end function GameScene:update(dt) pSystem:update(dt) GameScene:updateInput(dt) GameScene:updateBounds(dt) if currentPlanet ~= nil then love.graphics.print("hebebs",100,100); currentPlanet.update(dt) end end function GameScene:draw() love.graphics.setColor(255,255,255, 1) if currentPlanet ~= nil and currentPlanet.canvas ~= nil then love.graphics.draw(currentPlanet.canvas,0,0) end love.graphics.draw(pSystem, currentPlayer.px-2, currentPlayer.py) love.graphics.draw(pSystem, currentPlayer.px+2, currentPlayer.py) love.graphics.draw( currentPlayer.ship.image, currentPlayer.px, currentPlayer.py, currentPlayer.rot*(math.pi/180), 1, 1, currentPlayer.ship.image:getWidth()/2, currentPlayer.ship.image:getHeight()/2 ) love.graphics.print(currentPlayer.px..","..currentPlayer.py.." s: " .. currentPlayer.speed .. " a: " ..currentPlayer.acc,10,10) end function GameScene:drawHud() love.graphics.setColor(255,255,255, 1) love.graphics.draw( gameHud, 0, 600-66 ) love.graphics.setColor(255,255,255, 0.75) love.graphics.draw( currentPlayer.image, 14, 550, 0, 0.5, 0.5 ) love.graphics.setColor( text.r, text.g, text.b, text.alpha ) love.graphics.print( currentPlayer.name, 48, 550 ) love.graphics.print( currentPlayer:getShipname(), 48, 566 ) end function GameScene:keypressed(key,unicode) if key == "1" then GameScene:playerChanged(CaptainSteve) elseif key == "2" then GameScene:playerChanged(CaptainRobert) elseif key == "3" then GameScene:playerChanged(CaptainJohn) end end function GameScene:playerChanged(to) currentPlayer = to currentPlayer.px = windowWidth/2 currentPlayer.py = windowHeight/2 currentPlayer.rot = 0 currentPlayer.acc = 0 currentPlayer.bounds = { x1= 20, y1= 20, x2= windowWidth-20, y2= windowHeight - 86} end function GameScene:updateInput(dt) movementDelta = movementDelta + dt if (movementDelta > 0.02) then movementDelta = 0 local isUp = false local isLeft = false local isDown = false local isRight = false --local hAxis, vAxis, hAxis2, vAxis2 = love.joystick.getAxes(1) --local axisMargin = 0.5 isUp = love.keyboard.isDown( "w" )-- or (not (vAxis == nil) and vAxis < -(1-axisMargin)) or (not (vAxis2 == nil) and vAxis2 < -(1-axisMargin)) or love.joystick.isDown(1, 1) isDown = love.keyboard.isDown( "s" )-- or (not (vAxis == nil) and vAxis > (1-axisMargin)) or (not (vAxis2 == nil) and vAxis2 > (1-axisMargin)) or love.joystick.isDown(1, 2) isLeft = love.keyboard.isDown( "a" )-- or (not (hAxis == nil) and hAxis < -(1-axisMargin)) or (not (hAxis2 == nil) and hAxis2 < -(1-axisMargin)) or love.joystick.isDown(1, 3) isRight = love.keyboard.isDown( "d" )-- or (not (hAxis == nil) and hAxis > (1-axisMargin)) or (not (hAxis2 == nil) and hAxis2 > (1-axisMargin)) or love.joystick.isDown(1, 4) if isUp and isLeft then currentPlayer.rot = 315 particleRot = 45 elseif isUp and isRight then currentPlayer.rot = 45 particleRot = 135 elseif isUp then currentPlayer.rot = 0 particleRot = 90 elseif isDown and isLeft then currentPlayer.rot = 225 particleRot = 315 elseif isDown and isRight then currentPlayer.rot = 135 particleRot = 225 elseif isDown then currentPlayer.rot = 180 particleRot = 270 elseif isLeft then currentPlayer.rot = 270 particleRot = 0 elseif isRight then currentPlayer.rot = 90 particleRot = 180 end if isUp or isDown or isLeft or isRight then currentPlayer.acc = currentPlayer.acc + currentPlayer.accIncr elseif currentPlayer.acc > 0 then currentPlayer.acc = currentPlayer.acc - currentPlayer.accIncr end currentPlayer.acc = math.clamp(0, currentPlayer.acc, 1) if currentPlayer.acc > 0 then pSystem:setDirection(particleRot*(math.pi/180)) pSystem:emit( 64 * currentPlayer.acc ) end if isUp then currentPlayer.py = currentPlayer.py - (currentPlayer.speed*currentPlayer.acc) end if isDown then currentPlayer.py = currentPlayer.py + (currentPlayer.speed*currentPlayer.acc) end if isLeft then currentPlayer.px = currentPlayer.px - (currentPlayer.speed*currentPlayer.acc) end if isRight then currentPlayer.px = currentPlayer.px + (currentPlayer.speed*currentPlayer.acc) end end end function GameScene:updateBounds(dt) currentPlayer.px = math.clamp( currentPlayer.bounds.x1, currentPlayer.px, currentPlayer.bounds.x2 ) currentPlayer.py = math.clamp( currentPlayer.bounds.y1, currentPlayer.py, currentPlayer.bounds.y2 ) end