Advertisement
Guest User

Untitled

a guest
Oct 19th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. - MAIN.LUA -
  2.  
  3. tiny = require("libs/tiny")
  4.  
  5. entity = {}
  6. entity2 = {}
  7.  
  8. local world
  9.  
  10. local inputSystem = require("systems/InputSystem")
  11. local renderSystem = require("systems/RenderSystem")
  12. local movementSystem = require("systems/MovementSystem")
  13.  
  14. function love.load()
  15.     entity = {
  16.        
  17.         controllable = true,
  18.        
  19.         position = {
  20.             x = 0,
  21.             y = 0
  22.         },
  23.        
  24.         velocity = {
  25.             x = 0,
  26.             y = 0
  27.         },
  28.        
  29.         render = {
  30.             text = "entity 1",
  31.         }
  32.     }
  33.    
  34.     entity2 = {
  35.        
  36.         position = {
  37.             x = 50,
  38.             y = 50
  39.         },
  40.        
  41.         render = {
  42.             text = "entity 2",
  43.         }
  44.     }
  45.            
  46.     world = tiny.world(inputSystem, renderSystem, movementSystem, entity, entity2 )
  47.    
  48. end
  49.  
  50. function love.update(_dt)
  51.  
  52.     world:update(_dt)
  53.    
  54. end
  55.  
  56. function love.draw()
  57.     world:update(renderSystem.filter)
  58. end
  59.  
  60. - INPUTSYSTEM.LUA -
  61.  
  62.  
  63. local InputSystem = tiny.processingSystem()
  64.  
  65. InputSystem.filter = tiny.requireAll("controllable", "velocity")
  66.  
  67. function InputSystem:init(_target)
  68.     self.target = _target
  69. end
  70.  
  71. function InputSystem:process(_e, _dt)
  72.  
  73.     print(_dt)
  74.  
  75.     if love.keyboard.isDown('d') then                    -- When the player presses and holds down the "D" button:
  76.         _e.velocity.x = _e.velocity.x + (300 * _dt)    -- The player moves to the right.
  77.     end
  78.     if love.keyboard.isDown('a') then                -- When the player presses and holds down the "A" button:
  79.         _e.velocity.x = _e.velocity.x - (300 * _dt)   -- The player moves to the left.
  80.     end
  81.     if love.keyboard.isDown('w') then
  82.         _e.velocity.y = _e.velocity.y - (300 * _dt)
  83.     end
  84.     if love.keyboard.isDown('s') then
  85.         _e.velocity.y = _e.velocity.y + (300 * _dt)
  86.     end
  87.  
  88. end
  89.  
  90. return InputSystem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement