It was the length of the defined bars width, set to higher then 100.
I reset it to 100 and then reshuffled the areas it displays in.
If you want it to be smoother, or more accurate as things load, perhaps create another bar under that one for specific loading areas you had it in.
I removed the smooth loading areas in this instance.
It loads right up to 100% across the bar in this source code below.
Define the bar as 2 types within the one, if you want that feature and use the 2nd bar in those areas.
It looks really good so far mate. The sounds really help make it.
I'm heading off for a holiday tomorrow night so I wont have much time to see the result until i'm back from holidays.
REM -----------------------------------------------------------------------------------
REM SPACE INVADERS
REM Community Based Project
REM Language : DBP version 6.3
REM Jan 05 2007
REM Authors
REM Ridii
REM indi
REM Ruccus
REM Lukas W
REM
REM Program Notes
REM Added Loading bar
REM Cleaned up the code a little with clear titles
REM
REM -----------------------------------------------------------------------------------
REM -----------------------------------------------------------------------------------
REM SETUP GAME SHELL
REM -----------------------------------------------------------------------------------
Sync On : Sync Rate 60 : Autocam Off
color backdrop rgb(0,0,0)
REM -----------------------------------------------------------------------------------
REM CREATE LOADING BAR
REM -----------------------------------------------------------------------------------
type LoadBar
name$ as string
x1 as integer
y1 as integer
x2 as integer
y2 as integer
bdr as integer
width as integer
height as integer
length as integer
endtype
dim LoadBar(1) as LoadBar
LoadBar(1).height = 8
LoadBar(1).width = 100
LoadBar(1).x1 = 15
LoadBar(1).y1 = 15
LoadBar(1).x2 = LoadBar(1).x1 + LoadBar(1).width
LoadBar(1).y2 = LoadBar(1).y1 + LoadBar(1).height
LoadBar(1).bdr = 1
LoadBar(1).name$ = "Loading Data"
LoadBar(1).length = 0
REM -----------------------------------------------------------------------------------
REM INIT SCREEN
REM -----------------------------------------------------------------------------------
Load Image "data\space_invaders_splashscreen.png",1,1
Sprite 1,0,0,1
Size Sprite 1,Screen Width(),Screen Height()
Sprite 1,-800,-600,1
Hide Sprite 1
`Initialize the attached buttons functionality
Initialize_Buttons
`Make_Button(File as String,xpos as float, ypos as float,RVal as Integer,AnimFlag)
Make_Button("data\Start.png",screen width()/2-32,screen height()/2-66,1,1)
Show Sprite 1
Do
Paste Sprite 1,0,0
`Check to see if the button is "active" (mouse pointer is over sprite) and for left click
If Get_Button()=1 And MouseClick()=1 Then Exit
fastSync
Loop
hide sprite 1
`Clean up the buttons.
Clear_Buttons
REM -----------------------------------------------------------------------------------
REM UPDATING LOAD BAR
REM -----------------------------------------------------------------------------------
LoadBar(1).length = 10
Display_LoadBar(1)
REM -----------------------------------------------------------------------------------
REM
REM CREATE ALIENS
REM
REM -----------------------------------------------------------------------------------
`There will be 6 rows of 9 invaders to start with.
`The player's ship will be at the bottom, like so.
` X X X X X X X X X
` X X X X X X X X X
` X X X X X X X X X
` X X X X X X X X X
` X X X X X X X X X
` X X X X X X X X X
` /
`Create an array to store the invader information. This is not needed now, but will be needed later.
`This is a 2-dimensional array. It is 6 by 9 in size (or 6x9=54). 5,8 was used instead of 53 to make
`it easier to determine rows and columns. It is normally better to use a single array of 53.
Dim Invaders(5,8)
`Load the aliens
For r=0 to 5: `0 to 5 is 6 rows (0,1,2, 3,4,5)
For i = 0 to 8: `0 to 8 is 9 invaders per row
`Get a free object ID for our invader
obj=FreeObject()
`Store the Object ID in the Invaders array
Invaders(r,i)=obj
`Load the alien model
Load Object "Data\Alien1.x",obj
`Next, we need to make sure our model is the right size. For this, the model needs to be scaled.
`Roughly, we want a model that is 6x6x6 (just what is picked and looks about right).
`To scale the model, we first need to know it's size ratio to a size of 6.
`Here's how to get that:
s#=5.0/Object Size X(obj)
`All that is left to do is scale the model. Remember that Scale Object uses an integer scale that represents
`percentage values (100 = 100% = 1, 50 = 50% = .5, 1 = 1% = .01, and so on). So, the scale (s#) needs to be
`multiplied by 100.
Scale Object obj,s#*100.0,s#*100.0,s#*100.0
`Each invader is 6x6x6 in size. Our viewable area is a little less than 100 x 100
`In order to fit the invaders evenly, we can divide the area we have to work with by
`the number of colums - 9. Since 9 goes into 90 evenly, lets use that. The result is 10.
`Here is the formula to calculate the X-position of the invaders every 10 spaces from
`-45x to +45x
x=(i*10)-45
`Using the same spacing of 10 for the Y-position, and the invaders need to be well up off
`the ground, here is the formula to calculate the Y-position.
y=(r*10)+50
`Position the invader
Position Object obj,x,y,0
Set Object Collision To Boxes obj
Next i
Next r
REM -----------------------------------------------------------------------------------
REM UPDATING LOAD BAR
REM -----------------------------------------------------------------------------------
LoadBar(1).length = 20
Display_LoadBar(1)
Load Sound "data\fastinvader1.wav",1
Load Sound "data\invaderkilled.wav",3
` this variable will be used to store the objid of the first alien object
Global AlienObjIdStart
AlienObjIdStart = obj - 53
REM -----------------------------------------------------------------------------------
REM UPDATING LOAD BAR
REM -----------------------------------------------------------------------------------
LoadBar(1).length = 30
Display_LoadBar(1)
` *************************************************************************
` Prepare Enemy Bullets
` - last changed: 04.Jan.2007
` create a UDT for the Enemy Bullets
` (a description of UDT's and what they are, can be found further down.)
Type tEnemyBullet
` create a variable to store the bullets Object ID
ObjId AS INTEGER
` create a variable to store the alien Object ID
AlienId AS INTEGER
` create timer variables :: that way we can control how often
` the enemies are to fire a bullet.
TimeControl AS BOOLEAN ` here we will store a 1 for reset StartSecond or 0 for Start Counting Seconds
StartSecond AS INTEGER ` here we will store the starting position in time
CurSecond AS INTEGER ` here we will store the current position in time
FireHere AS INTEGER ` here we will store on which second the Alien should fire his bullet
` create a Active variable :: that way we can see if the bullet
` is destroyed. if it's destroyed, it means the alien
` connected to this bullet will be able to fire a new one.
Active AS INTEGER
` create position and rotation angle variables for the bullet
` this way we can easily control the movement and angle of the bullet
` --it would also be possible to make some sinus/cosinus effects
` if we want to make Easy - Hard difficulties. that would be neat.
xPos AS FLOAT
yPos AS FLOAT
zPos AS FLOAT
xAng AS FLOAT
yAng AS FLOAT
zAng AS FLOAT
EndType
` create the array where we store the Enemy Bullet information
` remember we have 6*9 aliens, yea? that means 54 enemies
Dim EnemyBullet(53) AS tEnemyBullet
`Counter to keep track of last bullet
Dim ALienFireFlag(0)
` now create all the bullets
For bullet = 1 to 54
` we set ID to bullet-1 because our Array "EnemyBullet" is counting
` from 0-53, and not 1-54
arrayPosition = bullet -1
` get the object nr for this bullet
obj = FreeObject()
` make a box object for the bullet
Load Object "Data\Missile.x",obj
s#=4.0/Object Size Y(obj)
Scale Object obj,s#*100.0,s#*100.0,s#*100.0
Set Object Emissive obj,Rgb(50,0,0)
Hide Object obj
Set Object Collision To Boxes obj
` update the EnemyBullet array
alien = AlienObjIdStart + arrayPosition
EnemyBullet( arrayPosition ).ObjId = obj ` the object nr
EnemyBullet( arrayPosition ).AlienId = alien ` the alien object nr
EnemyBullet( arrayPos ).FireHere = rnd(20) ` set FireHere to a random of 20 seconds
Next bullet
` --------------------------------------- end of Prepare Enemy Bullets
REM -----------------------------------------------------------------------------------
REM UPDATING LOAD BAR
REM -----------------------------------------------------------------------------------
LoadBar(1).length = 40
Display_LoadBar(1)
REM -----------------------------------------------------------------------------------
REM BARRIERS
REM -----------------------------------------------------------------------------------
`Load the shield barriers (same process as above).
Dim Barriers(2)
For i = 0 to 2
obj=FreeObject()
Barriers(i)=obj
Load Object "Data\Barrier.x",Barriers(i)
s#=12.0/Object Size X(obj)
Scale Object Barriers(i),s#*100.0,s#*100.0,s#*100.0
x#=(i*35)-35
Position Object Barriers(i),x#,20,0
Set Object Collision To Boxes Barriers(i)
Next i
REM -----------------------------------------------------------------------------------
REM UPDATING LOAD BAR
REM -----------------------------------------------------------------------------------
LoadBar(1).length = 50
Display_LoadBar(1)
REM -----------------------------------------------------------------------------------
REM CREATE PLAYER
REM -----------------------------------------------------------------------------------
`Load player's missile
`Use an array for the variable since it is global (A global variable could be used, but later you will see why
`there is a preference for Arrays over Global Variables).
Dim Missile(1)
`Assign a free object to Missile
Missile(0)=FreeObject()
`Load the missile model
Load Object "Data\Missile.x",Missile(0)
`Calculate the scale
s#=6.0/Object Size Y(Missile(0))
`Scale the missile.
Scale Object Missile(0),s#*100.0,s#*100.0,s#*100.0
`Hide the missile
Hide Object Missile(0)
Set Object Collision To Boxes Missile(0)
Create Animated Sprite 11,"Data\Explode.bmp",4,1,11
Sprite 11,-512,0,11
Size Sprite 11,50,50
Set Image Colorkey 0,0,0
Set Sprite 11,1,1
`Create a playertype "user defined array"
Load Sound "Data\shoot.wav",2
REM -----------------------------------------------------------------------------------
REM UPDATING LOAD BAR
REM -----------------------------------------------------------------------------------
LoadBar(1).length = 60
Display_LoadBar(1)
type PlayerType
`this will store the id of the object that is associated with the player, so we can move it later
ObjId as integer
`to keep track of the x position of the player, we are creating these as floats in order
`to maintain a smooth movement. With integers the player would "jump" from one integer to another
`adding the "#" to the end defines it as a float, to use this variable later you must use the "#"
xpos#
`we also need to keep track of the y position of the player, the player's "up and down"
`movement will be limited to keep them behind the bariers
ypos#
`this stores the distance that the player can move in one frame
speed#
` with the following variable stored, we can apply a neat rotation effect to the ship while
` it is moving left or right
yang#
`FireControl is how long before the player can fire again.
FireControl
endtype
REMSTART
Using "User Defined Types"
The code
type TheBestTypeEver
endtype
Creates a User Defined Type (reffered to as a UDT) with the name "TheBestTypeEver"
This by itself is a empty type, the entire point of using UDTs is to simplify code
by allowing sub variables for a "Parent" variable
to add sub variables to a UDT you simply type them out in between the 'type' and 'endtype'
type TheBestTypeEver
TheBestVariableEver as integer
TheOtherVariable as string
endtype
This adds two sub variables to the UDT, a integer (only "whole" numbers such as 1, 2, 3, 4, -17, 42,.. etc)
named "TheBestVariableEver", and a string named "TheOtherVariable"
Note: if you declare a variable without telling the compiler what type it is, it will
automatically be declared as an integer. So we could have left off the "as integer"
A UDT by itself does nothing at all, you can't assign something to it (such as TheBestTypeEver = 1337)
You have to declare a variable and define it as the type that your UDT is
A UDT is really just a fancy type of variable that you've created custom made for your game
It's used in exactly the same way that you would when you are declaring a variable as a string, float, or integer
bob as integer
bob as TheBestTypeEver
however, UDTs are different than normal variable types because they have sub variables
with "bob as int" you assign a value to it in the normal way, bob = 12
When you have a variable declared as a UDT you have to pick a sub variable to work with
It's easy to tell the compiler which sub variable you want, you just add a period (".")
to the end, then add the name of the sub variable.
so, going with our example, bob as TheBestTypeEver
bob.TheBestVariableEver = 20
bob.TheOtherVariable = "hello world"
That sets the two sub variables in bob to 20, and "hello world" (terribly original i know)
you can then access them just like normal variables
print bob.TheBestVariableEver
print bob.TheOtherVariable
Note: You CANNOT assign anything to the "parent" variable by itself. So bob = 20 would NOT work.
you need to pick a sub variable to assign to.
REMEND
`Create array Player() so it is global (A global variable can be used, but we will cover later why
`there is a preference for arrays over global variables).
`This array is created as a PlayerType array, and has all the attributes of the PlayerType User Defined Type
Dim Player(0) as PlayerType
`Get a free object for the player's ship
Player(0).ObjId = FreeObject()
`Load in the player's ship
Load Object "Data\Ship.x",Player(0).Objid
`Calculate the ratio of the ship to size 6 (making the player a little larger than the aliens)
s#=6.0/Object Size X(Player(0).ObjId)
`Scale the player's ship
Scale Object Player(0).ObjId,s#*100.0,s#*100.0,s#*100.0
`Place the player's ship
Position Object Player(0).ObjId,0,0,0
Set Object Collision To Boxes Player(0).ObjID
Set Object Light Player(0).ObjId,0
`-------------------------
`Player_Controls variables
`-------------------------
`set the player's speed
Player(0).speed# = 0.4
`sets the farthest position the player can travel to the right
rightside# = 77.0
`sets the farthest position the player can travel to the left
leftside# = -77.0
`sets the farthest position the player can travel upwards
topside# = 12.0
`sets the farthest position the player can travel downwards
bottomside# = -9.0
`-------------------------
`End Of Player_Controls variables
`-------------------------
REM -----------------------------------------------------------------------------------
REM UPDATING LOAD BAR
REM -----------------------------------------------------------------------------------
LoadBar(1).length = 60
Display_LoadBar(1)
REM -----------------------------------------------------------------------------------
REM PARTICLES
REM -----------------------------------------------------------------------------------
`Particle Data
`Use this function to set up the particle data, otherwise they wont work.
setupParticles()
`Create a particle emmiter
prtShip=addParticles(0,0,0,60,60)
setParticleSize(prtShip,1.8,-0.03)
colorParticles(prtShip,255,0,0)
setParticleGhost(prtShip,1)
setParticleGravity(prtShip,0,-0.1,0)
`Call this function to actually make all the particles
createParticles()
REM -----------------------------------------------------------------------------------
REM UPDATING LOAD BAR
REM -----------------------------------------------------------------------------------
LoadBar(1).length = 100
Display_LoadBar(1)
REM -----------------------------------------------------------------------------------
REM PRE MAIN LOOP
REM -----------------------------------------------------------------------------------
Position Camera 0,50,-100
ink rgb(255,255,255),1
backdrop on
REM -----------------------------------------------------------------------------------
REM MAIN GAME LOOP
REM -----------------------------------------------------------------------------------
disable escapekey : while escapekey()=0
gosub player_controls
Move_Aliens()
GoSub alien_fire_control
Control_Missile()
text 1,1,"fps :"+STR$(screen FPS())
fastSync
endwhile
End
`For more information on For/Next/Loops, refer to DBPro Help: Principles / Common Statements
`For more information on For/Next/Loops, refer to DBPro Help: Commands / Core Commands
`For more information on Object Commands, refer to DBPro Help: Commands / Basic3D Commands
`For more information on Formulas, refer to DBPro Help: Principles / Datatypes and variables
REM -----------------------------------------------------------------------------------
REM
REM FUNCTIONS DECLARATION
REM
REM -----------------------------------------------------------------------------------
`A quick little function to check for the first free object number.
Function FreeObject()
`Start at object number 1
i=1
`A simple loop
Do
`If the object does not exist (=0), then exit the loop. "i" will be the valid object number
If Object Exist(i)=0 Then Exit
`Move on to the next object number
i=i+1
`Close the loop
Loop
`End the function and return the valid object number
Endfunction i
`For more information on Functions and returning values, refer to DBPro Help (press F1): Principles / Functions
`For more information on Loops, refer to DBPro Help: Principles / Common Statements
`For more information on Loops, refer to DBPro Help: Commands / Core Commands
`For more information on Object Commands, refer to DBPro Help: Commands / Basic3D Commands
`handles all the input from the player
player_controls:
` while not left or right key is pressed, we rotate the ship back to its original angle
Player(0).yang# = curvevalue( 0.0, object angle y( Player(0).ObjId ), 50.0 )
`check if the player is hitting the right key, if they are we want to let them move right
`as long as they are not hitting the right side of the screen
if rightkey() = 1
`move the player to the right at the preset speed
inc Player(0).xpos#, Player(0).speed#
`make sure they haven't passed the right side of the screen
`if they have, then re-position them so that they can't pass it
if Player(0).xpos# > rightside# then Player(0).xpos# = rightside#
` apply rotation to the ship while we move right
Player(0).yang# = curvevalue( -40.0, object angle y( Player(0).ObjId ), 80.0 )
endif
`check in the same way for the left key
if leftkey() = 1
`move the player to the left at the preset speed
dec Player(0).xpos#, Player(0).speed#
`make sure they haven't passed the left side of the screen
`if they have, then re-position them so that they can't pass it
if Player(0).xpos# < leftside# then Player(0).xpos# = leftside#
` apply rotation to the ship while we move left
Player(0).yang# = curvevalue( 40.0, object angle y( Player(0).ObjId ), 80.0 )
endif
`check if the player is hitting the upkey, if they are we want to let them move up
`but not past the barriers
if upkey() = 1
`move the player upwards at the preset speed
inc Player(0).ypos#, Player(0).speed#
`make sure they haven't passed the barriers
`if they have, then re-position them so that they can't pass it
if Player(0).ypos# > topside# then Player(0).ypos# = topside#
endif
`check if the player is hitting the downkey, if they are we want to let them move down
`but not past the bottom of the screen
if downkey() = 1
`move the player downwards at the preset speed
dec Player(0).ypos#, Player(0).speed#
`make sure they haven't passed the bottom of the screen
`if they have, then re-position them so that they can't pass it
if Player(0).ypos# < bottomside# then Player(0).ypos# = bottomside#
endif
`now that we've adjusted the position of the player accordingly, we need to update the object
`that is representing the player
position object Player(0).ObjId, Player(0).xpos#, Player(0).ypos#, 0
rotate object Player(0).ObjId, 0, Player(0).yang#, 0
`Update Particles
positionParticles(prtShip,Player(0).xpos#+plusmin(rnd(1.0)), Player(0).ypos#, 0)
controlParticles()
return
alien_fire_control:
`Decrease the AlienFireFlag counter if it is greater than 0
AlienFireFlag(0)=AlienFireFlag(0)-(AlienFireFlag(0)>0)
` start a for-next loop :: go through each of the bullets
For arrayPos = 0 To 53
obj = EnemyBullet( arrayPos ).ObjId ` get object nr. for this bullet
alien = EnemyBullet( arrayPos ).AlienId ` get object nr. of the alien
If Object Exist(alien)
` If TimeControl = 0 And the bullet is inactive..
If EnemyBullet( arrayPos ).TimeControl = 0 And EnemyBullet( arrayPos ).Active = 0
EnemyBullet( arrayPos ).StartSecond = Timer() ` reset StartSecond
EnemyBullet( arrayPos ).FireHere = 5 + rnd(20) ` set FireHere to 3 seconds + a random of 10 seconds
EnemyBullet( arrayPos ).TimeControl = 1 ` set TimeControl to 1
EndIf
` If TimeControl = 1..
If EnemyBullet( arrayPos ).TimeControl = 1 and AlienFireFlag(0)=0
` increase .CurSecond by 1 each secound
EnemyBullet( arrayPos ).CurSecond = (Timer() - EnemyBullet( arrayPos ).StartSecond) / 1000
` if .CurSecond > FireHere, that means the alien should fire his bullet
If EnemyBullet( arrayPos ).CurSecond > EnemyBullet( arrayPos ).FireHere
EnemyBullet( arrayPos ).Active = 1
EnemyBullet( arrayPos ).TimeControl = 0
`Set the AlienFireFlag counter
AlienFireFlag(0)=60:`Sets the fire rate to approx. 1 second (60 frames at 60 FPS)
EndIf
EndIf
Endif
` if the bullet is active.. [stage 1] - update
If EnemyBullet( arrayPos ).Active = 1
Show Object obj
` update bullet position
EnemyBullet( arrayPos ).xPos = Object Position X( alien )
EnemyBullet( arrayPos ).yPos = Object Position Y( alien )
EnemyBullet( arrayPos ).zPos = Object Position Z( alien )
Position Object obj, EnemyBullet( arrayPos ).xPos, EnemyBullet( arrayPos ).yPos, EnemyBullet( arrayPos ).zPos
` go to stage 2 :: move the bullet
EnemyBullet( arrayPos ).Active = 2
EndIf
` if the bullet is active.. [stage 2] - move
If EnemyBullet( arrayPos ).Active = 2
` apply rotation to the bullet
EnemyBullet( arrayPos ).xAng = 0
EnemyBullet( arrayPos ).yAng = 0
EnemyBullet( arrayPos ).zAng = 180
` update position of the bullet
EnemyBullet( arrayPos ).xPos = EnemyBullet( arrayPos ).xPos + sin( EnemyBullet( arrayPos ).zAng ) * 1.3
EnemyBullet( arrayPos ).yPos = EnemyBullet( arrayPos ).yPos + cos( EnemyBullet( arrayPos ).zAng ) * 1.3
` check if the bullet is outside the screen
If EnemyBullet( arrayPos ).yPos < bottomside#
Hide Object obj
EnemyBullet( arrayPos ).Active = 0
EndIf
` update object
Position Object obj, EnemyBullet( arrayPos ).xPos, EnemyBullet( arrayPos ).yPos, EnemyBullet( arrayPos ).zPos
Rotate Object obj, EnemyBullet( arrayPos ).xAng, EnemyBullet( arrayPos ).yAng, EnemyBullet( arrayPos ).zAng
EndIf
Next arrayPos
return
Function Move_Aliens()
Dim NextAlienMove(0):`Tracks how long until the next alien move
Dim AlienMoveDirection(0):`Tracks which direction the aliens are moving in
Dim AliensXY(1):`Tracks the Aliens position as a group. 0=X, 1=Y
`Start by moving to the right.
If AlienMoveDirection(0)=0 Then AlienMoveDirection(0)=1
`Set the initial Alien Group position if it is not already set
If AliensXY(1)=0
AliensXY(0)=-45
AliensXY(1)=50
Endif
`Decrease NextAlienMove(0) if it is greater than 0
NextAlienMove(0)=NextAlienMove(0)-(NextAlienMove(0)>0)
`If NextAlienMove(0)>0 then exit the function, since no move will be made
If NextAlienMove(0)>0 Then ExitFunction
`Start by counting how many aliens still are alive. This will determine alien speed.
AlienCount=0
`Set the left & right invader trackers so we can determine the left & right most invaders
LeftInvader=8:RightInvader=0
For r=0 to 5: `0 to 5 is 6 rows (0,1,2, 3,4,5)
For i = 0 to 8: `0 to 8 is 9 invaders per row
If Object Exist(Invaders(r,i))
AlienCount=AlienCount+1
if i<LeftInvader then LeftInvader=i
if i>RightInvader then RightInvader=i
Endif
Next i
Next r
`A move will be processed, so set the NextAlienMove(0) counter now
NextAlienMove(0)=AlienCount+3
MoveDown=0
`Check to see if the aliens are to the far right.
If AlienMoveDirection(0)=1
If (RightInvader*10)+AliensXY(0)>70
MoveDown=1
Endif
Endif
`Check to see if the aliens are to the far left
If AlienMoveDirection(0)=-1
If (LeftInvader*10)+AliensXY(0)<-70
MoveDown=1
Endif
Endif
`Calculate the new alien group position
If MoveDown>0
`Move the alien group down
AliensXY(1)=AliensXY(1)-2
`And change directions
AlienMoveDirection(0)=-AlienMoveDirection(0)
Else
AliensXY(0)=AliensXY(0)+AlienMoveDirection(0)*2
Endif
`Reposition Aliens
For r=0 to 5: `0 to 5 is 6 rows (0,1,2, 3,4,5)
For i = 0 to 8: `0 to 8 is 9 invaders per row
x=AliensXY(0)+(i*10)
y=AliensXY(1)+(r*10)
If Object Exist(Invaders(r,i))
Position Object Invaders(r,i),x,y,0
Endif
Next i
Next r
Play Sound 1
Endfunction
`Particle Data
function plusmin(num#)
rand=rnd(10)
if rand>5 then ret#=num#*-1 else ret#=num#
endfunction ret#
function setupParticles()
dim prtsys(0) as tprtsys
endfunction
function createParticles()
count=array count(prtsys())
cmax=0
for c=1 to count
if prtsys(c).count>cmax then cmax=prtsys(c).count
next c
dim prtdat(array count(prtsys()),cmax) as tprtdat
for c=1 to array count(prtsys())
for o=1 to prtsys(c).count
prtdat(c,o).obj=val(getToken(prtsys(c).objc,",",o))
next o
next c
endfunction count
function addParticles(x#,y#,z#,life,count)
array insert at bottom prtsys()
num=array count(prtsys())
prtsys(num).pos.x=x#+plusmin(rnd(0.2))
prtsys(num).pos.y=y#+plusmin(rnd(0.2))
prtsys(num).pos.z=z#+plusmin(rnd(0.2))
prtsys(num).life=life
prtsys(num).count=count
for c=1 to prtsys().count
obj=zp_freeobject() : make object plain obj,100,100
set object transparency obj,3
disable object zwrite obj
position object obj,prtsys(num).pos.x,prtsys(num).pos.y,prtsys(num).pos.z
obj$=obj$+str$(obj)+","
lifep=rnd(life)
life$=life$+str$(lifep)+","
next c
prtsys(num).objc=obj$
prtsys(num).lifep=life$
endfunction num
function setParticleSpeed(num,speed#)
prtsys(num).speed=speed#
endfunction
function setParticleSize(num,size#,sizep#)
prtsys(num).sizei=size#
prtsys(num).sizep=sizep#
for c=1 to prtsys(num).count
obj=val(getToken(prtsys(num).objc,",",c))
scale object obj,size#,size#,1
next c
endfunction
function positionParticles(num,x#,y#,z#)
prtsys(num).pos.x=x#
prtsys(num).pos.y=y#
prtsys(num).pos.z=z#
endfunction
function setParticleGravity(num,x#,y#,z#)
prtsys(num).grav.x=x#
prtsys(num).grav.y=y#
prtsys(num).grav.z=z#
endfunction
function colorParticles(num,r,g,b)
col=rgb(r,g,b)
for c=1 to prtsys(num).count
obj=val(getToken(prtsys(num).objc,",",c))
color object obj,col
next c
endfunction
function setParticleGhost(num,flag)
for c=1 to prtsys(num).count
obj=val(getToken(prtsys(num).objc,",",c))
if flag=1
ghost object on obj
else
ghost object off obj
endif
next c
endfunction
function controlParticles()
for num=1 to array count(prtsys())
for c=1 to prtsys(num).count
prtsys(num).lifec=prtsys(num).lifec+1
prtsys(num).lifecount=prtsys(num).life-prtsys(num).lifec
obj=prtdat(num,c).obj
angx#=angx#+((360/prtsys(num).count)*c)
angy#=angy#+((360/prtsys(num).count)*c)
sx#=object position x(obj)+(sin(angy#)*cos(angx#)*prtsys(num).speed)
sy#=object position y(obj)-(sin(angx#)*prtsys(num).speed)
sz#=object position z(obj)+(cos(angy#)*cos(angx#)*prtsys(num).speed)
sx#=sx#+prtsys(num).grav.x
sy#=sy#+prtsys(num).grav.y
sz#=sz#+prtsys(num).grav.z
size#=prtsys(num).sizei+(prtsys(num).sizep*prtsys(num).lifecount)
position object obj,sx#,sy#,sz#
scale object obj,size#,size#,1
if prtsys(num).lifec>prtsys(num).life
prtsys(num).lifec=prtsys(num).lifec*0
size#=prtsys(num).sizei
position object obj,prtsys(num).pos.x,prtsys(num).pos.y,prtsys(num).pos.z
endif
next c
next num
endfunction
function getEmitterCount()
count=array count(prtsys())
endfunction count
function getParticleCount(num)
count=prtsys(num).count
endfunction count
function zp_freeobject()
repeat
inc i
until object exist(i)=0
endfunction i
function getTokens(st$,sp$)
if left$(st$,1)<>sp$ then nst$=sp$+st$
if right$(st$,1)<>sp$ then nst$=nst$+sp$
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$=sp$ then inc splits
until counter>len(nst$)
tokens=splits-1
endfunction tokens
function getToken(st$,sp$,num)
if left$(st$,1)<>sp$ then nst$=sp$+st$
if right$(st$,1)<>sp$ then nst$=nst$+sp$
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$=sp$ then inc splits
until splits=num or counter>len(st$)
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$<>sp$ then token$=token$+cur$
until cur$=sp$ or counter>len(st$)
endfunction token$
`Player Missile Control
Function Control_Missile()
If Sprite Frame(11)>3
Set Sprite Frame 11,1
Sprite 11,-512,0,11
Endif
If Sprite X(11)>0
Play Sprite 11,1,4,50
Endif
`Check to see of the Missile is hidden. If the missile is hidden, then it has not been launched.
Player(0).FireControl=Player(0).FireControl-(Player(0).FireControl>0)
If Object Visible(Missile(0))=0 and Player(0).FireControl<1
`The missile has not been launched; check to see if the player is pressing the space bar.
If SpaceKey()
`The spacekey is pressed, so launch the missile
`Start by showing the missile
Show Object Missile(0)
`Next, position the missile at the ship's location
Position Object Missile(0),Object Position X(Player(0).ObjID),Object Position Y(Player(0).ObjID), Object Position Z(Player(0).ObjID)
`Make sure the missile is pointing in the correct direction - up.
Rotate Object Missile(0),0,0,0
Player(0).FireControl=40
Play Sound 2
Else
`The missile has not been launched and the player is not pressing the space key - so nothing left to do.
Exitfunction
Endif
Endif
`If the code gets to these lines in this function, the missile has been launched. So, let's move it.
Move Object Up Missile(0),3
mc=Object Collision(Missile(0),0)
if mc=Player(0).ObjID Then Exitfunction
For r=0 to 5: `0 to 5 is 6 rows (0,1,2, 3,4,5)
For i = 0 to 8: `0 to 8 is 9 invaders per row
If mc=Invaders(r,i)
Delete Object Invaders(r,i)
Sprite 11,Object Screen X(Missile(0))-25,Object Screen Y(Missile(0))-45,11
Hide Object Missile(0)
Position Object Missile(0),0,-500,0
Play Sound 3
Endif
Next i
Next r
`Next, check to see if the missile has gone off the screen.
If Object Screen Y(Missile(0))<0
`The missile has gone off the screen, so let's hide it again. Remember, hiding it will stop it and have
`it ready for re-launch.
Hide Object Missile(0)
Endif
Endfunction
function Display_LoadBar(Num)
box LoadBar(Num).x1,LoadBar(Num).y1,LoadBar(Num).x2,LoadBar(Num).y2,rgb(192,192,192),rgb(92,92,92),rgb(192,192,192),rgb(92,92,92)
ink rgb(32,32,32),1
box LoadBar(Num).x1+LoadBar(Num).bdr,LoadBar(Num).y1+LoadBar(Num).bdr,LoadBar(Num).x2-LoadBar(Num).bdr,LoadBar(Num).y2-LoadBar(Num).bdr
if LoadBar(Num).length > LoadBar(Num).width
box LoadBar(Num).x1+LoadBar(Num).bdr+1,LoadBar(Num).y1+LoadBar(Num).bdr+1,LoadBar(Num).x1+LoadBar(Num).width-LoadBar(Num).bdr-1,LoadBar(Num).y2-LoadBar(Num).bdr-1,rgb(255,255,0),rgb(255,255,0),rgb(0,255,0),rgb(0,255,0)
else
box LoadBar(Num).x1+LoadBar(Num).bdr+1,LoadBar(Num).y1+LoadBar(Num).bdr+1,LoadBar(Num).x1+LoadBar(Num).length-1,LoadBar(Num).y2-LoadBar(Num).bdr-1,rgb(255,255,0),rgb(255,255,0),rgb(0,255,0),rgb(0,255,0)
endif
ink rgb(255,255,55),1
text LoadBar(Num).x1+LoadBar(Num).bdr+2,LoadBar(Num).y1 + LoadBar(Num).height+2,LoadBar(Num).name$
sync
endfunction
`UDTs
type vec3
x as float
y as float
z as float
endtype
type tprtsys
objc as string
pos as vec3
life as integer
lifec as integer
lifecount as integer
lifep as string
count as integer
speed as float
sizei as float
sizep as float
grav as vec3
endtype
type tprtdat
obj as integer
endtype
