Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - MAIN.LUA -
- tiny = require("libs/tiny")
- entity = {}
- entity2 = {}
- local world
- local inputSystem = require("systems/InputSystem")
- local renderSystem = require("systems/RenderSystem")
- local movementSystem = require("systems/MovementSystem")
- function love.load()
- entity = {
- controllable = true,
- position = {
- x = 0,
- y = 0
- },
- velocity = {
- x = 0,
- y = 0
- },
- render = {
- text = "entity 1",
- }
- }
- entity2 = {
- position = {
- x = 50,
- y = 50
- },
- render = {
- text = "entity 2",
- }
- }
- world = tiny.world(inputSystem, renderSystem, movementSystem, entity, entity2 )
- end
- function love.update(_dt)
- world:update(_dt)
- end
- function love.draw()
- world:update(renderSystem.filter)
- end
- - INPUTSYSTEM.LUA -
- local InputSystem = tiny.processingSystem()
- InputSystem.filter = tiny.requireAll("controllable", "velocity")
- function InputSystem:init(_target)
- self.target = _target
- end
- function InputSystem:process(_e, _dt)
- print(_dt)
- if love.keyboard.isDown('d') then -- When the player presses and holds down the "D" button:
- _e.velocity.x = _e.velocity.x + (300 * _dt) -- The player moves to the right.
- end
- if love.keyboard.isDown('a') then -- When the player presses and holds down the "A" button:
- _e.velocity.x = _e.velocity.x - (300 * _dt) -- The player moves to the left.
- end
- if love.keyboard.isDown('w') then
- _e.velocity.y = _e.velocity.y - (300 * _dt)
- end
- if love.keyboard.isDown('s') then
- _e.velocity.y = _e.velocity.y + (300 * _dt)
- end
- end
- return InputSystem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement