mirror of
https://github.com/libretro/lutro-iyfct.git
synced 2024-11-23 07:59:43 +00:00
Added tunnels... somewhat.
This commit is contained in:
parent
d264ca269d
commit
0e9a7ec354
39
main.lua
39
main.lua
@ -1,6 +1,7 @@
|
||||
require("player")
|
||||
require("cloud")
|
||||
require("train")
|
||||
require("tunnel")
|
||||
|
||||
WIDTH = 300
|
||||
HEIGHT = 100
|
||||
@ -8,6 +9,8 @@ SCALE = 2
|
||||
SCRNWIDTH = WIDTH*SCALE
|
||||
SCRNHEIGHT = HEIGHT*SCALE
|
||||
|
||||
TRACK_SPEED = 150
|
||||
|
||||
track_quad = love.graphics.newQuad(0,48,121,5,128,128)
|
||||
|
||||
global_speed = 1.0
|
||||
@ -25,7 +28,10 @@ function love.load()
|
||||
track_frame = 0
|
||||
nextCloud = 0
|
||||
|
||||
train = Train.create(10,math.random(1,2))
|
||||
train = Train.create()
|
||||
train.alive = false
|
||||
tunnel = Tunnel.create()
|
||||
tunnel.alive = false
|
||||
train.x = -190
|
||||
end
|
||||
|
||||
@ -44,22 +50,28 @@ function love.update(dt)
|
||||
|
||||
-- Update trains
|
||||
Train.update(train,dt)
|
||||
if train.x < -200 then
|
||||
train.x = WIDTH
|
||||
train.speed = math.random(TRAIN_MIN_SPEED,TRAIN_MAX_SPEED)
|
||||
train.type = math.random(1,2)
|
||||
end
|
||||
|
||||
Player.collideWithTrain(pl)
|
||||
|
||||
-- Update tunnel
|
||||
Tunnel.update(tunnel,dt)
|
||||
|
||||
-- Move tracks
|
||||
track_frame = track_frame + global_speed * dt * 150
|
||||
track_frame = track_frame + global_speed * dt * TRACK_SPEED
|
||||
if track_frame >= 11 then
|
||||
track_frame = 0
|
||||
track_frame = track_frame % 11
|
||||
end
|
||||
|
||||
-- Increase speed
|
||||
global_speed = global_speed + 0.05*dt
|
||||
|
||||
-- Respawn train or tunnel
|
||||
if train.alive == false and tunnel.alive == false then
|
||||
if math.random(5) == 1 then -- spawn tunnel
|
||||
tunnel = Tunnel.create()
|
||||
else -- spawn train
|
||||
train = Train.create()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
@ -70,6 +82,9 @@ function love.draw()
|
||||
if v.speed < 37 then Cloud.draw(v) end
|
||||
end
|
||||
|
||||
-- Draw back of tunnel
|
||||
Tunnel.drawBack(tunnel)
|
||||
|
||||
-- Draw foreground clouds
|
||||
for i,v in ipairs(clouds) do
|
||||
if v.speed >= 37 then Cloud.draw(v) end
|
||||
@ -86,6 +101,9 @@ function love.draw()
|
||||
-- Draw player
|
||||
love.graphics.setColor(255,255,255,255)
|
||||
Player.draw(pl)
|
||||
|
||||
-- Draw front of tunnel
|
||||
Tunnel.drawFront(tunnel)
|
||||
end
|
||||
|
||||
function loadResources()
|
||||
@ -94,4 +112,7 @@ function loadResources()
|
||||
|
||||
imgTrains = love.graphics.newImage("gfx/trains.png")
|
||||
imgTrains:setFilter("nearest","nearest")
|
||||
|
||||
imgTerrain = love.graphics.newImage("gfx/terrain.png")
|
||||
imgTerrain:setFilter("nearest","nearest")
|
||||
end
|
||||
|
@ -71,6 +71,10 @@ function Player.draw(self)
|
||||
end
|
||||
|
||||
function Player.collideWithTrain(self)
|
||||
if train.alive == false then
|
||||
return
|
||||
end
|
||||
|
||||
if self.status == 0 then
|
||||
-- check collision with front of train
|
||||
if Player.collideWithPoint(self,train.x+4,train.y+10) or
|
||||
|
18
train.lua
18
train.lua
@ -6,20 +6,36 @@ inside_train_quad = love.graphics.newQuad(0,96,146,36,256,256)
|
||||
TRAIN_MIN_SPEED = 160
|
||||
TRAIN_MAX_SPEED = 220
|
||||
|
||||
function Train.create(speed,type)
|
||||
function Train.create()
|
||||
return Train.createWithParams(math.random(TRAIN_MIN_SPEED,TRAIN_MAX_SPEED),math.random(1,2))
|
||||
end
|
||||
|
||||
function Train.createWithParams(speed,type)
|
||||
local self = {}
|
||||
self.speed = speed
|
||||
self.x = WIDTH
|
||||
self.y = 56
|
||||
self.type = type
|
||||
self.alive = true
|
||||
return self
|
||||
end
|
||||
|
||||
function Train.update(self,dt)
|
||||
if self.alive == false then
|
||||
return
|
||||
end
|
||||
|
||||
self.x = self.x - self.speed*dt*global_speed
|
||||
if self.x < -146 then
|
||||
self.alive = false
|
||||
end
|
||||
end
|
||||
|
||||
function Train.draw(self)
|
||||
if self.alive == false then
|
||||
return
|
||||
end
|
||||
|
||||
if self.type == 1 then -- closed train
|
||||
love.graphics.drawq(imgTrains,normal_train_quad,self.x,self.y)
|
||||
elseif self.type == 2 then -- open train from outside
|
||||
|
Loading…
Reference in New Issue
Block a user