1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- -- vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 autoindent:
- -- kate: space-indent on; indent-width 4; mixedindent off;
- -- Callback functions
- -- see http://www.love2d.org/wiki/Tutorial:Callback_Functions
- --
- -- for key constants, see http://www.love2d.org/wiki/KeyConstant
- --
- -- love.load() - at the game's start, used to initialise ressources
- -- love.update(dt) - the game loop function, where "dt" stands
- -- for the fraction of seconds since the function was called last
- -- love.draw() - graphics output loop
- -- love.mousepressed(x, y, button) - mouse down event callback function,
- -- where x, y the mouse's position, and button the number of the
- -- button pressed.
- -- love.mousereleased(x, y, button) - mouse button release event callback function,
- -- see mousepressed
- -- love.keypressed(key) - key press event callback function, where key is either
- -- a character, or any of the constants like "up", "down", "left", "right"
- -- love.keyreleased(key) - key release event callback function - see keypressed
- -- love.focus(f) - windows focus received/lost event callback function, where f
- -- is a boolean (true = focus gained, false = focus lost)
- -- love.quit - windows close event callback function
- require("init")
- require("players")
- function love.load()
- init.load()
- players.load()
- end
- function love.keypressed(key)
- if key == p1.keyleft then
- p1.direction = players.turnLeft(p1.direction)
- end
- -- what happens if p1 presses right?
- if key == p1.keyright then
- p1.direction = players.turnRight(p1.direction)
- end
- -- what happens if p2 presses left?
- if key == p2.keyleft then
- p2.direction = players.turnLeft(p2.direction)
- end
- -- what happens if p2 presses right?
- if key == p2.keyright then
- p2.direction = players.turnRight(p2.direction)
- end
- end
- function love.update(dt)
- update_players(dt)
- if love.keyboard.isDown(game_keyquit) then
- love.event.quit()
- end
- end
- function love.draw()
- -- Call our player drawing function
- draw_players()
- -- Some text over the Canvas
- love.graphics.setCanvas(canvas)
- love.graphics.setColor(text_color)
- font = love.graphics.newFont('SourceCodePro-Regular.ttf', 28)
- font:setFilter('linear')
- -- Set font before drawing text .. and something is wrong here...
- love.graphics.setFont(font);
- love.graphics.print ('p1:' .. p1.state .. ' p2:' .. p2.state , 25, 25, 0, 1, 1)
-
- -- Back to the screen
- love.graphics.setCanvas()
- love.graphics.setBackgroundColor(bg_color)
- -- Border
- love.graphics.setColor(border_color)
- love.graphics.rectangle("line", 0, 0, maxWidth - 1, maxHeight - 1)
- -- Draw the Player Canvas
- love.graphics.setColor(255, 255, 255, 255)
- love.graphics.draw(canvas)
- end
|