So, I have been doing more tweaking and I have created a code that looks like this
Rem Project: 2D Collision
Rem Created: 4/3/2008 5:16:22 PM
Rem ***** Main Source File *****
#constant SCREENSIZEX 1440
#constant SCREENSIZEY 900
`subs sets up program
gosub declare_vars
gosub screen_setup
gosub load_images
gosub make_sprites
gosub load_data
do
sync
gosub player_control
gosub collision
gosub scroll_screen
gosub show_player
loop
declare_vars:
hide mouse
`store how many tiles you have
num_tiles_x= 30
num_tiles_y= 30
`stores tile size
tile_sizex =64
tile_sizey =64
`player speed
speedx= 5
speedy= 5
`stores initial position of player
screen_centre_x= SCREENSIZEX/2
screen_centre_y= SCREENSIZEY/2
`stores out how many tiles can be on screen for x and y directions
tiles_per_screenx= SCREENSIZEX/tile_sizex
tiles_per_screeny= SCREENSIZEY/tile_sizey
`works out partially used tiles
if SCREENSIZEX mod tile_sizex then tiles_per_screenx= tiles_per_screenx + 1
if SCREENSIZEY mod tile_sizey then tiles_per_screeny= tiles_per_screeny + 1
`calculates largest x and y value map can get to
map_maxx= (tile_sizex * num_tiles_x) - (SCREENSIZEX + speed_x)
map_maxy= (tile_sizey * num_tiles_y) - (SCREENSIZEY + speed_y)
`stores predefined player position
playerx = screen_centre_x
playery = screen_centre_y
`store predefined map position
mapx=0
mapy=0
return
screen_setup:
`delete video mem
flush video memory
`set screen res
set display mode SCREENSIZEX, SCREENSIZEY, 32
`setup sync junk
sync on
sync rate 150
return
load_images:
`loads the player image
load image "Sprite1.jpeg",1
load image "Grass1.jpeg",2
get image 2,0,0,tile_sizex,tile_sizey,1
load image "Wall1.jpeg",3
get image 3,0,0,tile_sizex,tile_sizey,1
`set transparent colour
set image colorkey 255,0,255
return
make_sprites:
sprite 1,playerx,playery,1
set sprite 1,0,1
return
load_data:
dim testroom(num_tiles_x, num_tiles_y)
`load all of the data into the array
for y =0 to num_tilesy -1
for x = 0 to num_tilesx-1
read testroom(x,y)
next x
next y
return
player_control:
`store map x and x into old_mapx and old_mapy
old_mapy = mapy
old_mapx = mapx
`store x and y of player into old_player
old_playerx = playerx
old_playery = playery
`moves player and such
if leftkey() = 1
if mapx < playerx -(screen_centre_x - 5) and mapx > playerx - (screen_centre_x + 5) then mapx = mapx - speedx
playerx = playerx - speedx
endif
if rightkey() = 1
if mapx < playerx - (screen_centre_x - 5) and mapx > playerx - (screen_centre_x + 5) then mapx = mapx - speedx
playerx = playerx + speedx
playerx = playerx - speedx
endif
if upkey() = 1
if mapy < playery - (screen_centre_y - 5) and mapy > playery - (screen_centre_y + 5) then mapy = mapy - speedy
playery = playery - speedy
endif
if downkey () = 1
if mapy < playery - (screen_centre_y - 5) and mapy > playery - (screen_centre_y + 5) then mapy = mapy + speedy
playery = playery + speedy
endif
return
collision:
`gets tiles
left_tile_num = int(playerx / tile_sizex)
right_tile_num = int((playerx + (tile_sizex -1))/ tile_sizex)
top_tile_num = int(playery / tile_sizey)
bottom_tile_num = int((playery + (tile_sizey-1)) / tile_sizey)
`stores old tiles
old_left_tile_num = int(old_playerx /tile_sizex)
old_right_tile_num = int((old_playerx + (tile_sizex -1)) / tile_sizex)
old_top_tile_num = int(old_playery / tile_sizey)
old_bottom_tile_num = int((old_playery + (tile_sizey -1)) / tile_sizey)
`checks for collision
if testroom(left_tile_num, old_left_tile_num) = 3 then playerx = old_playerx : mapx = old_mapx
if testroom(old_left_tile_num, left_tile_num) = 3 then playerx = old_playerx : mapx = old_mapx
if testroom(right_tile_num, old_right_tile_num) = 3 then playerx = old_playerx :mapx = old_mapx
if testroom(old_right_tile_num, right_tile_num) = 3 then playerx = old_playerx :mapx = old_mapx
if testroom(top_tile_num, old_top_tile_num) = 3 then playery = old_playery :mapy = old_mapy
if testroom(old_top_tile_num, top_tile_num) = 3 then playery = old_playery :mapy = old_mapy
if testroom(bottom_tile_num, old_bottom_tile_num) = 3 then playery = old_playery :mapy = old_mapy
if testroom(old_bottom_tile_num, bottom_tile_num) = 3 then playery = old_playery :mapy = old_mapy
`map collision
if mapx < 0 then mapx = 0
if mapx >= map_maxx then mapx = map_maxx
if mapy < 0 then mapy = 0
if mapy >= map_maxy then mapx = map_maxy
return
scroll_screen:
`works out tile num in array to display tiles
tile_numx = mapx / tile_sizex
tile_numy = mapy / tile_sizey
`holds temp info
tempx = mapx - (tile_numx * tile_sizex)
tempy = mapy - (tile_numy * tile_sizey)
`resets temps
temp1 = 0
temp2 = 0
`sees if map is on last tile
if tiles_per_screenx + tile_numx >= num_tiles_x then temp1 = 1
if tiles_per_screeny + tile_numy >= num_tiles_y then temp2 = 1
`paste images to screen properly
for y = 0 to tiles_per_screeny - temp2
for x = 0 to tiles_per_screenx - temp1
paste image testroom(x + tile_numx, y + tile_numy), (x*tile_sizex) - tempx, (y*tile_sizey) - tempy
next x
next y
return
show_player:
`show sprite
sprite 1, playerx - mapx, playery -mapy,2
return
data 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
data 3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3
data 3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3
data 3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3
data 3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3
data 3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3
data 3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3
data 3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3
data 3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3
data 3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3
data 3,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2,2,2,2,2,2,2,2,2,2,2,2,3
data 3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3
data 3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3
data 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
The issue that I am getting is that I get the error "image number illegal at line 189" those specific lines are
for y = 0 to tiles_per_screeny - temp2
for x = 0 to tiles_per_screenx - temp1
paste image testroom(x + tile_numx, y + tile_numy), (x*tile_sizex) - tempx, (y*tile_sizey) - tempy
next x
next y
This is code made by pizzaman that I have adapted. Thanks for any help.
Cheers,
Christian
N.B. the tiles are 64 x 64 including the sprite
I fixed it nevermind