diff --git a/game/main.lua b/game/main.lua index 9d7cd2c..a1a5d59 100644 --- a/game/main.lua +++ b/game/main.lua @@ -1,3 +1,40 @@ +local mode = { + require("src.modes.racing"), + require("src.modes.raising_sim") +}; + +local actor = require("src.entities.shared.actor") +local player = actor.load("player") + +local mode_i = 1 + function love.load() - print("hello") + mode[mode_i].load(player) +end + +function love.update(dt) + mode[mode_i].update(dt) +end + +function love.draw() + mode[mode_i].draw() +end + +function love.keyreleased(key, scancode) + if (key == "right") then + mode_i = mode_i + 1 + if (mode_i > 2) then + mode_i = 1 + end + mode[mode_i].load(player) + end + mode[mode_i].keyreleased(key, scancode) +end + +function love.keypressed(key, scancode, isrepeat) + mode[mode_i].keypressed(key, scancode, isrepeat) +end + +function love.mousereleased(x, y, button, istouch, presses) + mode[mode_i].mousereleased(x, y, button, istouch, presses) end diff --git a/game/src/entities/racing/racer.lua b/game/src/entities/racing/racer.lua new file mode 100644 index 0000000..ef33feb --- /dev/null +++ b/game/src/entities/racing/racer.lua @@ -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 diff --git a/game/src/entities/raising/trainee.lua b/game/src/entities/raising/trainee.lua new file mode 100644 index 0000000..c7f8cb1 --- /dev/null +++ b/game/src/entities/raising/trainee.lua @@ -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 diff --git a/game/src/entities/shared/actor.lua b/game/src/entities/shared/actor.lua new file mode 100644 index 0000000..fc4d4de --- /dev/null +++ b/game/src/entities/shared/actor.lua @@ -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 diff --git a/game/src/modes/mode.lua b/game/src/modes/mode.lua new file mode 100644 index 0000000..52cc2da --- /dev/null +++ b/game/src/modes/mode.lua @@ -0,0 +1,24 @@ +local mode = {} + + +function mode.load(player) + +end + +function mode.update(dt) +end + +function mode.draw() +end + +function mode.keyreleased(key, scancode) +end + +function mode.keypressed(key, scancode, isrepeat) +end + +function mode.mousereleased(x, y, button, istouch, presses) +end + + +return mode diff --git a/game/src/modes/racing.lua b/game/src/modes/racing.lua new file mode 100644 index 0000000..e00d3ed --- /dev/null +++ b/game/src/modes/racing.lua @@ -0,0 +1,30 @@ +local racer = require("src.entities.racing.racer") + +local mode = {} + +local finish = {100, 100, 0} + +local entities = {} + +function mode.load(player) + entities.racer = racer.load(player, finish) +end + +function mode.update(dt) + entities.racer:update(dt) +end + +function mode.draw() + entities.racer:draw() +end + +function mode.keyreleased(key, scancode) +end + +function mode.keypressed(key, scancode, isrepeat) +end + +function mode.mousereleased(x, y, button, istouch, presses) +end + +return mode diff --git a/game/src/modes/raising_sim.lua b/game/src/modes/raising_sim.lua new file mode 100644 index 0000000..95afef6 --- /dev/null +++ b/game/src/modes/raising_sim.lua @@ -0,0 +1,31 @@ + +local trainee = require("src.entities.raising.trainee") + +local mode = {} + +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) +end + +function mode.mousereleased(x, y, button, istouch, presses) +end + + +return mode