converting as3 turet targeting to events

Get help using Construct 2

Post » Thu Dec 20, 2012 5:09 pm

*to make things simple i need that turret object can shot enemies within range (range is a turret var).

*and how do i upload my cpx to scirras db?
because i did make a waypoint system for enemy waves and want to share it.

if there's a way for me to learn how to convert my code into events i will be happy for advice about that.

it will be cool to have guides for programers to convert there code to events.

thats the orignal game i started to make with flashpunk:

thats the code:

private function obtainTarget():void
              if (!active1) { return; };//exit//if not active do nothing
              var _loc_1:Array = null;
            var _loc_2:int = 0;
              var targ_enemy:enemy = null;
              shot_delay_count += FP.elapsed;;
              if (shot_cooldown < shot_delay_count)
                    //new array
                    _loc_1 = [];
               world.getType("enemy1", _loc_1);
               _loc_2 = 0;
                   while (_loc_2 < _loc_1.length)
                    targ_enemy = _loc_1[_loc_2] as enemy;
                         //trace(distanceFrom(targ_enemy, true));
                    if (distanceFrom(targ_enemy,true) < range)
                            //chack target type if not the same stop or if all target typs shot
                            if (targ_enemy.type_enemy == target_type ||
                            targ_enemy.type_enemy =="both") { }else{break;}
                            //create bullet
                            world.add(new bullet(x,y,speed_shoot,dmg,twoer_type,1500,targ_enemy));
                    _loc_2 = _loc_2 + 1;
               }//end while
                    //reset shoot cooldwom
                    shot_delay_count = 0;
              }//end count delay     
          }//end obtainTarget
[\code]antrax2012-12-20 17:12:33
Posts: 5
Reputation: 360

Post » Thu Dec 20, 2012 6:45 pm

Is the ActionScript your own work? If you know how to write a situation in AS "converting" to C2 is very easy!

After a brief look at your code, it looks like the first stanza (I like poems!) deals with the default behaviour of the turret, you can do this easily in C2 with a boolean variable as the condition for your entire event,just make a boolean variable called TurretActive.

Second stanza looks like a cooldown effect, this is also quite easy with events, simply make a variable called Cooldown that is set to a number (Let's say 3) every time the turret fires, and decrememnts by the value of 1 every time the turret fires.

Finally you've got your turret actually firing, for this you want to make sure that you have three conditionals for this event. The first is that TurretActive is set to True, the second is that Cooldown has a value less than or equal to 0.

The third conditional is the distance from the target, again this can be a boolean variable, and can draw it's values from the .distance expression, comparing your turret and target sprite. Set the bool to true if the distance is close enough (say 500?)

When all of these conditions are met, it's a simple matter of spawning a sprite with the bullet property at the angle of your target, which you can do with the angle expression.

You can add all kinds of finishing touches like rotating you turret, imagepoints and the like; if you're dealing with many targets it will be worthwhile reading up on unique IDs and sprite picking.

C2 is effectively pseudocode, if you have a good grasp of your mechanics it's an absolute joy to use.
Posts: 540
Reputation: 5,636

Post » Thu Dec 20, 2012 7:17 pm

thank you Mr E Bear, i realy liked the poem metaphor.

i kinda figured stuff out.

one of the mods told me rtfm so i kinda did,also used faq about homing missiles.

about cooldown its timer based,ill try to see how it works.

i realy want to upload the project file so everyone can use it(like i did in flashpunk all my code is free for all).
(i can use my own servere but would like to upload to some scirra db).

isnt pasodo code is based on logics? thats what you meant?antrax2012-12-20 19:19:01
Posts: 5
Reputation: 360

Return to How do I....?

Who is online

Users browsing this forum: Solomon and 29 guests