two projectiles
BlitzMax Forums/BlitzMax Beginners Area/two projectiles
| ||
hey everyone. Currently I have a ship able to fire one projectile at a time. Which is drawn, updated, deleted when neccessary and collision is checked for.. what I'd like to try is have two instances in the same projectile fire when you fire. So say the ship has missile launchers on the left wing and the right wing... when I fire i want two separate and distinct objects to come out. The problem is that so far how ive been trying it, ive been duplicating the previous code, except this time referencing the second instance, it just seems unneccessary and i was wonder what would be a better way to go about it. so far when you fire, missle:tmissle = new tmissle is created. I went about putting in missle2:tmissle = new t missle would that be the right way to go about it? |
| ||
no What you would do would place all created missiles in a missile list and update all missiles on that list in the "update projectile" function you have. |
| ||
currently i place all in a list. but if i only have one missle object instanced when I fire, i only have one missle.x and missle.y to work with, so i cant affect the launch location of the first missile, without affecting, the position of the second one... without a separate instance |
| ||
in my update projectile function i am using for missile = eachin tmissile.list where the missile object is the actual reference to my missile object right now. and the update function updates that specific missle, draws it moves it, by refering to each field that I need to like this, missle.x, missle.y, missle,frame, missile.age etcetc... maybe there is a way to let it update each missles fields in that list, but its going over my head.. LOL |
| ||
currently i place all in a list. but if i only have one missle object instanced when I fire, i only have one missle.x and missle.y to work with Don't create with new then. Add a Create() function to your missile type, which takes the x and y coordinates as parameters and creates a new missile and adds it to the list. It's much neater that way. |
| ||
in my update projectile function i am using for missile = eachin tmissile.list where the missile object is the actual reference to my missile object right now. and the update function updates that specific missle, draws it moves it, by refering to each field that I need to like this, missle.x, missle.y, missle,frame, missile.age etcetc... maybe there is a way to let it update each missles fields in that list, but its going over my head.. LOL so how would I go about updating the new missiles values as stated above.. gotta change the update function some how, so it only doesnt refer to the first missile object only, but all the objects. |
| ||
What? for missile = eachin tmissile.list where the missile object is the actual reference to my missile object right now. No, that goes through every missile in the list. If it's not doing every missile, you're not putting them all in the list. so how would I go about updating the new missiles values as stated above.. gotta change the update function some how, so it only doesnt refer to the first missile object only, but all the objects. It *isn't* just doing the first missile object. That's why it's called EachIn and not FirstIn. |
| ||
what if the update function is only refering to the first missiles fields? For missile = EachIn missile.List missile.age :+ 1 If missile.age > 150 PlaySound(missileExplosionFx:TSound) RemoveLink missile.link End If SetRotation missile.angle SetBlend ALPHABLEND SetAlpha 1.0 SetColor(255,255,255) MidHandleImage (missile.Image) SetScale 2,2 DrawImage(missile.Image,missile.x,missile.y,missile.frame) missile.frame:+ 1 If missile.frame = 30 Then missile.frame = 0 missile.vx:+ Sin(missile.angle) * missile.speed missile.vy:+ Cos(missile.angle) * missile.speed missile.x :+ missile.vx missile.y :- missile.vy |
| ||
Small Sample: Maybe it helps. |
| ||
very nice klepto! |