Implemented inside of trains and global raising speed

This commit is contained in:
SimonLarsen 2011-05-03 00:03:54 +02:00
parent 3fa2a7c92d
commit 0a7257188f
5 changed files with 43 additions and 16 deletions

View File

@ -7,7 +7,7 @@ function Cloud.create(y,size,type)
self.x = WIDTH
self.y = y
self.size = size
self.speed = math.random(25,50)
self.speed = global_speed*math.random(25,50)
self.type = type
self.alive = true
return self

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -10,6 +10,8 @@ SCRNHEIGHT = HEIGHT*SCALE
track_quad = love.graphics.newQuad(0,48,121,5,128,128)
global_speed = 1.0
function love.load()
love.graphics.setMode(SCRNWIDTH,SCRNHEIGHT,false)
love.graphics.setBackgroundColor(255,255,255)
@ -23,7 +25,7 @@ function love.load()
nextCloud = 0
train = Train.create(10,1)
train.x = -200
train.x = -190
end
function love.update(dt)
@ -43,17 +45,20 @@ function love.update(dt)
Train.update(train,dt)
if train.x < -200 then
train.x = WIDTH
train.speed = math.random(150,200)
train.speed = global_speed*math.random(TRAIN_MIN_SPEED,TRAIN_MAX_SPEED)
train.type = math.random(1,2)
end
Player.collideWithTrain(pl)
-- Move tracks
track_frame = track_frame + dt*150
track_frame = track_frame + global_speed * dt * 150
if track_frame >= 11 then
track_frame = 0
end
-- Increase speed
global_speed = global_speed + 0.05*dt
end
function love.draw()

View File

@ -37,6 +37,9 @@ function Player.update(self,dt)
elseif self.status == 1 then
self.x = train.x-10
elseif self.status == 3 then
self.y = 66
end
-- Update walk frame
@ -53,14 +56,17 @@ function Player.draw(self)
end
function Player.collideWithTrain(self)
if train.type == 1 then -- closed train
if self.status == 0 then
-- check collision with front of train
if Player.collideWithPoint(self,train.x+4,train.y+10) or
Player.collideWithPoint(self,train.x+2,train.y+24) then
if train.type == 1 then -- hit by closed train
self.status = 1 -- hit by train
if self.y < train.y-9 then
self.y = train.y-9
end
elseif train.type == 2 then -- hit by open train
self.status = 3
end
end
-- check if landed on train
@ -71,6 +77,13 @@ function Player.collideWithTrain(self)
self.onGround = true
end
end
end
if self.status == 3 then
if self.x > train.x+135 then
self.status = 0
end
end
end
function Player.collideWithPoint(self,x,y)
@ -85,5 +98,7 @@ end
--[[ Status values:
0 = alive
1 = hit by train
2 = hit by bird?
2 = hit by bird
3 = inside train
4 = falling through ground
--]]

View File

@ -3,6 +3,9 @@ normal_train_quad = love.graphics.newQuad(0,0,132,36,256,256)
open_train_quad = love.graphics.newQuad(0,48,146,36,256,256)
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)
local self = {}
self.speed = speed
@ -20,6 +23,10 @@ function Train.draw(self)
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
if pl.status == 3 then
love.graphics.drawq(imgTrains,inside_train_quad,self.x-7,self.y)
else
love.graphics.drawq(imgTrains,open_train_quad,self.x-7,self.y)
end
end
end