Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > Simple Stuff (Newbies)

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-29-2010, 09:25 PM   #1
undecillion
Registered User
 
Join Date: Jun 2010
Posts: 9
Question duplicating an object and its code

Hi everyone, i was making a space shooting game, where you control
a horizontally moving ship and fire with the space bar. I want to get asteroids to come from the top of the screen and go down, and if they go past the bottom of the screen, you lose a life.

so far, I have one asteroid that does precisely what i want it to do, the code for the asteroid is as follows (entered in the main timeline) :

ActionScript Code:
for (var i = 0; i<bulletCount; i++) {         var b = bulletArray[i];         if (b._y>0) {             b._y -= bulletSpeed;         } else {             removeMovieClip(b);             bulletArray.splice(i, 1);         }         if (!hit) {             if (b.hitTest(ob)) {                 hit = true;                 ob.play();                 b.play();                 _root.score +=500;                 b._y -= bulletSpeed;                 bulletArray.splice(i, 1);                 removeMovieClip(b);             }         }     } } var nrEnemies = 3; for (i = 1; i < nrEnemies; i++) {     _root.ob.duplicateMovieClip("asteroid" + i, _root.getNextHighestDepth()); } var hit = false; var obSpeed = 5; var earthSpeed = 1; function createObject(o) {     ob = this.attachMovie(o, o, 100);     ob._x = random(460) + 20; } function resetObject() {     ob._x = random(460)+20;     ob._y = -40;     ob.gotoAndStop(1);     ob.restart = false;     hit = false     } function loseLife() {     earthMc._y = 360;     } function lostlife() {     earthMc._y += earthSpeed; } function moveObject() {     if (ob._y<400) {         ob._y += obSpeed;         _root.score +=1         lostlife();     } else {         ob.play();         resetObject();         _root.lives -=1;         loseLife();             }     if (ob.restart) {         resetObject();         }     } createObject("asteroid", "asteroid", (0));

my problem is that i only have one asteroid and the game is far too easy.
Is there a way to change the code or make a new one so that there will be more than one asteroid on the screen with the same properties?

any and all help is greatly appreciated.

Last edited by undecillion; 06-29-2010 at 09:29 PM.
undecillion is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:52 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.