converting as3 turet targeting to events

0 favourites
  • 3 posts
From the Asset Store
14 amazing sound files of game events like Level Ups, Level Completes, object spawn, object taking etc.
  • *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:

    yoelscripts.cowhosting.net/flashpunk%20_source/td.swf

    thats the code:

    private function obtainTarget():void
              {
                  ?if (!active1) { return;  };//exit//if not active do nothing
                  ?//trace("bla");
                  ?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)
                    {
                             //trace("in");
                        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;}
                                ??//SFX.towerShoot.play();
                                ??//create bullet
                                ??//trace("shoot");
                                ??world.add(new bullet(x,y,speed_shoot,dmg,twoer_type,1500,targ_enemy));
                                ??break;
                        }
                        _loc_2 = _loc_2 + 1;
                    }//end while
                
                        
                        //reset shoot cooldwom
                        shot_delay_count = 0;
                  ?}//end count delay     
                  ?
                  ?
              }//end obtainTarget
    [\code]
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

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

    i kinda figured stuff out.

    s608.beta.photobucket.com/user/adamrain/media/13267_zps98206b7e.png.html

    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?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)