|
Asleep...
Join Date: Oct 2005
Posts: 1,382
|
Lua Help :(
my code wont work, its spposed to load the menu, push something, and load level. my code:
Quote:
CODE:
tiles = Image.load("data/tiles.png")
figure = Image.load("data/figure.png")
menu = Image.load("data/menu.png")
white = Color.new(255, 255, 255)
-- Menu
onmenu = 1
-- Menu Control
menuy = 100
-- Menu Time
menutime = 0
-- Current Level
level = 1
-- Level Score
levelscore = 0
-- Score
score = 0
function level1()
-- the map
mapSource = {
"mmmmmmmmmmmmmmmmmmmmmmmm m mmmmm",
"meaaaaaaaaaaaaaaaaaaaafa a aaafm",
"mdnnnnbnnnnnnnnnnnnonndn n npnbm",
"mdnonnbnnnnnbnnnnnnnnndn n nnnbm",
"mdnnnnnnnbnnbnnccccccchc c ccnnm",
"mecccccccgnnnnnnnnnnnndn b nnnbm",
"mdnnnnnnnnnnnnnnnnnnnndn b nnnbm",
"mdnnnnnnnnnnnnnnnnbnnndc c nnnbm",
"mdnnecccccccccccnnbnnndn n nnnbm",
"mdnnbnnnnnbnnnnbnnbnnndn n nnnbm",
"mdnnbnnonnbnnonbnnbnnndn n nnnbm",
"mdnnbnnnnnbnnnnbnnbnnndn n nccbm",
"mdnnbnnccccnnnnbnnbnnndn n nnnbm",
"mdnnbnnnnnnnnnnnnnbnnnnn n nnnbm",
"mdnnbnnnnnnnnnnnnnbnnnnn n nnnbm",
"mhccgcccccccccccccgccccc c cccgm",
"mmmmmmmmmmmmmmmmmmmmmmmm m mmmmm"
}
-- offsreen image, where the map will be drawn
board = Image.createEmpty(480, 272)
-- draw one tile on the map
function drawTile(tile, x, y)
tile = string.byte(tile, 1) - string.byte("a")
local tileX = math.mod(tile, 4)
local tileY = math.floor(tile / 4)
board:blit(16 * x, 16 * y, tiles, 17 * tileX + 1, 17 * tileY + 1, 16, 16, false)
end
-- copy the map source to an array for easier access and draw the offscreen board
map = {}
for y = 1, 17 do
line = mapSource[y]
map[y] = {}
for x = 1, 30 do
tile = string.sub(line, x, x)
map[y][x] = tile
drawTile(tile, x - 1, y - 1)
end
end
-- current player position
playerX = 3
playerY = 14
-- current player animation image
animation = 0
-- 1 = animation images increases, -1: decreases
animationDirection = 1
-- animation slowdown counter
animationSlowDown = 0
-- controls the movement speed. At speedStep == 0, the last
-- pad will be evaluated, other steps the pad movements are only
-- saved
speedStep = 0
-- last pad direction
dx = 0
dy = 0
-- current score
score = 0
-- text color
white = Color.new(255, 255, 255)
while true do
-- read current pad
pad = Controls.read()
if pad:start() then
-- exit to lowser, if started from there
break
end
if speedStep == 0 then
-- save old player position
oldPlayerX = playerX
oldPlayerY = playerY
-- add last movement
playerX = playerX + dx
playerY = playerY + dy
-- check new tile
newTile = map[playerY][playerX]
-- if the position is not allowed, restore old player position
if newTile ~= "n" and newTile ~= "p" and newTile ~= "o" then
playerX = oldPlayerX
playerY = oldPlayerY
end
-- if it is a tile which can be eaten, eat it
if newTile == "p" then score = score + 5 end
if newTile == "o" then score = score + 1 end
if newTile == "p" or newTile == "o" then
-- set background tile
map[playerY][playerX] = "n"
-- draw background tile
drawTile("n", playerX - 1, playerY - 1)
end
-- reset last movement
dx = 0
dy = 0
else
-- check pad movement
if pad:up() then
dy = -1
elseif pad:down() then
dy = 1
elseif pad:left() then
dx = -1
elseif pad:right() then
dx = 1
end
end
-- update speed step counter
speedStep = speedStep + 1
if speedStep == 5 then
speedStep = -1
end
-- blit board
screen:blit(0, 0, board, 0, 0, board:width(), board:height(), false)
-- blit current player animation image
screen:blit((playerX - 1) * 16 - 4, (playerY - 1) * 16 - 4, figure, 1 + 25 * animation, 1, 24, 24)
-- calculate next animation image
animationSlowDown = animationSlowDown + 1
if animationSlowDown == 3 then
animationSlowDown = 0
animation = animation + animationDirection
if animation == 4 then
animationDirection = -1
elseif animation == 0 then
animationDirection = 1
end
end
-- print score
screenrint(10, 260, "BY HEDZX, SCORE:" .. score, white)
-- wait for vertical sync and show new screen
screen.waitVblankStart()
screen:flip()
end
while true do
-- Clear Screen
screen:clear()
-- Show Background
showbackground()
-- Menu
if onmenu == 1 then
screen:blit(165,80, menu)
mainmenuscreen()
screenrint(198, 100, "Start", white)
pad2 = Controls.read()
if pad2:up() then
if menutime == 0 then
if menuy > 100 then
menuy = menuy - 10
end
menutime = 1
end
end
if pad2:down() then
if menutime == 0 then
if menuy < 120 then
menuy = menuy + 10
end
menutime = 1
end
end
if pad2:cross() then
if menuy == 100 then
onmenu = 0
screen:clear()
showbackground()
level1()
screen:flip()
screen.waitVblankStart(18 0) -- Wait 3 seconds
screen:clear()
end
if menuy == 110 then
onmenu = 3
screen.waitVblankStart(15 )
end
if menuy == 120 then
onmenu = 2
screen.waitVblankStart(15 )
end
end
-- Timer for Menu Selecting
if menutime >= 1 then
menutime = menutime + 1
end
if menutime == 5 then
menutime = 0
end
screenrint(180, menuy, "->", white)
end
end
-- Read Controls pressed and change cursor location
pad = Controls.read()
|
taken from console shooter...... and get this error:
Quote:
error:untl.lua:240: 'end' expected (to close 'function' at line 19) near '<eof>'
Error: No script file found.
Press start to restart
|
tnx
|