1. a title screen with music
2. player graphic that moves about
3. a scrolling landscape
4. missiles
Now we need something to shoot, once again instead of dumping everything directly into our game I'll make a small stack for developing some enemies and testing their scripts first.
So the Enemy Factory stack works nearly exactly like the Missile Factory:
We generate graphics with "Regular" style, this time with a bunch of random numbers for their colors, linesize, occasional dashes, outerGlow and sometims their opaque property with an innerShadow, we keep their script handy in a button and then copy that script to the objects.
Here'se the basic code
MakeEnemies
Code: Select all
on MakeEnemies
put 0 into Rows
put 0 into Cols
put the script of button "EnemyScript" into EnemyBehavior
repeat with N = 1 to 20
create graphic
set the script of the last graphic to EnemyBehavior
set the name of the last graphic to "Enemy"&N
set the style of the last graphic to "regular"
set the polySides of the last graphic to 3+random(10)
set the height of the last graphic to 15+random(30)
set the width of the last graphic to 15+random(30)
set the loc of the last graphic to 50+(50*Cols), 50+(Rows*50)
put item N of colorList into tColor
set the foregroundColor of the last graphic to tColor
put random(10) into dashrand
if dashrand > 7 then
set the dashes of the last graphic to random(3)
end if
set the lineSize of the last graphic to random(4)
Glamour
add 1 to Cols
if Cols > 4 then
put 0 into Cols
add 1 to Rows
end if
end repeat
end MakeEnemies
Code: Select all
on Glamour
put item random(20) of colorList into tColor
put RGBFromColorName(tColor) into fgColor
add random(100) to item 1 of fgColor
add random(100) to item 2 of fgColor
add random(100) to item 2 of fgColor
set outerGlow of the last graphic to true
set the outerGlow["color"] of the last graphic to fgColor
set the outerGlow["spread"] of the last graphic to 24+random(40)
set the outerGlow["size"] of the last graphic to 24+random(40)
set colorOverlay of the last graphic to false
subtract random(100) from item 1 of fgColor
subtract random(100) from item 2 of fgColor
subtract random(100) from item 2 of fgColor
put random(10)into OpaRand
if OpaRand > 8 then
set the opaque of the last graphic to true
set the backgroundcolor of the last graphic to "White"
set innerShadow of the last graphic to true
set the innerShadow["color"] of the last graphic to fgColor
set the innerShadow["spread"] of the last graphic to 24+random(40)
set the innerShadow["size"] of the last graphic to 24+random(40)
end if
end Glamour
The enemy scripts call ActivateBullets from the main stack script so I added the enemy bullets in the stack along with their scripts and everything works mostly just like the Missile Factory, only we don't test/adjust bullet speeds since they are randomized and rely on the player to target...hmm, might have to make the Enemy Factory bigger to test against a "Player" object. But for now these are the elements:
button "Make Enemies" -- calls MakeEnemies handler
button "Get Enemies" -- calls GetEnemies handler
button "Stage Enemies" -- calls StageEnemies handler
button "Activate Enemies" -- calls ActivateEnemies and continues to do so while the mouse is the button rect
button "Edit Enemy Script"[i/] -- opens script editor to the script of button "EnemyScript"[/i]
button "EnemyScript" -- contains the script that is copied to the "Enemy" graphic objects
There's another column of buttons for the missiles that do all the same stuff for them, with the addition of:
button "Style" -- sets the graphic style of the bullets to Regular, Rectangle, Oval or Line
The GetEnemies, StageEnemies, GetBullets, StageBullets scripts work like their counterparts do in the Missile Factory stack, ie, they either present the objects on the stack or hide them away off screen.
The "Get..." buttons and their handlers also act to update the scripts of the objects, use those if you've modified the script of their respetcive script "*Script" buttons.
Okay next to explain the script of button "EnemyScript the ActivateEnemies, InactiveEnemies, and EnemyExplosions handlers and then we'll get into some actual math with the bullets.