Hi.
Im having trubble with my code. The problem seems to be that a sprite wont exist, even after Ive created it. You see, when I try to compile the program, it complains about that sprite. And I dont know whats wrong. It didnt complain before. And I KNOW Im using the function to create the sprite before I use the function to move it (which is where the compiler stops). Take a look at the functions called \"MovementPlayerOne()\" and \"MovementPlayerTwo()\". You can also take a look at the function called \"MakeShips()\". And pleace tell me if you know why it wont work.
rem The text settings
set text font \"arial\" : set text size 15
rem Sync the program
sync on : sync rate 60
rem Randomize the timer
randomize timer()
rem Turn th backdrop off
backdrop off
rem The colorkey
set image colorkey 0,0,0
rem Types for the array \"objects\"
type characters
imageNr as float
objectNr as float
x as float
y as float
speed as float
points as float
endtype
rem Dim the array that contains the images
dim objects(4) as characters : for n=1 to 4 : inc objects(n).imageNr,objects(n-1).imageNr+1 : next n
objects(1).objectNr=1
objects(2).objectNr=2
objects(3).objectNr=3
objects(4).objectNr=4
rem The backdrop variable
backdrop=5
rem Load all images
load image \"Media/Ships/Ship player one.bmp\",objects(1).imageNr : load image \"Media/Ships/Ship player two.bmp\",objects(2).imageNr
if file exist(\"Media/backdrops/backdrop.bmp\") then load image \"Media/backdrop.bmp\",backdrop
rem Variables
menu=1
sel=1
rem Types
type ArrayTypes
x as float
y as float
endtype
type WeaponTypes
imageRipper as float
imageBullet as float
imageRocket as float
endtype
type Fire
CantFire as float
time as float
wait0 as float
endtype
type playerBullet
playerOne as float
playerTwo as float
endtype
rem The rest of the arrays
dim starArray(100) as ArrayTypes
dim weaponState(2) as Fire
dim bullets(100) as playerBullet
dim wonderer(2)
rem Value wonderer
wonderer(1)=300
wonderer(2)=300
rem Value the weapons
weapons.imageRipper=501
weapons.imageBullet=502
rem Fill the array \"bullets\"
for n=1 to 100
rem bullets(n)=300+n
next n
rem Put the star positions in the array (starArray)
for n=1 to 100
starArray(n).x=rnd(screen width()-20)+10
starArray(n).y=rnd(screen height()-20)+10
next n
rem Defined variables
global menu as float
global sel as float
global NrOfStars as float
global wonderer as float
global weapons as WeaponTypes
rem The main part of the program
do
rem Clear the screen
cls
rem The game state
if menu=1
gosub main
else
rem In the game itself
gosub gameVisual
gosub gameBattle
endif
rem Update the screen
sync
loop
rem The main menu
main:
rem Output the stars
Stars()
rem The \"headline\"
set text size 25
text 10,10,\"FIGHTERS GOLD\"
rem The buttons
set text size 15
if button(10,40,1,\"New game\")=1 then switch=1
button(10,57,2,\"Options\")
if button(10,74,3,\"Controls\")=3 then switch=3
if button(10,91,4,\"Exit\")=4 then end
rem Apply the arrowkeys to the menu
rem Effect
select switch
case 0 : KeyControl(1,4) : endcase
case 1
select NewGame()
rem Points
case 101
CreateBulletImage()
CreateRipperImage()
MakeBlocks(1)
MakeShips()
hide mouse
menu=0
endcase
rem Adrenalin
case 102
endcase
rem Return to the main menu
case 103 : switch=0 : endcase
endselect
KeyControl(101,103)
endcase
case 2 : gosub options : endcase
case 3 : Help() : KeyControl(1,4) : endcase
endselect
return
options:
return
rem The game: Movement and other visual stuff
gameVisual:
Stars()
interface()
MovementPlayerOne()
MovementPlayerTwo()
MoveBlocks()
UpdateBlocks()
if keystate(59)=1
ReturnToMain()
switch=0
endif
return
rem Sounds, bullets and other things that has to do with the battle
gameBattle:
if keystate(54)=1 and weaponState(1).CantFire=0
weaponState(1).wait0=timer()
weaponState(1).CantFire=1
endif
if keystate(42)=1 and weaponState(2).CantFire=0
endif
return
rem The functions
rem Start a new game
function NewGame()
rem Headline
text 40+text width(\"Singleplayer\"),40,\"Choose game type:\"
rem Buttons
detectPress=button(40+text width(\"Singleplayer\"),57,101,\"Points\")
detectPress=button(40+text width(\"Singleplayer\"),74,102,\"Adrenalin\")
detectPress=button(40+text width(\"Singleplayer\"),91,103,\"return to main\")
endfunction detectPress
rem The ships
function MakeShips()
rem Set the position of ship one
objects(1).x=screen width()-57
objects(1).y=screen height()-138
rem Set ship speed
objects(1).speed=2
rem Create sprite and position it
objects(1).objectNr=1 : sprite objects(1).objectNr,objects(1).x,objects(1).y,objects(1).imageNr
rem Set the position of ship two
objects(2).x=10
objects(2).y=10
rem Set ship speed
objects(2).speed=2
rem Create and position the sprite of ship two
objects(2).objectNr=2 : sprite objects(2).objectNr,objects(2).x,objects(2).y,objects(2).imageNr
endfunction
rem The interface
function interface()
rem The Square
ink rgb(100,100,100),0 : box 10,screen height()-90,screen width()-10,screen height()-10
ink rgb(0,0,0),0 : box 13,screen height()-87,screen width()-13,screen height()-13
ink rgb(255,255,255),0
rem The text
text 16,screen height()-84,\"Score player one: \"+str$(objects(1).points)
text 16,screen height()-56,\"Score player two: \"+str$(objects(2).points)
endfunction
rem The credits
function Help()
text 40+text width(\"Singleplayer\"),40,\"Controls player one:\"
text 40+text width(\"singleplayer\"),55,\"Move left = Left key\"
text 40+text width(\"Singleplayer\"),70,\"Move right = right key\"
text 40+text width(\"Singleplayer\"),100,\"Controls player two:\"
text 40+text width(\"Singleplayer\"),115,\"Move left = s\"
text 40+text width(\"Singleplayer\"),130,\"Move right = d\"
endfunction
rem Movement player one
function MovementPlayerOne()
rem Move left
if leftkey()=1 and sprite x(objects(1).objectNr)>10
rotate sprite objects(1).objectNr,-90
move sprite objects(1).objectNr,objects(1).speed
rotate sprite objects(1).objectNr,sprite angle(objects(1).objectNr)+90
endif
rem Move right
if rightkey()=1 and sprite x(objects(1).objectNr)<screen width()-57
rotate sprite objects(1).objectNr,90
move sprite objects(1).objectNr,objects(1).speed
rotate sprite objects(1).objectNr,sprite angle(objects(1).objectNr)-90
endif
endfunction
rem Movement player two
function MovementPlayerTwo()
rem Move left
if keystate(31)=1 and sprite x(objects(2).objectNr)>10
rotate sprite objects(2).objectNr,-90
move sprite objects(2).objectNr,objects(2).speed
rotate sprite objects(2).objectNr,sprite angle(objects(2).objectNr)+90
endif
rem Move right
if keystate(32)=1 and sprite x(objects(2).objectNr)<screen width()-57
rotate sprite objects(2).objectNr,90
move sprite objects(2).objectNr,objects(2).speed
rotate sprite objects(2).objectNr,sprite angle(objects(2).objectNr)-90
endif
endfunction
rem Button command
function button(x,y,id,string$)
rem Other ways to select the button
if sel=id
rem color the text
ink rgb(255,255,100),0
rem Select the button
if returnkey()=1 then returnvalue=id
endif
rem Detect if the mouse is on the \"button\"
if mousex()>=x and mousex()<=x+text width(string$)
if mousey()>=y and mousey()<=y+(text height(string$))
rem If so the text becomes yellow
ink rgb(255,255,0),0
rem If the left mousebutton is clicked, then return the value 1
if mouseclick()=1 then returnvalue=id
endif
endif
rem The text
text x,y,string$
rem Set the color to white
ink rgb(255,255,255),0
endfunction returnvalue
rem Change values on the variable \"Sel\" (as in \"Selection\")
function KeyControl(paramiterOne,paramiterTwo)
if upkey()=1 then dec Sel,1
if downkey()=1 then inc Sel,1
if Sel<paramiterOne then Sel=paramiterTwo
if Sel>paramiterTwo then Sel=paramiterOne
wait 65
endfunction
rem Make the blocks
function MakeBlocks(speed)
rem Clear the screen
cls
rem Color and make the box
ink rgb(155,155,155),0
box 10,10,120,60
rem Make the box to an image
get image objects(3).imageNr,10,10,120,60
rem Clear the screen and color back everything
cls
ink rgb(255,255,255),0
rem The position of teh sprites
objects(3).x=10
objects(3).y=60
objects(4).x=screen width()-120
objects(4).y=screen height()-200
rem Make and position the sprites
objects(3).objectNr=3 : sprite objects(3).objectNr,objects(3).x,objects(3).y,objects(3).imageNr
objects(4).objectNr=4 : sprite objects(4).objectNr,objects(4).x,objects(4).y,objects(3).imageNr
rem Set block speed
objects(3).speed=speed
objects(4).speed=speed
endfunction
rem Move the blocks
function MoveBlocks()
rem Move block one
rotate sprite objects(3).objectNr,90
move sprite objects(3).objectNr,objects(3).speed
rotate sprite objects(3).objectNr,sprite angle(objects(3).objectNr)-90
rem Move block two
rotate sprite objects(4).objectNr,90
move sprite objects(4).objectNr,objects(4).speed
rotate sprite objects(4).objectNr,sprite angle(objects(4).objectNr)-90
endfunction
rem Position the blocks
function UpdateBlocks()
rem Update the position of sprite one
if sprite x(objects(3).objectNr)>(screen width()+1)
delete sprite objects(3).objectNr
objects(3).x=-111
sprite objects(3).objectNr,objects(3).x,objects(3).y,objects(3).imageNr
endif
rem Update the position of sprite two
if sprite x(objects(4).objectNr)>(screen width()+1)
delete sprite objects(4).objectNr
objects(4).x=-111
sprite objects(4).objectNr,objects(4).x,objects(4).y,objects(3).imageNr
endif
endfunction
rem The stars
function Stars()
rem The FOR-NEXT loop that puts out the stars again
for n=1 to 100
dot starArray(n).x,starArray(n).y
next n
endfunction
rem Update the stars positions
function MoveStars(movex,movey)
rem FOR-NEXT loop
for n=1 to 100
rem Update x positions
inc starArray(n).x,movex
rem X position limits
if starArray(n).x>screen width() then starArray(n).x=0
if starArray(n).x<0 then starArray(n).x=screen width()
rem Update y positions
inc starArray(n).y,movey
rem Set y limits
if starArray(n).y>screen height() then starArray(n).y=0
if starArray(n).y<0 then starArray(n).y=screen height()
next n
endfunction
rem Return to main
function ReturnToMain()
for n=1 to 4
delete sprite n
next n
show mouse
menu=1
endfunction
rem Create the bullet image
function CreateBulletImage()
rem Clear the screen
cls
rem Make the bullet and color it
ink rgb(255,255,100),0 : circle 100,100,1 : dot 100,100,rgb(255,155,155)
rem Get the image
get image weapons.imageBullet,99,99,102,102
rem Clear the screen
cls
endfunction
rem Create ripper image
function CreateRipperImage()
rem Clear the screen
rem Make and color the box
ink rgb(255,50,50),0 : box 100,100,102,115
rem Get the image
get image weapons.imageRipper,100,100,103,110
rem Clear the screen
cls
endfunction
rem Make the bullets for player one
function MakeBulletPlayerOne()
rem Increase the nr of the sprite that will be created, and set its limit
inc wonderer(1),1 : if wonderer(1)>400 then wonderer(1)=300
rem Enter \"wonderer\" into the array
bullets(wonderer(1)).playerOne=wonderer(1)
rem Make the sprite
sprite bullets(wonderer(1)).playerOne,sprite x(objects(1).objectNr)+23.5,sprite y(objects(1).objectNr),weapons.imageBullet
endfunction
rem Make the bullets for player two
function MakeBulletPlayerTwo()
rem Increase the nr of the sprite that will be created, and set its limit
inc wonderer(2),1 : if wonderer(2)>400 then wonderer(2)=300
rem Enter \"wonderer\" into the array
bullets(wonderer(2)).playerOne=v
rem Make the sprite
sprite bullets(wonderer(2)).playerTwo,sprite x(objects(1).objectNr)+23.5,sprite y(objects(1).objectNr),weapons.imageBullet
endfunction