A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Help with glitchy arcade shooter game

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    2

    Unhappy Help with glitchy arcade shooter game

    So hey guys, I'm pretty newbie at making Flash games - in fact this is my first scroller, I've only played around with a dressup and dating sim - and coding using actionscript (and coding in general, only done a little bit of VB and Python before). I've been following a nice arcade side-scroller tutorial on this site which has three parts, if you want to view and go over them to help. It was designed for Flash 5 and I'm using Flash 8 Pro. :\

    Building Games in Flash5 Part1: Player Movement and Fire
    Building Games in Flash 5 - Part 2 - Scrolling
    Building Games in Flash 5 - Part 3 - Enemies and collisions


    Anyway, as I was going through and coding/drawing the whole thing I came across a lot of problems and glitches (and a lot of times when the game coding would crash and I'd have to abort it and remake the entire coding again). I sort of stumbled around blindly, deleting and editing code to get things to work, and I'm up to the point where I'm almost finished with the thing. It's still glitchy though.

    I was wondering if any Flash coders could help me out? I would really, really appreciate it a lot, since I'm going to be creating a Flash game for my programming class and I would prefer if it wasn't screwy (if I need to remake it with less cutesy graphics). xD;; If you could download the .Fla file and fix the coding problems I have, or even just point out where I'm going wrong, that would be amazing. <3


    Playable SWF game on my deviantart account
    .FLA downloadable file (@ Mediafire; no viruses, trojans, blahblah attached)


    Problems:

    • The enemies tend to randomly explode before the missile has even hit them.
    • The original enemy movie clip doesn't even want to explode.
    • The score counter won't tick for each kill.
    • The boundary box (?) of the player/enemy seems to be too big. You die before you should - in certain positions the enemy gets close and I guess the boundary boxes hit, which initiates the hitTest. It seems premature though, I'm wondering if I can reduce the boundary box, or have it so the enemy and player collide on the actual graphic, and not the movie clip box? I have no idea if this makes sense, I hope it does.
    • There seems to be a bunch of other small glitches too.



    If you don't want to download the game, here's the coding which might help.

    Player character:
    PHP Code:
    onClipEvent(load){

        
    moveSpeed=16;
         
    _root.laser._visible=false;
         
    laserCounter=1;
        
    scrollx=_root.mainGround.ground._width/6;
        
    scrollStart=true;
        }
        
        
        
        
    onClipEvent (enterFrame) {
        
    if (
    Key.isDown(Key.SPACE)) {
     
    laserCounter++;
     
    _root.laser.duplicateMovieClip"laser"+laserCounterlaserCounter );
     
    _root["laser"+laserCounter]._visible=true;

     } 
    if (
    Key.isDown(Key.RIGHT)) {
             if (
    this._x<>scrollx){
                 
    this._x+=moveSpeed;
             } else {
                 
    scrollStart=true;
     }
         } else if (
    Key.isDown(Key.LEFT)) {
             
    this._x-=moveSpeed;
     }


        if (
    Key.isDown(Key.DOWN)) {
             
    this._y+=moveSpeed;
         } else if (
    Key.isDown(Key.UP)) {
             
    this._y-=moveSpeed;
     }
    }

    onClipEvent (keyUp) {
     if (
    Key.getCode() == Key.RIGHT) {
     
    scrollStart=true;
     }



    Enemy:
    PHP Code:
    onClipEvent (load) {
         function 
    reset(){
             
    this._x=700;
             
    this._y=random(199)+50;
             
    enemy1Speed=random(13)+4;
            
    this.gotoAndStop(1);
     }
     
    reset();
    }

    onClipEvent (enterFrame) {
     if (
    _root.player.scrollStart){
     
    this._x-=enemy1Speed;
     }
     if (
    this._x<-150) {
     
    reset();
     }
     if (
    this.hitTest_root.player ) ){
     
    _root.gotoAndStop "gameOver" );
    }


    Missile:
    PHP Code:
    onClipEvent (load) {

      
    laserMoveSpeed=20;
      
    this._x=_root.player._x+140
      
    this._y=_root.player._y+40;

    }

    onClipEvent (enterFrame) {
      
    this._x+=laserMoveSpeed;
      if (
    this._x>700){
        
    _root.player.laserCounter--;
        
    this.removeMovieClip();
      }

      for (
    i=1i<=_root.numEnemy1i++){
         if (
    this.hitTest_root["enemy1"+i])){
            
    _root.score+=100;
            
    _root["enemy1"+i].gotoAndPlay);
            }
        
      }


    Control layer randomiser:
    PHP Code:
    numEnemy1=4;

    for (
    i=2i<=numEnemy1i++){
        
    enemy1.duplicateMovieClip"enemy1"+ii+100 );




    I hope that's enough information~

  2. #2
    Senior Member
    Join Date
    Mar 2000
    Posts
    116
    First problem..

    on the control layer of the root.. put this..

    score = 0;

    select the score text box. in the "var" field of the properties window. enter "score".

    This will start your score as a number set to 0 and link the text field to the score variable.
    Webpages:

    www.winningsolutionsinc.com

  3. #3
    Senior Member
    Join Date
    Mar 2000
    Posts
    116
    Second problem..

    on the control layer you have..

    for (i=2; i<=numEnemy1; i++){
    enemy1.duplicateMovieClip( "enemy1"+i, i+100 );

    }

    change it to.. (remove the 1 in "enemy1")

    for (i=2; i<=numEnemy1; i++){
    enemy1.duplicateMovieClip( "enemy"+i, i+100 );

    }

    now look at the actions on your missile.. ditch the 1 in "enemy1" in both places bolded below.

    for (i=1; i<=_root.numEnemy1; i++){
    if (this.hitTest( _root["enemy1"+i])){
    _root.score+=100;
    _root["enemy1"+i].gotoAndPlay( 2 );
    }

    }

    Score should be fixed now.. and all monster can be shot! New problem.. you will start with a "missile" being fired. DOH!
    Webpages:

    www.winningsolutionsinc.com

  4. #4
    Senior Member
    Join Date
    Mar 2000
    Posts
    116
    Next fix.. this is for the bug that shows up.. probably from the get go.. but even more noticable with my fixes from above..

    change the code on the missile from..

    onClipEvent (load) {

    laserMoveSpeed=20;
    this._x=_root.player._x+140;
    this._y=_root.player._y+40;

    }

    To..

    onClipEvent (load) {
    if(_root.myFlag == undefined) {
    _root.myFlag = true;
    this.removeMovieClip()
    }
    else {
    laserMoveSpeed=20;
    this._x=_root.player._x+140;
    this._y=_root.player._y+40;
    }

    }

    This will remove the first missile.. since the "fire" button wasn't pushed anyway.
    Webpages:

    www.winningsolutionsinc.com

  5. #5
    Senior Member
    Join Date
    Mar 2000
    Posts
    116
    Okay.. i guess we are going to have to move it off screen too..


    onClipEvent (load) {
    if(_root.myFlag == undefined) {
    _root.myFlag = true;
    this.removeMovieClip();
    _root.laser._y = -30;
    }
    else {
    laserMoveSpeed=20;
    this._x=_root.player._x+140;
    this._y=_root.player._y+40;
    }

    }

    I think this is because an initial movieclip can't remove itself.

    Don't know for sure.. it fixes the issue, in a "hack" way.. but this is old as2 coding.. and resembles as1 more than anything.. back then, hacks was what it was all about.

    For your hit box issue.. tough one there man.. my suggestion for a quick fix.. would be to make an "invisible" box in both of the player and enemy movieclips, some what smaller than their normal hit box.. and check those on the hit test. There is no way that I know of it do a "per pixel" hit test with as2 without having to write a custom function.

    You can do per pixel detection with the hitTest function.. but only for a certain point.

    aka..

    public hitTest(x:Number, y:Number, [shapeFlag:Boolean]):Boolean

    but, like i said.. this checks a POINT.. not another object... and looping through this bad boy for every point in the "enemy" target would be rather processor intensive.
    Webpages:

    www.winningsolutionsinc.com

  6. #6
    Senior Member
    Join Date
    Mar 2000
    Posts
    116
    • The enemies tend to randomly explode before the missile has even hit them. (FIXED)
    • The original enemy movie clip doesn't even want to explode. (FIXED)
    • The score counter won't tick for each kill. (FIXED)
    • The boundary box (?) of the player/enemy seems to be too big. (SUGGESTED POSSIBLE FIX)


    Cheers!!!
    Webpages:

    www.winningsolutionsinc.com

  7. #7
    Junior Member
    Join Date
    Aug 2009
    Posts
    2
    Oh man, thank you so much. <3 I really appriciate all the effort you've put into replying and answering my problems!

    I don't have access to Flash here on this computer, but when I do, I'll deffinetly fix all the problems and see if there's any more glitches. I just wanted to reply now and say thank you~ You've cured my headache. xD

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