Characters can be either player controlled or computer controlled. They're meant to work with the grid module.
To use the module, it must be required somewhere in your code. To do this you use the require function. Make sure you save the result of require to a local variable otherwise you won't be able to use it!
local character = require("character")
newCharacter
Create a new character object
Creates a new character from an image name for use on a grid.
character.newCharacter(imageName)
- imageName The name of the image to use for the character's on screen representation.
gridSquare
The grid square the character is currently in or nil if they're off of the mapdisplayObject
The Corona ImageRect that displays the character
enter(gridSquare)
Moves the character into the given grid squareshow()
Makes the character visiblehide()
Hides the character from view
char:enter(gridSquare)
gridSquare
The specific GridSquare object to move the character into
local character = require("character")
local player = char.newCharacter("runner.png")
player:enter(somegrid[0][0])
local character = require("character")
local enemy = character.newCharacter("badguy.png")
function enemyTurn()
if enemy.gridSquare.x > player.gridSquare.x then
enemy:enter(enemy.gridSquare:left())
elseif enemy.gridSquare.x < player.gridSquare.x then
enemy:enter(enemy.gridSquare:right())
elseif enemy.gridSquare.y > player.gridSquare.y then
enemy:enter(enemy.gridSquare:above())
elseif enemy.gridSquare.y < player.gridSquare.y then
enemy:enter(enemy.gridSquare:below())
else
print("Captured the player!")
end
char:show()
char:hide()
enemyCharacter:enter(enemyCharacter.gridSquare:left())
if enemyCharacter.gridSquare.obstacle then
enemyCharacter:hide()
end
Reveal hidden enemies after a certain number of turns
if numberOfTurns > 5 then
enemyOne:show()
enemyTwo:show()
end