I'm having another prob ;p lets see if I can actually put this stuff in...
good so far.
OKAY the problem I'm having is that I've added 5 sets of data to the
bottom of the data set. In theory it should lengthen the map by 5.
I changed the one variable that I know has to do with the length of the map. (was 30, now 35)
But (and I found out this happened even with only 30) sometimes when the ship moves across the map, the map stops moving and won't scroll. I'm not sure what's going on.
When I added the 5 extra sets of data, I can move the ship down but then the map will no longer scroll back up.
Any help for a poor newb ;P would be appreciated.
`Credits:
`The Tilemap and Tile Based Collision sytem are the work of "Pizzaman"
`
` Rewrite .03
`
` Code for sdorez
` .01 - rewrote all code from sdorez in the style of the tile scrolling engine
` .02 - first try at mixing in the tile engine
` .03 - time to add some more tiles!
#constant SCREENSIZEX 1024
#constant SCREENSIZEY 768
gosub DeclareVariables
gosub ScreenSetup
gosub CreateImages
gosub LoadSound
gosub LoadData
gosub MakePlayer
do
if spacekey() = 1 then exit
cls
gosub Controls
gosub Collision
gosub ScrollScreen
gosub DisplayGraphics
gosub DisplayDebugInfo
sync
loop
gosub CleanUp
end
DeclareVariables:
global shipmovex
NumOfTilesX = 40
NumOfTilesY = 35
TileSizeX = 32
TileSizeY = 32
SpeedX = 2
SpeedY = 2
shipmovex = 512
shipmovey = 384
shield = 1
acceleration# = .5
ScreenCentreX = SCREENSIZEX / 2
ScreenCentreY = SCREENSIZEY / 2
TilesPerScreenX = SCREENSIZEX / TileSizeX
TilesPerScreenY = SCREENSIZEY / TileSizeY
if SCREENSIZEX mod TileSizeX then TilesPerScreenX = TilesPerScreenX + 1
if SCREENSIZEY mod TileSizeY then TilesPerScreenY = TilesPerScreenY + 1
MaxMapX = (TileSizeX * NumOfTilesX) - (SCREENSIZEX + SpeedX)
MaxMapY = (TileSizeY * NumOfTilesY) - (SCREENSIZEY + SpeedY)
X1 = shipmovex
Y1 = shipmovey
MapX = 0
MapY = 0
return
ScreenSetup:
flush video memory
set display mode 1024, 768, 32
sync on
sync rate 30
return
CreateImages:
load image "spaceship1.bmp", 1
load image "shield1.bmp", 2
load image "bullet.bmp",3
sprite 1, 512, 384, 1
offset sprite 1, 32, 36
sprite 2, 512, 384, 2
offset sprite 2, 49, 49
load image "spacetile3.bmp", 11
load image "spacetile4.bmp", 14
load image "spacetile5.bmp", 15
load image "spacetile6.bmp", 16
load image "spacetile7.bmp", 17
`create a yellow/orange box as the player
`box 0, 0, TileSizeX, TileSizeY, rgb(255, 255, 0), rgb(255, 128, 0), rgb(255, 128, 0), rgb(255, 255, 0)
`get image 2, 0, 0, TileSizeX, TileSizeY, 1
`create a red box
`cls rgb(255, 0, 0)
`get image 10, 0, 0, TileSizeX, TileSizeY, 1
`create a blue box
`box 0, 0, TileSizeX, TileSizeY, rgb(0, 0, 255), rgb(0, 0, 225), rgb(0, 0, 225), rgb(0, 0, 200)
`get image 1,0,0,TileSizeX,TileSizeY,1
return
LoadData:
dim TileMap(NumOfTilesX - 1, NumOfTilesY - 1)
for y = 0 to NumOfTilesY - 1
for x = 0 to NumOfTilesX - 1
read TileMap(x, y)
next x
next y
return
LoadSound:
load music "engine.wav",1
return
MakePlayer:
`sprite 1, X1, Y1, 2
`set sprite 1, 0, 1
return
Controls:
mbinput = mouseclick()
if mbinput > 1 and mbinput < 4
scale_x# = cos(angle# -90)
scale_y# = sin(angle# -90)
velocity_x# = velocity_x# + scale_x#
velocity_y# = velocity_y# + scale_y#
load image "spaceship2.bmp",1
loop music 1
endif
if mbinput < 2 or mbinput > 3
stop music 1
load image "spaceship1.bmp", 1
endif
checkkey$ = inkey$()
if checkkey$ = "z"
velocity_x# = velocity_x# * .95
velocity_y# = velocity_y# * .95
if velocity_x# > -.5 and velocity_x# < .5 then velocity_x# = 0
if velocity_y# > -.5 and velocity_y# < .5 then velocity_y# = 0
endif
```````````````````````````
`this part is the controls from the tile engine
```````````````````````````
` if leftkey() = 1
` if MapX < X1 - (ScreenCentreX - 5) and MapX > X1 - (ScreenCentreX + 5) then MapX = MapX - SpeedX
` X1 = X1 - SpeedX
` endif
` if rightkey() = 1
` if MapX < X1 - (ScreenCentreX - 5) and MapX > X1 - (ScreenCentreX + 5) then MapX = MapX + SpeedX
` X1 = X1 + SpeedX
` endif
` if upkey() = 1
` if MapY < Y1 - (ScreenCentreY - 5) and MapY > Y1 - (ScreenCentreY + 5) then MapY = MapY - SpeedY
` Y1 = Y1 - SpeedY
` endif
` if downkey() = 1
` if MapY < Y1 - (ScreenCentreY - 5) and MapY > Y1 - (ScreenCentreY + 5) then MapY = MapY + SpeedY
` Y1 = Y1 + SpeedY
` endif
if MapX < shipmovex - (ScreenCentreX - 16) and MapX > shipmovex - (ScreenCentreX + 16) then MapX = mapx + ((velocity_x# * -1)/2)
if MapX < shipmovex - (ScreenCentreX - 16) and MapX > shipmovex - (ScreenCentreX + 16) then MapX = mapx + ((velocity_x# * -1)/2)
if MapY < shipmovey - (ScreenCentreY - 16) and MapY > shipmovey - (ScreenCentreY + 16) then MapY = mapy + ((velocity_y# * -1)/2)
if MapY < shipmovey - (ScreenCentreY - 16) and MapY > shipmovey - (ScreenCentreY + 16) then MapY = mapy + ((velocity_y# * -1)/2)
`mapx = mapx + (velocity_x# * -1)
`mapy = mapy + (velocity_y# * -1)
return
Collision:
if shipmovex > 950
shipmovex = 950
velocity_x# = velocity_x# * -.25
endif
if shipmovex < 74
shipmovex = 74
velocity_x# = velocity_x# * -.25
endif
if shipmovey > 694
shipmovey = 694
velocity_y# = velocity_y# * -.25
endif
if shipmovey < 74
shipmovey = 74
velocity_y# = velocity_y# * -.25
endif
``````````````````````````````````
`tile engine collision
``````````````````````````
LeftTileNum = int(X1 / TileSizeX)
RightTileNum = int((X1 + (TileSizeX - 1)) / TileSizeX)
TopTileNum = int(Y1 / TileSizeY)
BottomTileNum = int((Y1 + (TileSizeY - 1)) / TileSizeY)
OldLeftTileNum = int(oldX1 / TileSizeX)
OldRightTileNum = int((oldX1 + (TileSizeX - 1)) / TileSizeX)
OldTopTileNum = int(oldY1 / TileSizeY)
OldBottomTileNum = int((oldY1 + (TileSizeY - 1)) / TileSizeY)
if TileMap(LeftTileNum, OldTopTileNum) >= 14 then X1 = oldX1 : MapX = OldMapX
if TileMap(OldLeftTileNum, TopTileNum) >= 14 then Y1 = oldY1 : MapY = OldMapY
if TileMap(RightTileNum, OldTopTileNum) >= 14 then X1 = oldX1 : MapX = OldMapX
if TileMap(OldRightTileNum, TopTileNum) >= 14 then Y1 = oldY1 : MapY = OldMapY
if TileMap(LeftTileNum, OldBottomTileNum) >= 14 then X1 = oldX1 : MapX = OldMapX
if TileMap(OldLeftTileNum, BottomTileNum) >= 14 then Y1 = oldY1 : MapY = OldMapY
if TileMap(RightTileNum, OldBottomTileNum) >= 14 then X1 = oldX1 : MapX = OldMapX
if TileMap(OldRightTileNum, BottomTileNum) >= 14 then Y1 = oldY1 : MapY = OldMapY
if MapX < 0 then MapX = 0
if MapX >= MaxMapX then MapX = MaxMapX
if MapY < 0 then MapY = 0
if MapY >= MaxMapY then MapY = MaxMapY
return
ScrollScreen:
TileNumX = MapX / TileSizeX
TileNumY = MapY / TileSizeY
TempX = MapX - (TileNumX * TileSizeX)
TempY = MapY - (TileNumY * TileSizeY)
Temp1 = 0
Temp2 = 0
if TilesPerScreenX + TileNumX >= NumOfTilesX then Temp1 = 1
if TilesPerScreenY + TileNumY >= NumOfTilesY then Temp2 = 1
for y = 0 to TilesPerScreenY - Temp2
for x = 0 to TilesPerScreenX - Temp1
paste image TileMap(x + TileNumX, y + TileNumY), (x * TileSizeX) - TempX, (y * TileSizeY) - TempY
next x
next y
return
DisplayGraphics:
if velocity_x# > 10 then velocity_x# = 10
if velocity_x# < -10 then velocity_x# = -10
if velocity_y# > 10 then velocity_y# = 10
if velocity_y# < -10 then velocity_y# = -10
shipmovex = shipmovex + (velocity_x# * -1)
shipmovey = shipmovey + (velocity_y# * -1 )
xcurrentposition = 512
ycurrentposition = 384
mx = mousex()
my = mousey()
angle# = -1.0*atanfull(mx - shipmovex, my - shipmovey)
`now we rotate the ship sprite to face the mouse
sprite 2, shipmovex, shipmovey, 2
sprite 1, shipmovex, shipmovey, 1
rotate sprite 1, angle#
rotation = rotation + 3
if rotation > 360 then rotation = 0
rotate sprite 2, rotation
`sprite 2, 512, 384, 2
`sprite 1, 512, 384, 1
return
DisplayDebugInfo:
text 0, 0,"FPS " + str$(screen fps())
text 0,20,"MapX " + str$(MapX)
text 0,40,"MapY " + str$(MapY)
text 0,60,"MaxMapX " + str$(MaxMapX)
text 0,80,"MaxMapY " + str$(MaxMapY)
text 0,100,"X1 " + str$(X1)
text 0,120,"Y1 " + str$(Y1)
text 100, 0,"Press spacebar to exit"
text 80, 120, "scale_x: " + str$(scale_x#)
text 80, 150, "scale_y: " + str$(scale_y#)
text 80, 180, "shipmovex: " + str$(shipmovex)
text 80, 210, "shipmovey: " + str$(shipmovey)
text 80, 240, "angle: " + str$(angle#)
text 80, 270, "velocity_x#: " + str$(velocity_x#)
text 80, 300, "velocity_y#: " + str$(velocity_y#)
text 300,100,"mousex: " + str$(mx)
text 300,140,"mousey: " + str$(my)
return
CleanUp:
for x = 1 to 11
if image exist(x) then delete image x
if sprite exist(x) then delete sprite x
next x
flush video memory
return
data 11,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,11
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 17,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,15
data 11,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,11