A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Loosing damage while shooting

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    4

    Loosing damage while shooting

    Hi,

    I'm making a platform game, where you can shoot enemies. The shooting animation is inside my character's movie clip and in the final frame of this shooting animation, there's a lightning, which is the one that kills the enemy.

    Now, when I put this following code in the enemy movie clip;

    onClipEvent(enterFrame){
    if(_root.hahmo.shoot.salama.hitTest(this)){
    this.nextFrame();

    }
    }

    onClipEvent(enterFrame){
    if(_root.hahmo.hitTest(this)){
    _root.GOTHIT();
    }
    }

    ...the enemy falls back like it should and dies. But then also happens something I don't want to; my character loses one heart. I know this is pretty easy one to solve, but i'm not very good at actionscript 2 yet.

    Here's my character's code (it's on frame);

    invulnerable=0;
    invTime=1.5;

    function GOTHIT(){
    if(!invulnerable){
    invulnerable=1;
    _root.vcam.tayssydan.nextFrame();
    clearTimeout(fff);
    fff=setTimeout(function(){invulnerable=0;},invTime *1000);
    }
    }

    I've tried almost everything here, but like I said, i'm not very good at actionscript 2. You've probably noticed english isn't my first language, so here's some explaining
    hahmo = character
    salama = lightning
    tayssydan = fullheart

    Plz help, my game is almost ready and this is the only problem I can't figure out. Thanks

  2. #2
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    I'd really appreciate if someone could help me with this amateur problem. Anything? I hate to beg twice like this, but my game is now all ready, except when it comes to that annoying problem. Thank you.

  3. #3
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,145
    You need to post your fla files. We need to see where that actionscript is placed. Plus it's far faster and easier to debug.

  4. #4
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    https://www.dropbox.com/s/bgnb3294qmzphn5/game.fla ask if there's too weird words, I tried to check that but i may be too blind to my native language words. I haven't said yet that vihollinen means the enemy there.

    I really this, thank you! The hearts (sydan or sydän) are inside vcam.

  5. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    ...apparently there's a one missing word, meant to say I really appreciate this. Still haven't figured this out though, I tried couple of times.

  6. #6
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    vihollinen movieclip:

    PHP Code:
     onClipEvent(enterFrame){
        if(
    _root.hahmo.hitTest(this) && _root.attack == false)
        {
            
    _root.vcam.tayssydan.nextFrame();
        }

    characterX layer script:

    PHP Code:
    stop();
        var 
    grav:Number 5;
        var 
    gravity:Number 2;
        var 
    speed:Number 10.5;
        var 
    maxJump:Number = -22;
        var 
    touchingGround:Boolean false;
        var 
    attack:Boolean false;
        
        

    function 
    onEnterFrame() {
        
    hahmo._y += grav;
        
    grav += gravity;
        while (
    ground.hitTest(hahmo._xhahmo._ytrue)) {
        
    hahmo._y -= gravity;
        
    grav 0
    }if (
    ground.hitTest(hahmo._xhahmo._y+5true)) {
        
    touchingGround true;
    } else {
        
    touchingGround false;

    }if (
    ground.hitTest(hahmo._x-(_width/2), hahmo._y-(_height/2), true)) {
        
    hahmo._x += speed;
    }if (
    ground.hitTest(hahmo._x+(_width/2),hahmo_y-(_height/2), true)) {
        
    hahmo._x -= speed;
    }if (
    ground.hitTest(hahmo._xhahmo._y-(height), true)) {
        
    grav 3;

    }else if (
    Key.isDown(Key.UP) && touchingGround) {
        
    grav maxJump;
    }else if(
    Key.isDown(Key.RIGHT) && touchingGround || Key.isDown(Key.RIGHT) && !touchingGround){
        
    hahmo._x+=speed;
        
    hahmo.gotoAndStop(2);
        
    hahmo._xscale 100;
        if(
    hahmo.hitTest(_root.vihollinen)){
            
    hahmo._x-= speed;
        }
    }

    else if(
    Key.isDown(Key.LEFT) && touchingGround || Key.isDown(Key.LEFT) && !touchingGround){
        
    hahmo._x-=speed;
        
    hahmo.gotoAndStop(2);
        
    hahmo._xscale = -100;
        if(
    hahmo.hitTest(_root.vihollinen)){
            
    hahmo._x+= speed;
        }

    }else if(
    Key.isDown(Key.SPACE) && touchingGround || Key.isDown(Key.SPACE) && !touchingGround){
        
    hahmo.gotoAndStop(3);
        
    attack true;
        if(
    hahmo.shoot.salama.hitTest(vihollinen) && attack == true){
            
    unloadMovie(vihollinen);
            
    GOTHIT();
        }

    }else{
        
        
    hahmo.gotoAndStop(1);
    }
    }

    invulnerable=0;    
    invTime=1.5;    

    function 
    GOTHIT(){
        if(
    invulnerable == 0){
            
    invulnerable=1;
            
    clearTimeout(fff);
            
    fff=setTimeout(function(){invulnerable=0;},invTime*1000);
            }
            
    attack false;
        } 

    The vCam is buggy, so i'm not touching that script today. If you need help with vCam I may help you later or one of the forum's users.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center