I'll Warn you right now that the code is somewhat messy.........
-- music = Mod.load("Positive01.xm")
-- Mod.setVolume(128)
-- Mod.play(music)
Wall = {}
map = {}
c=0
mapsizeX = 8
mapsizeY = 8
dofile("./Declare functions.lua")
for c = 1,200 do
Wall[c] = {active = 0, x = 0, y = 0, width = 64, height = 64}
end
dofile("./Load maps.lua")
BSwrd = Image.load("Wep/Broadsword.PNG",VRAM)
Weapons = {}
Weapons[1] = {name = "Broadsword", type = "Melee", offsetx = 16, offsety = 9}
Malespr = Sprite.new("char/male.png", 32, 32, VRAM)
Malespr:addAnimation({0,1,2,1}, 100) -- Walk up
Malespr:addAnimation({3,4,5,4}, 100) -- Walk left
Malespr:addAnimation({6,7,8,7}, 100) -- Walk right
Malespr:addAnimation({9,10,11,10}, 100) -- Walk down
hair = Sprite.new("char/Hair/hair1.png", 32, 32, RAM)
hair:addAnimation({0,1,2,1}, 100) -- Walk up
hair:addAnimation({3,4,5,4}, 100) -- Walk left
hair:addAnimation({6,7,8,7}, 100) -- Walk right
hair:addAnimation({9,10,11,10}, 100) -- Walk down
clothes = Sprite.new("char/Clothes/clothes1.png", 32, 32, RAM)
clothes:addAnimation({0,1,2,1}, 100) -- Walk up
clothes:addAnimation({3,4,5,4}, 100) -- Walk left
clothes:addAnimation({6,7,8,7}, 100) -- Walk right
clothes:addAnimation({9,10,11,10}, 100) -- Walk down
collectgarbage()
x = 150
y = 80
direction = 1
curclothes = 1
curhair = 1
Player = {}
Player[1] = {x = 150, y = 80, oldx = 0, oldy = 0, width = 32, height = 32, velx = 3, vely = 0, spd = 0.12, maxspd = 1.5, wepangle = 1, state = 0}
lnewhair = 0
lnewcloth = 0
Tile1 = Image.load("Level/Testtile.png",RAM)
Wall1 = Image.load("Level/Testwall.png",RAM)
mapcanvas = Canvas.new()
-- 2
-- 3
c = 0
for x = 1,mapsizeX do
for y = 1,mapsizeY do
-- if on screen, then print....
if mt[x][y] == 1 then obj = Canvas.newImage ( x*64, y*64, Wall1) Canvas.add(mapcanvas, obj) end
end
end
mapcanvas2 = Canvas.new()
for x = 1,mapsizeX do
for y = 1,mapsizeY do
-- if ( (x-1)*64 ) - scrollx > -64 and ( (x-1)*64 ) - scrollx < 320 and ( (y-1)*64 ) - -- scrolly > -64 and ( (y-1)*64 ) - scrolly < 256 then
obj = Canvas.newImage ( x*64, y*64, Tile1)
Canvas.add(mapcanvas2, obj)
-- screen.blit(SCREEN_DOWN, ( (x-1)*64 ) - scrollx, ( (y-1)*64 ) - scrolly, Tile1)
-- end
end
end
scrollx = 200
scrolly = 200
collectgarbage()
while not Keys.newPress.Start do
Controls.read()
Player[1].oldx = Player[1].x
Player[1].oldy = Player[1].y
if Player[1].x > 192 then scrollx = scrollx + (Player[1].x - 192) Player[1].x = 192 end
if Player[1].x < 64 then scrollx = scrollx + (Player[1].x - 64) Player[1].x = 64 end
-- if scrollx < 0 then scrollx = 0 end
if Player[1].y > 128 then scrolly = scrolly + (Player[1].y - 128) Player[1].y = 128 end
if Player[1].y < 64 then scrolly = scrolly + (Player[1].y - 64) Player[1].y = 64 end
-- if scrolly < 0 then scrolly = 0 end
startDrawing()
if NB_FPS > 20 then
Canvas.draw(SCREEN_DOWN, mapcanvas2, 0 - scrollx,0 - scrolly)
Canvas.draw(SCREEN_DOWN, mapcanvas, 0 - scrollx,0 - scrolly)
end
if Keys.held.Up and Player[1].state == 0 then direction = 4 Player[1].vely = Player[1].vely + Player[1].spd walk = 1 end
if Keys.held.Right and Player[1].state == 0 then direction = 3 Player[1].velx = Player[1].velx - Player[1].spd walk = 1 end
if Keys.held.Down and Player[1].state == 0 then direction = 1 Player[1].vely = Player[1].vely - Player[1].spd walk = 1 end
if Keys.held.Left and Player[1].state == 0 then direction = 2 Player[1].velx = Player[1].velx + Player[1].spd walk = 1 end
if Stylus.doubleClick and Player[1].state == 0 then
Player[1].state = 1
if direction == 1 then Player[1].wepangle = 90 Player[1].vely = -0.55 end
if direction == 2 then Player[1].wepangle = 360 Player[1].velx = 0.55 end
if direction == 3 then Player[1].wepangle = 0 Player[1].velx = -0.55 end
if direction == 4 then Player[1].wepangle = 90 Player[1].vely = 0.55 end
end
if Stylus.deltaX > 15 and Player[1].state == 0 or Stylus.deltaX < -15 and Player[1].state == 0 then
Player[1].state = 1
if Stylus.deltaX > 15 then direction = 3 Player[1].wepangle = 360 Player[1].velx = -3.5 end
if Stylus.deltaX < -15 then direction = 2 Player[1].wepangle = 0 Player[1].velx = 3.5 end
end
if Keys.newPress.A then curclothes = curclothes + 1 lnewcloth = 1 end
if Keys.newPress.Y then curclothes = curclothes - 1 lnewcloth = 1 end
if Keys.newPress.X then curhair = curhair + 1 lnewhair = 1 end
if Keys.newPress.B then curhair = curhair - 1 lnewhair = 1 end
if lnewhair == 1 then
hair:destroy()
hair = nil
hair = Sprite.new("char/Hair/hair"..curhair..".png", 32, 32, RAM)
hair:addAnimation({0,1,2,1}, 100) -- Walk up
hair:addAnimation({3,4,5,4}, 100) -- Walk left
hair:addAnimation({6,7,8,7}, 100) -- Walk right
hair:addAnimation({9,10,11,10}, 100) -- Walk down
lnewhair = 0
end
if lnewcloth == 1 then
clothes:destroy()
clothes = nil
clothes = Sprite.new("char/Clothes/clothes"..curclothes..".png", 32, 32, RAM)
clothes:addAnimation({0,1,2,1}, 100) -- Walk up
clothes:addAnimation({3,4,5,4}, 100) -- Walk left
clothes:addAnimation({6,7,8,7}, 100) -- Walk right
clothes:addAnimation({9,10,11,10}, 100) -- Walk down
hair:destroy()
hair = nil
hair = Sprite.new("char/Hair/hair"..curhair..".png", 32, 32, RAM)
hair:addAnimation({0,1,2,1}, 100) -- Walk up
hair:addAnimation({3,4,5,4}, 100) -- Walk left
hair:addAnimation({6,7,8,7}, 100) -- Walk right
hair:addAnimation({9,10,11,10}, 100) -- Walk down
lnewcloth = 0
end
if Keys.released.Left and Keys.released.Right and Keys.released.Up and Keys.released.Down then
if direction == 1 then Malespr:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 1) end
if direction == 2 then Malespr:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 4) end
if direction == 3 then Malespr:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 7) end
if direction == 4 then Malespr:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 10) end
walk = 0
end
if walk == 1 then
Malespr:playAnimation(SCREEN_DOWN, Player[1].x, Player[1].y, direction)
clothes:playAnimation(SCREEN_DOWN, Player[1].x, Player[1].y, direction)
hair:playAnimation(SCREEN_DOWN, Player[1].x, Player[1].y, direction)
else
if direction == 1 then clothes:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 1) end
if direction == 2 then clothes:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 4) end
if direction == 3 then clothes:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 7) end
if direction == 4 then clothes:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 10) end
if direction == 1 then hair:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 1) end
if direction == 2 then hair:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 4) end
if direction == 3 then hair:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 7) end
if direction == 4 then hair:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 10) end
end
if Player[1].state == 1 then
if direction == 1 then Malespr:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 2) Player[1].wepangle = Player[1].wepangle + 15 end
if direction == 2 then Malespr:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 5) Player[1].wepangle = Player[1].wepangle - 15 end
if direction == 3 then Malespr:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 8) Player[1].wepangle = Player[1].wepangle + 15 end
if direction == 4 then Malespr:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 11) Player[1].wepangle = Player[1].wepangle - 15 end
if direction == 1 then clothes:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 2) end
if direction == 2 then clothes:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 5) end
if direction == 3 then clothes:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 8) end
if direction == 4 then clothes:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 11) end
if direction == 1 then hair:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 2) end
if direction == 2 then hair:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 5) end
if direction == 3 then hair:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 8) end
if direction == 4 then hair:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 11) end
-- up = 4
-- down = 1
-- left = 2
-- right = 3
if Player[1].wepangle > 360 then Player[1].wepangle = Player[1].wepangle - 360 end
if Player[1].wepangle < 0 then Player[1].wepangle = Player[1].wepangle + 360 end
Image.rotateDegree(BSwrd, Player[1].wepangle, Image.width(BSwrd)/2, Image.height(BSwrd)/2)
screen.blit(SCREEN_DOWN, Player[1].x - Weapons[1].offsetx , Player[1].y - Weapons[1].offsety, BSwrd)
if direction == 4 then
Malespr:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 11)
clothes:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 11)
hair:drawFrame(SCREEN_DOWN, Player[1].x, Player[1].y, 11)
end
if direction == 1 and Player[1].wepangle > 220 then Player[1].wepangle = 0 Player[1].state = 0 end
if direction == 2 and Player[1].wepangle > 250 and Player[1].wepangle < 270 then Player[1].wepangle = 0 Player[1].state = 0 end
if direction == 3 and Player[1].wepangle > 110 then Player[1].wepangle = 0 Player[1].state = 0 end
if direction == 4 and Player[1].wepangle > 270 and Player[1].wepangle < 360 then Player[1].wepangle = 0 Player[1].state = 0 end
end
Player[1].x = Player[1].x - Player[1].velx
Player[1].y = Player[1].y - Player[1].vely
if Player[1].velx > 0.05 then Player[1].velx = Player[1].velx - 0.05 end
if Player[1].velx < -0.05 then Player[1].velx = Player[1].velx + 0.05 end
if Player[1].vely > 0.05 then Player[1].vely = Player[1].vely - 0.05 end
if Player[1].vely < -0.05 then Player[1].vely = Player[1].vely + 0.05 end
if Player[1].velx < 0.06 and Player[1].velx > -0.06 then Player[1].velx = 0 end
if Player[1].vely < 0.06 and Player[1].vely > -0.06 then Player[1].vely = 0 end
if Player[1].velx > Player[1].maxspd then Player[1].velx = Player[1].maxspd end
if Player[1].velx < Player[1].maxspd*-1 then Player[1].velx = Player[1].maxspd*-1 end
if Player[1].vely > Player[1].maxspd then Player[1].vely = Player[1].maxspd end
if Player[1].vely < Player[1].maxspd*-1 then Player[1].vely = Player[1].maxspd*-1 end
c = 0
-- for x = 1,mapsizeX do
-- for y = 1,mapsizeY do
c = c + 1
-- if mt[x][y] == 1 then wallcollisionCheck( 1, c) end
-- end
-- end
screen.print(SCREEN_UP, 0, 184, "FPS: "..NB_FPS)
screen.print(SCREEN_UP, 0, 0, "Press START to quit")
stopDrawing()
end
Malespr:destroy()
Malespr = nil
direction = nil
Tile1:destroy()
Tile1 = nil
Wall1:destroy()
Wall1 = nil
The Do File Commands are just placeholders - they're not for any purpose right now, exept load maps, which it only grabs some data from...
I think its the danged canvas i'm drawing.....
(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )