diff --git a/cloud.lua b/cloud.lua index cd36602..c50e9fa 100644 --- a/cloud.lua +++ b/cloud.lua @@ -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 diff --git a/gfx/mockup.png b/gfx/mockup.png index a5bcf6c..41d81fb 100644 Binary files a/gfx/mockup.png and b/gfx/mockup.png differ diff --git a/main.lua b/main.lua index b516d91..e6e4d8d 100644 --- a/main.lua +++ b/main.lua @@ -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() diff --git a/player.lua b/player.lua index 511990b..6d42612 100644 --- a/player.lua +++ b/player.lua @@ -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,22 +56,32 @@ 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 - self.status = 1 -- hit by train - if self.y < train.y-9 then - self.y = train.y-9 + 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 + if train.x < self.x and train.x+125 > self.x then + if self.y > 35 then + self.y = 35 + self.yspeed = 0 + self.onGround = true end end end - -- check if landed on train - if train.x < self.x and train.x+125 > self.x then - if self.y > 35 then - self.y = 35 - self.yspeed = 0 - self.onGround = true + + if self.status == 3 then + if self.x > train.x+135 then + self.status = 0 end end end @@ -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 --]] diff --git a/train.lua b/train.lua index 44f8567..8f33184 100644 --- a/train.lua +++ b/train.lua @@ -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 - love.graphics.drawq(imgTrains,open_train_quad,self.x-7,self.y) + 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