Results 1 to 5 of 5

Thread: Enemy help???

  1. #1

    Afrostyle Enemy help???

    I have made this game which is like stick defense. I have made 2 enemies and can get one enemy to come on the screen but cant seem to get the other one to. I cant attach the file as it is too big but here is the code I used. thanks


    I am new to flash and dont know much and the code I have given wasnt written by me.


    _root.onLoad = function() {
    //starting a timer to make spawn frequently
    _root.archerstartTime = getTimer();
    //this is just a var to set the names and depths
    _root.archerenemyCounter = 0;
    //creating a delay for the enemy spawn
    _root.archerdifficulty = 2000;
    //loading the cursor in a higher depth than the enemies
    _root.attachMovie("cursor", "cursor", 1000);
    _root.cursor._xscale=70
    _root.cursor._yscale=70 //starting a timer to make spawn frequently
    _root.swordstartTime = getTimer();
    //this is just a var to set the names and depths
    _root.swordenemyCounter = 0;
    //creating a delay for the enemy spawn
    _root.sworddifficulty = 2000;
    };
    _root.onEnterFrame = function() {
    //this is other var to see the current time
    _root.swordcurrentTime = getTimer();
    //for each delay time a new enemy is spawned
    if (_root.swordcurrentTime-_root.swordstartTime>=_root.sworddifficulty) {
    //setting the enemy number
    _root.swordenemyCounter++;
    //putting the enemy on stage
    _root.swordcurrentEnemy = _root.attachMovie("swordenemy", "swordenemy"+_root.swordenemyCounter, 500+_root.swordenemyCounter);
    //putting the enemy in the right place of the stage!
    _root.swordcurrentEnemy._y = random(150)+150;
    _root.swordcurrentEnemy._x = -100;
    //I think they are too big... resizing
    _root.swordcurrentEnemy._xscale = 17;
    _root.swordcurrentEnemy._yscale = 17;
    //this line says: "-come back in one second"
    _root.swordstartTime = _root.swordcurrentTime;
    //setting max dificulty(spawning frequency)

    }
    //for each 30 seconds we will clear our index
    if (_root.swordcurrentTime-_root.swordstartTime>=30000) {
    //this will make names repeat
    _root.swordenemyCounter = 0;
    //this is other var to see the current time
    _root.archercurrentTime = getTimer();

    //for each delay time a new enemy is spawned
    if (_root.archercurrentTime-_root.archerstartTime>=_root.archerdifficulty) {
    //setting the enemy number
    _root.archerenemyCounter++;
    //putting the enemy on stage
    _root.archercurrentEnemy = _root.attachMovie("archerenemy", "archerenemy"+_root.archerenemyCounter, 500+_root.archerenemyCounter);
    //putting the enemy in the right place of the stage!
    _root.archercurrentEnemy._y = random(150)+150;
    _root.archercurrentEnemy._x = -100;
    //I think they are too big... resizing
    _root.archercurrentEnemy._xscale = 17;
    _root.archercurrentEnemy._yscale = 17;
    //this line says: "-come back in one second"
    _root.archerstartTime = _root.archercurrentTime;
    //setting max dificulty(spawning frequency)

    }
    //for each 30 seconds we will clear our index
    if (_root.archercurrentTime-_root.archerstartTime>=30000) {
    //this will make names repeat
    _root.archerenemyCounter = 0;
    }
    }
    };
    Last edited by sam_vickery; July 24th, 2008 at 11:11 AM.

  2. #2
    hi there!

    I read your code. Apparently, you don't have to get your enemies on screen by yourself.
    There is a Timer, and each 2 secs time delay, a new ennemy should appear on screen by the left side.
    All you have to do is to create a MC in your library and name it "swordenemy" (and also it's linkage name by the properties panel).
    You can change the difficulty by modifing the variable archerdifficulty (increase it for more difficulty).

  3. #3
    I have done that but only the sword enemy comes on the screen. I just dont know what to do. Is there any errors in the code that I cant find?

  4. #4
    calm down sam
    I will take a look at the files in the weekend
    i'm at work now, and the only time I have for coding is at the weekend.

    but I will see what I can do for you now.


    ps: for those who didn't see the first topic: the code is mine

    "A human can interpret missing logic but a computer can't." - wkt
    "That goes into the 'too bad' box." - TOdorus
    "This is a three year old thread, there's no reason to post here..." - flyingmonkey456
    "Despite beeing the oposite, they look very similar to me." - SparK

  5. #5
    here's your brand new code!
    (erase everything then put it in place)

    Code:
    _root.onLoad = function() {
        //starting a timer to make spawn frequently
        _root.startTime = getTimer();
        //this is just a var to set the names and depths
        _root.enemyCounter = 0;
        //creating a delay for the enemy spawn
        _root.difficulty = 2000;
        //loading the cursor in a higher depth than the enemies
        _root.attachMovie("cursor", "cursor", 1000);
        _root.cursor._xscale=70
        _root.cursor._yscale=70 //starting a timer to make spawn frequently
    }
    _root.onEnterFrame = function() {
        //this is other var to see the current time
        _root.currentTime = getTimer();
        //for each delay time a new enemy is spawned
        if (_root.currentTime-_root.startTime>=_root.difficulty) {
            _root.spawnEnemy("swordenemy");
            if(_root.currentTime-_root.startTime>=_root.difficulty*2){
                _root.spawnEnemy("archerenemy");
                //this line says: "-come back in one second"
                _root.startTime = _root.currentTime;
            }
        }
        
        //for each 30 seconds we will clear our index
        if (_root.currentTime-_root.startTime>=30000) {
            //this will make names repeat
            _root.enemyCounter = 0;
        }
    }
    
    _root.spawnEnemy = function(enemyName){
        //setting the enemy number
        _root.enemyCounter++;
        //putting the enemy on stage
        var currentEnemy = _root.attachMovie(enemyName, "enemy"+_root.enemyCounter, 500+_root.enemyCounter);
        //putting the enemy in the right place of the stage!
        currentEnemy._y = random(150)+150;
        currentEnemy._x = -100;
        //I think they are too big... resizing
        currentEnemy._xscale = 17;
        currentEnemy._yscale = 17;
    }
    EDIT:

    hey man!
    good news, i worked on a level system for the game!
    it's working, it's working! muahahahaha XD
    ==
    Attached Files Attached Files
    Last edited by SparK_BR; July 30th, 2008 at 06:28 AM.

    "A human can interpret missing logic but a computer can't." - wkt
    "That goes into the 'too bad' box." - TOdorus
    "This is a three year old thread, there's no reason to post here..." - flyingmonkey456
    "Despite beeing the oposite, they look very similar to me." - SparK

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012