PowerMan,
In the code snippet below is the edited code you have been patiently waiting for. I have deleted both of your functions, as they were not needed, at least in the manner they were set up. I have added one new function, which is called
launchmissle, a spin-off of your old function. It makes the missle to move and prints the text "launch missle" to the screen, when called.
rem check for screen res
if check display mode(640,480,32)=1
set display mode 640,480,32
else
set display mode 640,480,16
endif
sync on
sync rate 30
color backdrop 0
hide mouse
`***************************Load in all the graphics*****************
load image "craft4.bmp",1
load image "misile.bmp",84
load image "Level_change.bmp",202
` ***********Spacseship co-ordinates
craftx=50:crafty=200
REM << these will be the variables used to move the missle, must needs to prepare them >>>>>>>>>>>>>>>>
missle_x# = 570
missle_y# = 390
` ***********Constant
Player_Craft=1
` *************************** position enemy misiles
REM << I have placed the missle at same coords as before, except I used the new position variables >>>>>>>>>>>>>
sprite 113,missle_x#,missle_y#,84
`**************************** Place the Invisiable markers for misiles
sprite 150,400,60,202
`//////////////// Start of Main Game Loop ////////////////////////////////////////////////////
do
`************** KEY DIRECTIONs
REM Upkey to move space ship Up
if UPKEY()=1 and crafty>100
dec crafty,5
endif
REM Downkey to move space ship Down
if DOWNKEY()=1 and crafty<400
inc crafty,5
endif
REM Leftkey to move space ship Up
if LEFTKEY()=1 and craftx>10
dec craftx,5
endif
REM Rightkey to move space ship Down
if RIGHTKEY()=1 and craftx<400
inc craftx,5
endif
if SPRITE EXIST(Player_Craft)
Collision_Number=SPRITE COLLISION(Player_Craft,0)
REM << the next line of code will set a 'launch' to a value of 1 in referance(boolean) that the rocket needs to be launched >>>>>>>>>>>>>>>>>>
if Collision_Number = 150 and launch = 0
launch = 1
REM << I am using PASTE SPRITE to move the missle image(more framerate than SPRITE),so the sprite needs to be hidden first >>>>>>>>>>>>>>>>>
hide sprite 113
endif
endif
REM << this next function will move the missle object upwards when the variable 'launch' is set to a value 1 >>>>>>>>>>>>>>>>>
if launch = 1 then missle_y# = launchmissle(missle_x#,missle_y#)
REM << stop the missle movement and reposition the missle where it was before once it leaves the screen >>>>>>>>>>>>>>
if missle_y# < -42
REM << reset 'launch' to 0 to end missle flight >>>>>>>>>>>>>>>>>
launch = 0
REM << reset rocket's position(which isn't linked to the actual sprite, which never accually moved since I used PASTE) and show it's sprite once again >>>>>>>>>>>>>>>>>>
missle_y# = 390
show sprite 113
endif
`******************** UPDATE OBJECTS *****************************
sprite Player_Craft,craftx,crafty,Player_Craft
SYNC
REM << I have added clear screen for the text which will be displayed for a period of time, while the rocket is moving >>>>>>>>>>>>>>>>
cls
LOOP
REM << the new launch missle function;I must recieve the current value of the missle'd y position >>>>>>>>>>>>>>>>>>>>
function launchmissle(x#,y#)
REM << for added physics affects, I have included a variable which will increase the speed of the missle's movement by so much each loop >>>>>>>>>>>>>>>>>
inc movespeed#,0.10
REM << here I subtract 'movespeed' from missle_y# to move the missle up at a gradually increasing speed >>>>>>>>>>>>>>>>>>>>>>>>
dec y#,movespeed#
REM << here the text will be displayed for as long as this function runs >>>>>>>>>>>>>>>>>>>
ink rgb(255,0,0),0
text 530,460,"Launch Missle"
REM << paste missle sprite at coords >>>>>>>>>>>>>>>>>
paste sprite 113,x#,y#
REM << if rocket goes above screen,reset values for next launch >>>>>>>>>>>>>>>>>>>>>>>
if y# < -42 then movespeed# = 0
REM << y coords of the missle will be recieved every loop and then changed, so I must also update them by returning the new missle_y# value to itself >>>>>>>>>>>>>>>>>>>
endfunction y#
` ////////////////////////////////////////////////////////////////////////////////////////////
To create this effect I have used a referance(boolean value) variable named
launch, that as long as it is set to a value of 1, the
launchmissle() function will be called. If the variable is set to anything else, the function will not be called.
There are two conditions to be met which alters the value inside
launch.
1)launch = 0 and collision between the marker and player craft is true. This condition, being met, will change the value of
launch to 1.
2) Missle goes completely out of screen(missle_y# < -42) This condition, being met, will set
launch to 0 and the missle will be repositioned at its initial position.
There are plenty off REM comments of mine within your code, which will help navigate you to a good understanding of how the program works. The comments of mine look like this
REM << a comment >>>>>>>>>>>>.
+NanoBrain+