racing_stat_prototype #2
@ -3,10 +3,13 @@ local mode = {
|
||||
require("src.modes.raising_sim")
|
||||
};
|
||||
|
||||
local actor = require("src.entities.shared.actor")
|
||||
local player = actor.load("player")
|
||||
|
||||
local mode_i = 1
|
||||
|
||||
function love.load()
|
||||
mode[mode_i].load()
|
||||
mode[mode_i].load(player)
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
@ -23,6 +26,7 @@ function love.keyreleased(key, scancode)
|
||||
if (mode_i > 2) then
|
||||
mode_i = 1
|
||||
end
|
||||
mode[mode_i].load(player)
|
||||
end
|
||||
mode[mode_i].keyreleased(key, scancode)
|
||||
end
|
||||
|
||||
49
game/src/entities/racing/racer.lua
Normal file
49
game/src/entities/racing/racer.lua
Normal file
@ -0,0 +1,49 @@
|
||||
local entity = {}
|
||||
|
||||
entity.__index = entity
|
||||
|
||||
function entity.load(actor, finish)
|
||||
local self = setmetatable({}, entity)
|
||||
self.data = {
|
||||
pos = {0, 100, 0},
|
||||
color = {255/255, 255/255, 255/255},
|
||||
actor = actor,
|
||||
|
||||
current_speed = 0.0,
|
||||
current_accel = 0.0,
|
||||
|
||||
finish = finish
|
||||
}
|
||||
return self
|
||||
end
|
||||
|
||||
function entity:update(dt)
|
||||
if (self.data.pos[1] > self.data.finish[1]) then
|
||||
self.data.pos[1] = 0
|
||||
self.data.current_speed = 0
|
||||
self.data.current_accel = 0
|
||||
end
|
||||
self:accel(dt)
|
||||
self.data.pos[1] = self.data.pos[1] + self.data.current_speed * dt
|
||||
end
|
||||
|
||||
function entity:accel(dt)
|
||||
if (self.data.current_accel <= self.data.actor.data.accel) then
|
||||
self.data.current_accel = self.data.current_accel + dt
|
||||
end
|
||||
if (self.data.current_speed <= self.data.actor.data.max_speed) then
|
||||
self.data.current_speed = self.data.current_speed + self.data.current_accel * dt
|
||||
end
|
||||
end
|
||||
|
||||
function entity:draw()
|
||||
love.graphics.push()
|
||||
love.graphics.setColor(self.data.color[1], self.data.color[2], self.data.color[3])
|
||||
love.graphics.points(self.data.pos[1], self.data.pos[2])
|
||||
love.graphics.print(self.data.current_speed, self.data.pos[1], self.data.pos[2])
|
||||
love.graphics.print(string.format("Current Accel : %s", self.data.current_accel), 0, 40)
|
||||
love.graphics.pop()
|
||||
self.data.actor:draw()
|
||||
end
|
||||
|
||||
return entity
|
||||
41
game/src/entities/raising/trainee.lua
Normal file
41
game/src/entities/raising/trainee.lua
Normal file
@ -0,0 +1,41 @@
|
||||
local entity = {}
|
||||
|
||||
entity.__index = entity
|
||||
|
||||
function entity.load(actor)
|
||||
local self = setmetatable({}, entity)
|
||||
self.data = {
|
||||
actor = actor,
|
||||
|
||||
increase_max_speed = 1,
|
||||
increase_accel = 1
|
||||
}
|
||||
return self
|
||||
end
|
||||
|
||||
function entity:update(dt)
|
||||
|
||||
end
|
||||
|
||||
function entity:draw()
|
||||
love.graphics.push()
|
||||
love.graphics.print(string.format("[(a)-Max Speed+(d)] : %s", self.data.increase_max_speed), 0, 40)
|
||||
love.graphics.print(string.format("[(q)-Accel+(e)] : %s", self.data.increase_accel), 0, 60)
|
||||
love.graphics.pop()
|
||||
self.data.actor:draw()
|
||||
end
|
||||
|
||||
function entity:keyreleased(key, scancode)
|
||||
if (key == "a") then
|
||||
self.data.actor.data.max_speed = self.data.actor.data.max_speed - self.data.increase_max_speed
|
||||
elseif (key == "d") then
|
||||
self.data.actor.data.max_speed = self.data.actor.data.max_speed + self.data.increase_max_speed
|
||||
elseif (key == "q") then
|
||||
self.data.actor.data.accel = self.data.actor.data.accel - self.data.increase_accel
|
||||
elseif (key == "e") then
|
||||
self.data.actor.data.accel = self.data.actor.data.accel + self.data.increase_accel
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return entity
|
||||
26
game/src/entities/shared/actor.lua
Normal file
26
game/src/entities/shared/actor.lua
Normal file
@ -0,0 +1,26 @@
|
||||
local entity = {}
|
||||
|
||||
entity.__index = entity
|
||||
|
||||
function entity.load(name)
|
||||
local self = setmetatable({}, entity)
|
||||
self.data = {
|
||||
max_speed = 100.0,
|
||||
accel = 2.0,
|
||||
}
|
||||
return self
|
||||
end
|
||||
|
||||
function entity:update(dt)
|
||||
end
|
||||
|
||||
function entity:draw()
|
||||
love.graphics.push()
|
||||
love.graphics.print(string.format("Max Speed : %s", self.data.max_speed), 0, 0)
|
||||
love.graphics.print(string.format("Accel : %s", self.data.accel), 0, 20)
|
||||
love.graphics.pop()
|
||||
end
|
||||
|
||||
|
||||
|
||||
return entity
|
||||
@ -1,7 +1,7 @@
|
||||
local mode = {}
|
||||
|
||||
|
||||
function mode.load()
|
||||
function mode.load(player)
|
||||
|
||||
end
|
||||
|
||||
|
||||
@ -1,55 +1,13 @@
|
||||
local racer = require("src.entities.racing.racer")
|
||||
|
||||
local mode = {}
|
||||
|
||||
local finish = {100, 100, 0}
|
||||
|
||||
local entities = {
|
||||
racer = {
|
||||
pos = {0, 100, 0},
|
||||
color = {255/255, 255/255, 255/255},
|
||||
|
||||
race_stats = {
|
||||
max_speed = 100.0,
|
||||
accel = 2.0,
|
||||
current_speed = 2.0,
|
||||
current_accel = 0.0,
|
||||
},
|
||||
|
||||
draw = function (self)
|
||||
love.graphics.push()
|
||||
love.graphics.setColor(self.color[1], self.color[2], self.color[3])
|
||||
love.graphics.points(self.pos[1], self.pos[2])
|
||||
|
||||
love.graphics.print(self.race_stats.current_speed, self.pos[1], self.pos[2])
|
||||
|
||||
love.graphics.print(string.format("Max Speed : %s", self.race_stats.max_speed), 0, 0)
|
||||
love.graphics.print(string.format("Accel : %s", self.race_stats.accel), 0, 20)
|
||||
love.graphics.print(string.format("Current Accel : %s", self.race_stats.current_accel), 0, 40)
|
||||
love.graphics.pop()
|
||||
end,
|
||||
|
||||
update = function (self, dt)
|
||||
if (self.pos[1] > finish[1]) then
|
||||
self.pos[1] = 0
|
||||
self.race_stats.current_speed = 0
|
||||
self.race_stats.current_accel = 0
|
||||
end
|
||||
self:accel(dt)
|
||||
self.pos[1] = self.pos[1] + self.race_stats.current_speed * dt
|
||||
end,
|
||||
|
||||
accel = function(self, dt)
|
||||
if (self.race_stats.current_accel <= self.race_stats.accel) then
|
||||
self.race_stats.current_accel = self.race_stats.current_accel + dt
|
||||
end
|
||||
if (self.race_stats.current_speed <= self.race_stats.max_speed) then
|
||||
self.race_stats.current_speed = self.race_stats.current_speed + self.race_stats.current_accel
|
||||
end
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
function mode.load()
|
||||
local entities = {}
|
||||
|
||||
function mode.load(player)
|
||||
entities.racer = racer.load(player, finish)
|
||||
end
|
||||
|
||||
function mode.update(dt)
|
||||
|
||||
@ -1,21 +1,24 @@
|
||||
|
||||
local trainee = require("src.entities.raising.trainee")
|
||||
|
||||
local mode = {}
|
||||
|
||||
local entities = {
|
||||
|
||||
}
|
||||
|
||||
|
||||
function mode.load()
|
||||
local entities = {}
|
||||
|
||||
function mode.load(player)
|
||||
entities.trainee = trainee.load(player)
|
||||
end
|
||||
|
||||
function mode.update(dt)
|
||||
entities.trainee:update(dt)
|
||||
end
|
||||
|
||||
function mode.draw()
|
||||
entities.trainee:draw()
|
||||
end
|
||||
|
||||
function mode.keyreleased(key, scancode)
|
||||
entities.trainee:keyreleased(key, scancode)
|
||||
end
|
||||
|
||||
function mode.keypressed(key, scancode, isrepeat)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user