lcurses with love
Posted: Tue Jan 15, 2013 5:07 pm
Hello, y'all.
I've been trying to use lcurse's graphical interface with love's input and audio modules on a simple game.
To do this, I:
I've installed lcurses through luarocks and properly require'd it on the code.
Here's the full source:
I've been trying to use lcurse's graphical interface with love's input and audio modules on a simple game.
To do this, I:
- Disabled love's image and graphic's mode through conf.lua
- Stopped calling any visual-related functions (love.draw()/love.focus()/etc)
- Initialized curses
I've installed lcurses through luarocks and properly require'd it on the code.
Here's the full source:
Code: Select all
-- oh yeah
require 'curses'
function love.load()
curses_init()
player_x, player_y = 0, 0
end
function curses_init()
screen = nil
curses.initscr() -- start curses
curses.cbreak() -- will wait for input
curses.echo(0) -- won't show input characters
curses.noln(0) -- use line-feed capability ('man 3 nl')
screen = curses.stdscr()
screen:clear()
screen:mvaddstr(3, 3, "Curses Initialized!")
screen:refresh()
end
-- treats input
function love.keypressed(key, unicode)
if key == 'd' or key == 'right' then
player_x = player_x + 1
elseif key == 's' or key == 'down' then
player_y = player_y + 1
elseif key == 'w' or key == 'up' then
player_y = player_y - 1
elseif key == 'a' or key == 'left' then
player_x = player_x - 1
elseif key == 'q' then
quit_game()
end
end
function love.update()
screen:mvaddch(player_y, player_x, '#')
end
-- This works around an issue on quitting between love versions.
function quit_game()
local f = love.event.quit or love.event.push
f('q')
end