alrite ok. Here's the rest of the code
*** blk is a 2D that contains all the grid spaces the sprites are not allowed to move onto
function UpdatePlayer(pla)
print(GetPointerX())
print(GetPointerY())
Print( ScreenFPS() )
SetTextString(3, "X: " + Str(GetSpriteX(pla),0) + " Y: " + Str(GetSpriteY(pla),0))
Sync()
//player movement
if GetVirtualButtonPressed(1) //up
if CanMove(pla, 1)
for i = 1 to 5
for j = 1 to 10
PlaySprite(pla, 2, 0, 4, 6)
Sync()
next j
SetSpritePosition(pla, GetSpriteX(pla), GetSpriteY(pla)-8)
next i
endif
endif
if GetVirtualButtonPressed(2) //down
if CanMove(pla, 2)
for i = 1 to 5
for j = 1 to 10
PlaySprite(pla, 2, 0, 1, 3)
Sync()
next j
SetSpritePosition(pla, GetSpriteX(pla), GetSpriteY(pla)+8)
next i
endif
endif
if GetVirtualButtonPressed(3) //left
if CanMove(pla, 3)
for i = 1 to 4
for j = 1 to 10
PlaySprite(pla, 2, 0, 7, 9)
Sync()
next j
SetSpritePosition(pla, GetSpriteX(pla)-9, GetSpriteY(pla))
next i
endif
endif
if GetVirtualButtonPressed(4) //right
if CanMove(pla, 4)
for i = 1 to 4
for j = 1 to 10
PlaySprite(pla, 2, 0, 10, 12)
Sync()
next j
SetSpritePosition(pla, GetSpriteX(pla)+9, GetSpriteY(pla))
next i
endif
endif
endfunction
//enemy function
function UpdateEnemy(ene)
true = 1
SetTextString(4, "X: " + Str(GetSpriteX(ene),0) + " Y: " + Str(GetSpriteY(ene),0))
//enemy movement
enedir = Random(1,4)
if CanMove(ene, enedir)
if enedir = 1 //up
for i = 1 to 5 //1 to 5
//for j = 1 to 10
PlaySprite(ene, 2, 0, 5, 6)
Sync()
//next j
SetSpritePosition(ene, GetSpriteX(ene), GetSpriteY(ene)-8) //8
next i
endif
if enedir = 2 //down
for i = 1 to 5
//for j = 1 to 10
PlaySprite(ene, 2, 0, 7, 8)
Sync()
//next j
SetSpritePosition(ene, GetSpriteX(ene), GetSpriteY(ene)+8) //8
next i
endif
if enedir = 3 //left
for i = 1 to 4
//for j = 1 to 10
PlaySprite(ene, 2, 0, 1, 2)
Sync()
//next j
SetSpritePosition(ene, GetSpriteX(ene)-9, GetSpriteY(ene)) //9
next i
endif
if enedir = 4 //right
for i = 1 to 4
//for j = 1 to 10
PlaySprite(ene, 2, 0, 3, 4)
Sync()
//next j
SetSpritePosition(ene, GetSpriteX(ene)+9, GetSpriteY(ene)) //9
next i
endif
endif
endfunction true
function GameOver()
repeat
if win = 1 then print("WIN!")
if win = 0 then print("LOSE!")
Sync()
until GetPointerPressed() > 0
endfunction
function CanMove(i, dir)
IF GetSpriteY(i) = 20 AND dir = 1 //up bounds (lowest y)
move = 0
elseif GetSpriteY(i) = 260 AND dir = 2//down bounds (highest y)
move = 0
elseif (GetSpriteX(i) = 23 OR GetSpriteX(i) = 32) AND dir = 3 //left bounds (lowest x)
move = 0
elseif GetSpriteX(i) = 248 AND dir = 4//right bounds (highest x)
move = 0
else
move = 1 //means can move
endif
//checks for illegal block movements
if dir = 1
plannedy = GetSpriteY(i) - 40
plannedx = GetSpriteX(i)
elseif dir = 2
plannedy = GetSpriteY(i) + 40
plannedx = GetSpriteX(i)
elseif dir = 3
plannedx = GetSpriteX(i) - 36
plannedy = GetSpriteY(i)
elseif dir = 4
plannedx = GetSpriteX(i) + 36
plannedy = GetSpriteY(i)
endif
for a = 1 to blk.length
if plannedx = blk[a,1] AND plannedy = blk[a,2]
move = 0
exit
endif
next a
endfunction move