General functions
- game.init(title, width, height, bit_depth, fullscreen)
- Creates a window with the chosen title, a size in pixel
chosen by width and height and the chosen
bit_depth. The fullscreen parameter toggles
between fullscreen (true) or windowed mode
(false).
- game.getWindowWidth()
- Has to be called after game.init().
Returns the window width in pixels.
- game.getWindowHeight()
- Has to be called after game.init().
Returns the window height in pixels.
- game.getTicks()
- Has to be called after game.init().
Returns the number of milliseconds since the start of the
application.
- game.showCursor([show])
- If called without argument, returns the current state of the cursor
as boolean. Otherwise the state of the cursor is changed depending on
the boolean argument show.
- game.exit()
- A call to this function immediately exits the application.
- game.addFile(filename)
- Runs the file with the chosen filename.
- game.draw(table)
- This function can draw points, lines and polygons. The array part of
the table contains the list of x,y coordinate pairs of the
points. The interpretation of those points depends on several settings
made by the following key-value pairs. All of them are optional.
- color [= {255, 255, 255, 255}]
- This table sets the color of the point(s), line(s) or polygon(s)
to the given value. The first three elements are the red, green and
blue components of the color. The optional fourth value is the alpha
component. All four elements have to be in the range from 0 to 255.
The default color is opaque white.
- size [= 1]
- Sets the pixel size or line width to the chosen number. The
default value is 1.
- connect [= false]
- If this boolean value is true and if there are more than two
points a line will be drawn between the first and the second,
the second and the third and so on. The default value is false.
- fill [= false]
- If this boolean value is true the created shape will be filled
with the chosen color. The default value is false.
- antialiasing [= false]
- This boolean value activates or deactivates the anti-aliasing.
If it is true, pixels with a size greater one will become
circles and lines will blend nicely with the background.
The default value is false.
- pixellist [= false]
- If the boolean value pixellist is true, a point
will be drawn at each location given by the coordinate pairs. If it
is false and there is more than one point, the points will be interpreted
as one or more line(s) or as a polygon depending on the other options.
The default value is false.
Example
game.init("Draw Test - Click to test!", 600, 400, 32, false)
-- prepare one table for big white pixels
pixels = { antialiasing = false, size = 20, pixellist = true }
-- prepare one table for red connected lines
lines = { color = {255,0,0}, antialiasing = true, connect = true }
main = {
render = function(dt)
game.draw(lines)
game.draw(pixels)
end,
mousepressed = function(x, y, button)
-- add the point where the mouse was pressed to the list of pixels
pixels[#pixels+1] = x
pixels[#pixels+1] = y
-- add the point to the list of lines, too
lines[#lines+1] = x
lines[#lines+1] = y
end
}