Post by iCon on Feb 24, 2012 19:33:46 GMT -5
Thanks for all the help!
Here's the final code.
I'll be moving most of it into a seperate program which shall become a small platforming game.
Here's the final code.
I'll be moving most of it into a seperate program which shall become a small platforming game.
textmode (TEXT_BUFFERED)
' 0 1 2 3 4 5 6 7 8 9 10 11 12
data 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 '0
data 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 '1
data 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 '2
data 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 '3
data 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 '4
data 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 '5
data 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 '6
data 1, 1, 1, 1, 2, 2, 2, 1, 1, 0, 1, 1, 1 '7
data 1, 1, 1, 1, 2, 2, 2, 1, 1, 0, 1, 1, 1 '8
data 1, 1, 1, 1, 1, 2, 1, 1, 0, 0, 1, 1, 1 '9
data 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 '10
data 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0 '11
data 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0 '12
data 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 '13
data 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 '14
dim xtiles = 12, ytiles = 14
dim x, y, tiles (xtiles) (ytiles), tilemap
for y = 0 to ytiles
for x = 0 to xtiles
read tiles (x) (y)
next
next
resizespritearea (640, 480) 'default sprite area size
const tilesize = 64
tilemap = newtilemap (loadtexstrip ("tiles\tiletest.png", tilesize, tilesize))
sprsetsolid (false)
sprsetxrepeat (false)
sprsetyrepeat (false)
sprsetpos (0, 0)
sprsetzorder (1)
sprsettiles (tiles)
'tilemap variables
dim tloop 'tile map loop
dim i, j, m
'constants
const widthhalf = 3
const heighthalf = 14
'variables
dim cyanman (texstripframes ("tiles\cyanman.png")- 1)
dim walk (9), stand
dim score = 0
dim a = 1
dim ploop 'platform loop
dim cl 'collision loop
dim notonplat = 1
dim onground = false
dim newplatform = true
'player variables
dim xplayer# = 50
dim yplayer# = 175
'collision variables
dim xmap, ymap
cyanman = loadtexstrip ("tiles\cyanman.png")
stand = cyanman (0)
walk (0) = cyanman (8)
walk (1) = cyanman (1)
walk (2) = cyanman (2)
walk (3) = cyanman (3)
walk (4) = cyanman (4)
walk (5) = cyanman (0)
walk (6) = cyanman (5)
walk (7) = cyanman (6)
walk (8) = cyanman (7)
walk (9) = cyanman (0)
dim sprite
sprite = newsprite (stand)
sprsetpos (xplayer#, yplayer#)
'collision functions
'bottom
function downcollision (xloc, yloc)'x location, y location
xmap = (xloc/32)
ymap = ((yloc + heighthalf)/32) 'bottom of sprite
if tiles (xmap, ymap) = 1 then
return true
endif
return false
end function
'top collision detection isn't required
'left and right
function lrcollision (xloc, yloc)
ymap = (yloc/32)
xmap = ((xloc - widthhalf)/32) 'left of sprite
if tiles (xmap, ymap) = 1 then
return 1
endif
xmap = ((xloc + widthhalf)/32) 'right of sprite
if tiles (xmap, ymap) = 1 then
return 2
endif
return 0
end function
while true
cls
'Player Control
bindsprite (2)
if scankeydown (VK_RIGHT) then
sprsettextures (walk)
sprsetanimspeed (0.2)
sprsetxflip (false)
xplayer# = xplayer# + 1
elseif scankeydown (VK_LEFT) then
sprsettextures (walk)
sprsetanimspeed (0.2)
sprsetxflip (true)
xplayer# = xplayer# - 1
else
sprsettexture (stand)
xplayer# = xplayer#
endif
'Stops the player going off screen
if sprleft (2) <= -10 and scankeydown (VK_LEFT) then
xplayer# = xplayer# + 1
endif
if sprright (2) >= spriteareawidth () + 10 and scankeydown (VK_RIGHT) then
xplayer# = xplayer# - 1
endif
'Tilemap Collision Detection
if downcollision (xplayer#, yplayer#) = false then
yplayer# = yplayer# + 1
endif
if lrcollision (xplayer#, yplayer#) = 1 then
xplayer# = xplayer# + 1
elseif lrcollision (xplayer#, yplayer#) = 2 then
xplayer# = xplayer# - 1
endif
locate 0, 1: print xmap
locate 0, 3: print ymap
bindsprite (2): sprsetpos (xplayer#, yplayer#)
drawtext ()
animatesprites ()
waittimer (10)
wend