I'm not to sure where to go with this. I have the scrolling background setup with collision and shooting in the direction the sprite is facing and the sprite rotates, but it wont stop rotating and continue in the facing direction. I have removed all the media and attached the code. I'm hoping someone here can shed some light on this please.
Ok. I got the sprite to move and rotate around the screen with shooting and a tile background, but i still can't get the scrolling to work. I have attached the media and updated the code.
`set screen resolution
set display mode 1024, 768, 32
`setup syncing
sync on
sync rate 60
#constant SCREENSIZEX 1024
#constant SCREENSIZEY 768
` player shoot switch
global shoot=0
load sound "media\sounds\arrow_001.wav",101
load image "media\player\arrow_001.png",111,1
create animated sprite 101, "media\player\skeleton_walk_001.png",24,3,101
sprite 101, SCREENSIZEX /2, SCREENSIZEY /2, 101
offset sprite 101,sprite width(101) /2,sprite height(101) /2
` set characters position on screen and offset sprite to rotate on center
`sprite 101, SCREENSIZEX / 2, SCREENSIZEY / 2, 101
`offset sprite 101, sprite width(101) / 2, sprite height(101) / 2
` Set the character sprite to always draw to the front
Set sprite priority 101,1
`set sprite 101, 0, 1
`********************************************************************************
gosub DeclareVariables
gosub createimages
gosub loaddata
`********************************************************************************
do
gosub controls
gosub collision
gosub ScrollScreen
gosub handleweapon
gosub DisplayInfo
sync
LOOP
`************************************************************************************
DeclareVariables:
`store how many horizontal/verticle tiles there are
NumOfTilesX = 40
NumOfTilesY = 30
`store the size (in pixels) of a tile
TileSizeX = 64
TileSizeY = 64
`store the speed of the tile
SpeedX = 4
SpeedY = 4
`store the coordinates that will make the player be at the centre of the screen
ScreenCentreX = SCREENSIZEX / 2
ScreenCentreY = SCREENSIZEY / 2
`Work out out how many tiles there are on screen for x and y directions
TilesPerScreenX = SCREENSIZEX / TileSizeX
TilesPerScreenY = SCREENSIZEY / TileSizeY
`Works out if a tile is partially visible on screen, if so then add 1 to the TilesPerScreen variable.
if SCREENSIZEX mod TileSizeX then TilesPerScreenX = TilesPerScreenX + 1
if SCREENSIZEY mod TileSizeY then TilesPerScreenY = TilesPerScreenY + 1
`Calculates the largest co-ordinates the map can scroll too
MaxMapX = (TileSizeX * NumOfTilesX) - (SCREENSIZEX + SpeedX)
MaxMapY = (TileSizeY * NumOfTilesY) - (SCREENSIZEY + SpeedY)
`store predefined coordinates of player
X1 = ScreenCentreX
Y1 = ScreenCentreY
`store predefined coordinates of map
MapX = 0
MapY = 0
angle#=0
return
`************************************************************************************
createimages:
`create a green box
box 0, 0, TileSizeX, TileSizeY, rgb(0, 255, 0), rgb(0, 225, 0), rgb(0, 225, 0), rgb(0, 200, 0)
get image 1, 0, 0, TileSizeX, TileSizeY, 1
`create a red box
box 0, 0, TileSizeX, TileSizeY, rgb(255, 0, 0), rgb(255, 0, 0), rgb(255, 0, 0), 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, 255), rgb(0, 0, 255), rgb(0, 0, 255)
get image 11,0,0,TileSizeX,TileSizeY,1
return
`************************************************************************************
loaddata:
`create an array called TileMap used this to store the tile data.
dim TileMap(NumOfTilesX - 1, NumOfTilesY - 1)
`load data into the array to read 20 bits of data from one data statment
for y = 0 to NumOfTilesY - 1
for x = 0 to NumOfTilesX - 1
read TileMap(x, y)
next x
next y
return
`************************************************************************************
controls:
`store the map's x and y coordinates into the variables OldMapX and OldMapY
OldMapX = MapX
OldMapY = MapY
`store the x and y coordinates of the player into the variables oldX1 and oldY1
OldX1 = X1
OldY1 = Y1
` plays the idle animation
play sprite 101,25,48,100
rotate sprite 101,angle#
if keystate(30)=1
angle#=wrapvalue(angle#-4.0)
else
if keystate(32)=1
angle#=wrapvalue(angle#+4.0)
endif
endif
if keystate(17)=1
play sprite 101,1,24,40
move sprite 101, 4
a#=wrapvalue((360.0-angle#)+180.0)
inc ScreenCentreX,sin(a#)*1.0
inc ScreenCentreY,cos(a#)*1.0
if MapY < Y1 - (ScreenCentreY - 5) and MapY > Y1 - (ScreenCentreY + 5) then MapY = MapY - SpeedY
Y1 = Y1 - SpeedY
if MapY < Y1 - (ScreenCentreY - 5) and MapY > Y1 - (ScreenCentreY + 5) then MapY = MapY + SpeedY
Y1 = Y1 + SpeedY
if MapX < X1 - (ScreenCentreX - 5) and MapX > X1 - (ScreenCentreX + 5) then MapX = MapX - speedx
X1 = X1 - SpeedX
if MapX < X1 - (ScreenCentreX - 5) and MapX > X1 - (ScreenCentreX + 5) then MapX = MapX + speedx
X1 = X1 + SpeedX
endif
return
`************************************************************************************
collision:
`the following 8 lines of code stores the old and new left,right,top,bottom edges of the sprite in the respective variables
`gets which tiles the current left and right co-ordinates of the player are on
LeftTileNum = int(X1 / TileSizeX)
RightTileNum = int((X1 + (TileSizeX *2)) / TileSizeX)
`gets which tiles the current top and bottom co-ordinates of the player are on
TopTileNum = int(Y1 / TileSizeY)
BottomTileNum = int((Y1 + (TileSizeY *2)) / TileSizeY)
`gets which tiles the old left and right co-ordinates of the player are on
OldLeftTileNum = int(oldX1 / TileSizeX)
OldRightTileNum = int((oldX1 + (TileSizeX *2)) / TileSizeX)
`gets which tiles the old top and bottom co-ordinates of the player are on
OldTopTileNum = int(oldY1 / TileSizeY)
OldBottomTileNum = int((oldY1 + (TileSizeY *2)) / TileSizeY)
`checks for top-left collision point
if TileMap(LeftTileNum, OldTopTileNum)>= 10 then X1 = oldX1 : MapX = OldMapX
if TileMap(OldLeftTileNum, TopTileNum)>= 10 then Y1 = oldY1 : MapY = OldMapY
`checks for top-right collision point
if TileMap(RightTileNum, OldTopTileNum)>= 10 then X1 = oldX1 : MapX = OldMapX
if TileMap(OldRightTileNum, TopTileNum)>= 10 then Y1 = oldY1 : MapY = OldMapY
`checks for bottom-left collision point
if TileMap(LeftTileNum, OldBottomTileNum)>= 10 then X1 = oldX1 : MapX = OldMapX
if TileMap(OldLeftTileNum, BottomTileNum)>= 10 then Y1 = oldY1 : MapY = OldMapY
`checks for bottom-right collision point
if TileMap(RightTileNum, OldBottomTileNum)>= 10 then X1 = oldX1 : MapX = OldMapX
if TileMap(OldRightTileNum, BottomTileNum)>= 10 then Y1 = oldY1 : MapY = OldMapY
`stops player from scrolling past the edges of the map by resetting the maps
`global coordinates to their maximum values
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:
`works out the tile number within array to start displaying tiles at
TileNumX = MapX / TileSizeX
TileNumY = MapY / TileSizeY
`cache calculation to tempX and TempY variables for a minor speed increase
`this calculation works out how many pixels to offset the position where the tile
`images should be placed.
TempX = MapX - (TileNumX * TileSizeX)
TempY = MapY - (TileNumY * TileSizeY)
`reset values
Temp1 = 0
Temp2 = 0
`Calculates if the map has scrolled to the last tile, if so we must remove a column
`or/and row of tiles from the screen as they have no more map data to draw; also
`because of this it would create an error
if TilesPerScreenX + TileNumX >= NumOfTilesX then Temp1 = 1
if TilesPerScreenY + TileNumY >= NumOfTilesY then Temp2 = 1
`this pastes the images to screen in the correct order by working out where to start
`pasting the images from in the array, then displaying the images at the correct
`screen coordinates
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
`************************************************************************************
handleweapon:
` shoot (space key)
if keystate(57)=1 and shoot=0
play sound 101
play sprite 101,49,72,60
sprite 111,sprite x(101),sprite y(101),111
scale sprite 111,50
offset sprite 111, sprite width(101) / 2, sprite height(101) / 2
rotate sprite 111,sprite angle(101)
` turn on shoot switch
shoot=1
else
sleep 1
endif
` check if the player shot the weapon
if shoot=1
move sprite 111,20
` check if the bullet is off the screen
if sprite x(111)<-1 or sprite x(111) >SCREENSIZEX or sprite y(111)<-1 or sprite y(111) >SCREENSIZEY
` turn off the shoot switch
shoot=0
endif
endif
return
`************************************************************************************
DisplayInfo:
text 0,20,"FPS: "+STR$(Screen FPS())
text 0,40,"shoot: "+str$(shoot)
text 0,60,"W A S D to move"
text 0,80,"space key to shoot"
return
`************************************************************************************
`store tile data at the end of the program so its out of the way
data 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10
data 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,10
data 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,10
data 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,10
data 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,10
data 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,10
data 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,10
data 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,10
data 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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