-
Notifications
You must be signed in to change notification settings - Fork 10
Lua state
Lua is a popular scripting language for games. Through Rengine's Lua State you get access to a Lua interpreter, with most of Rengine's functionality exposed.
Links:
- The Lua Homepage
- A great introduction to Lua is the book Programming In Lua
These functions have global scope in the Lua script.
Writes a message to Rengine's log file.
Waits for millis
milliseconds, then calls func
Registers the function func
to be called every frame
Functions in the Game
scope
Changes the game's state to the state identified by newstate
Creates a particle at position (x,y), with color color
moving in direction (dx,dy) every frame.
The particle life
lasts for frames (So if the game's FPS is 33, then a life
value of 66 will mean the the particle will last for 2 seconds)
Retrieves a specific Style from the game.ini file.
The Bitmap object encapsulates a bitmap in the engine. Instances of BmpObj are drawn to the screen with the G.blit() function
Loads the bitmap file specified by filename
from the
Resources and returns it
encapsulated within a BmpObj
instance.
Returns a string representation of the BmpObj
instance.
Garbage collects the BmpObj
instance.
Sets the color used as a mask when the bitmap is drawn to the screen.
The Cell object. The CellObj encapsulates a collection of cells on the map. You then use the methods of the CellObj to manipulate the cells.
You use the C(selector) function to create a CellObj instance that collects all the cells on the maps that match the specific selector.
Returns a CellObj
instance that encapsulates all the
cells on a map that matches the particular selector.
Returns a string representation of the CellObj
Frees the CellObj when it is garbage collected.
Sets the specific layer of the cells encapsulated in the CellObj to
the si,ti
value, where
-
si
is the Set Index -
ti
is the Tile Index
G
is the Graphics object that allows you to draw primitives on the screen.
You can only call these functions when the screen is being drawn. That's to say, you can only call then inside
functions registered through onUpdate()
If you call them elsewhere, you will get the error "Call to graphics function outside of a screen update"
These fields are also available:
-
G.FPS
- The configured frames per second of the game (see game.ini). -
G.SCREEN_WIDTH
- The configured width of the screen. -
G.SCREEN_HEIGHT
- The configured height of the screen.
Sets the color used to draw the graphics primitives.
Plots a pixel at x,y
on the screen.
Draws a line from x0,y0
to x1,y1
Draws a rectangle from x0,y0
to x1,y1
Draws a filled rectangle from x0,y0
to x1,y1
Draws a circle centered at x,y
with radius r
Draws a filled circle centered at x,y
with radius r
Draws an ellipse from x0,y0
to x1,y1
Draws a rectangle from x0,y0
to x1,y1
with rounded corners of radius r
Draws a rectangle from x0,y0
to x1,y1
with rounded corners of radius r
Draws a Bezier curve from x0,y0
to x2,y2
with x1,y1
as the control point.
Note that it doesn't pass through x1,y1
Returns a color that is some fraction frac
along
the line from col1
to col2
.
For example, G.lerp("red", "blue", 0.33)
will return a color
that is 1/3rd of the way from red to blue.
Sets the font used for the G.print()
function.
Prints the text
to the screen, with its top left position at x,y
.
Returns the width,height in pixels that the text
will occupy on the screen.
Example:
local w,h = G.textDims(message);
Draws an instance bmp
of BmpObj
to the screen at dx, dy
.
sx,sy
specify the source x,y position and w,h
specifies the
width and height of the source to draw.
sx,sy
defaults to 0,0
and w,h
defaults to the entire
source bitmap.
Keyboard Input Functions
Checks whether a key is down on the keyboard.
The parameter key
is the name of specific key.
See http://wiki.libsdl.org/SDL_Scancode for the names of all the possible keys.
If key
is omitted, the function returns true if any key is down.
Resets the keyboard input.
Mouse input functions.
These constants are used with Mouse.down()
and Mouse.click()
to identify specific mouse buttons:
Mouse.LEFT
Mouse.MIDDLE
Mouse.RIGHT
Returns the x,y
position of the mouse.
Example:
local x,y = Mouse.position();
Returns true if the button btn
is down.
Returns true if the button btn
was clicked.
A button is considered clicked if it was down the
previous frame and is not anymore this frame.