| View previous topic :: View next topic |
| Author |
Message |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu Jul 31, 2008 6:06 am Post subject: [Flash/AS] Falling objects |
|
|
I'm trying to make a game for my DA profile where random objects fall down and you have to collect them (and dodge some).
So far i have:
| Code: | var drops = new Array( "_shuriken", "_kunai", "_konoha", "_kibaCollect" );
var count = 0;
function SpawnDrop ()
{
var Drop:MovieClip;
Drop._x = Math.Random()*Stage.width;
Drop._y = 0;
if( count <= 35 ) {
Drop.attachMovie( trace(drops[ Math.Random()*3 ]), "_dropTmp", count, count );
Drop.onEnterFrame = StartDrop(Drop);
} else {
gotoAndStop(3); // Leave to the completion frame
}
count++;
}
var IntID = setInterval( SpawnDrop, 3000 );
function StartDrop ( item )
{
var gravity = 6;
item._y += gravity;
item._y += item._y;
if (item.hitTest(_root.tray))
{
trace("Item fell");
delete item.onEnterFrame;
}
} |
Does anyone know why NOTHING appears or falls? if i change "item" to "this" in the StartDrup function, the whole stage falls down so I know that the falling works.
|
|
| Back to top |
|
 |
merlin22 Master Cheater
Reputation: 0
Joined: 29 Mar 2008 Posts: 267
|
Posted: Thu Jul 31, 2008 8:08 am Post subject: |
|
|
| Code: |
var drops = new Array( "_shuriken", "_kunai", "_konoha", "_kibaCollect" );
function SpawnDrop ()
{
for (i=0; i<35; i++) {
var Drop:MovieClip = _root.attachMovie("lol", "Drop",+_root.getNextHighestDepth, _root.getNextHighestDepth)
Drop._x = Math.random()*Stage.width;
Drop._y = 0;
Drop.onEnterFrame = function() {
var gravity = 2
this._y += gravity;
this._y += 2
if (this.hitTest(_root.tray))
{
trace("Item fell");
this.unloadMovie()
}
}
}
}
var IntID = setInterval( SpawnDrop, 3000 );
|
I fixed the ball falling speed for you because it was way to fast.
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu Jul 31, 2008 8:25 am Post subject: |
|
|
Thanks! Things actually fall down now but i'm still having problems with my array. Whenever i use trace like this:
| Code: | | trace(drops[ Math.Random()*3 ]) |
It outputs "undefined". Any ideas?
|
|
| Back to top |
|
 |
merlin22 Master Cheater
Reputation: 0
Joined: 29 Mar 2008 Posts: 267
|
Posted: Thu Jul 31, 2008 8:35 am Post subject: |
|
|
| Code: |
trace(drops[Math.round(Math.random()*3)])
|
An array requires specific values, not 0.10438302 so round it.
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu Jul 31, 2008 8:40 am Post subject: |
|
|
| That made it output all of the entries at once =|. Also, I want more than one thing to fall at once but why does the movieclip currently on screen dissapear when another is put on?
|
|
| Back to top |
|
 |
merlin22 Master Cheater
Reputation: 0
Joined: 29 Mar 2008 Posts: 267
|
Posted: Thu Jul 31, 2008 8:46 am Post subject: |
|
|
| noz3001 wrote: | | That made it output all of the entries at once =|. |
| Code: |
nub.onRelease = function() {
trace(drops[Math.round(Math.random()*3)])
}
|
| noz3001 wrote: |
Also, I want more than one thing to fall at once but why does the movieclip currently on screen dissapear when another is put on? |
remove:
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu Jul 31, 2008 9:19 am Post subject: |
|
|
| Nope, still no luck. It dissapears when the function is called again.
|
|
| Back to top |
|
 |
merlin22 Master Cheater
Reputation: 0
Joined: 29 Mar 2008 Posts: 267
|
Posted: Thu Jul 31, 2008 9:52 am Post subject: |
|
|
| Just change the theme of the game. Have it fall into lava, or something where it is impossible to be retrieved if it falls all the way, and just vanishes.
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu Jul 31, 2008 10:04 am Post subject: |
|
|
| merlin22 wrote: | | Just change the theme of the game. Have it fall into lava, or something where it is impossible to be retrieved if it falls all the way, and just vanishes. |
It is supposed to fall all the way offscreen but i would like to spawn more than one movieclip at a time. The current code removes the movieclip when it puts another on.
|
|
| Back to top |
|
 |
merlin22 Master Cheater
Reputation: 0
Joined: 29 Mar 2008 Posts: 267
|
Posted: Thu Jul 31, 2008 10:33 am Post subject: |
|
|
| Well.. use the exact same code but for a different object, then you have two objects spawning, and use variables to control the rate of falling, etc.
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
|
| Back to top |
|
 |
merlin22 Master Cheater
Reputation: 0
Joined: 29 Mar 2008 Posts: 267
|
Posted: Thu Jul 31, 2008 11:07 am Post subject: |
|
|
This will end up being practically the exact same game..
The graphics are up to you, this should be all the code you need for the gameplay.
| Code: |
_root.timer = 10
_root.score = 0
_root.missed = 0
function SpawnDrop ()
{
var Drop:MovieClip = _root.attachMovie("lol", "Drop",+_root.getNextHighestDepth, _root.getNextHighestDepth)
Drop._x = Math.random()*Stage.width;
Drop._y = 0;
Drop.onEnterFrame = function() {
var gravity = 9
this._y += gravity;
if (this.hitTest(_root.catcher))
{
_root.score += 1
this.unloadMovie()
}
else if (this._y > 400){
_root.missed += 1
this.unloadMovie()
}
}
}
onEnterFrame = function() {
_root.timer -= .2
if (_root.timer <= 0) {
_root.timer = 10
SpawnDrop();
}
}
catcher.onEnterFrame = function() {
this._x = _xmouse
}
|
-Put frame rate on 40
-Stage size 550 by 400 pixels
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu Jul 31, 2008 11:16 am Post subject: |
|
|
| It'll be nothing like that, firstly you have a character which you move around and second 2 of the drops kill you and 2 increase score.
|
|
| Back to top |
|
 |
merlin22 Master Cheater
Reputation: 0
Joined: 29 Mar 2008 Posts: 267
|
Posted: Thu Jul 31, 2008 11:28 am Post subject: |
|
|
This code will drop 4 random objects. I will let you decide what the objects will do, and let you program what will happen if it touches the catcher.
| Code: |
var drops:Array = new Array("1", "2", "3", "4")
_root.timer = 10
_root.score = 0
_root.missed = 0
function SpawnDrop ()
{
var Drop:MovieClip = _root.attachMovie(drops[Math.round(Math.random()*3)]) , "Drop",+_root.getNextHighestDepth, _root.getNextHighestDepth)
Drop._x = Math.random()*Stage.width;
Drop._y = 0;
Drop.onEnterFrame = function() {
var gravity = 9
this._y += gravity;
if (this.hitTest(_root.catcher))
{
_root.score += 1
this.unloadMovie()
}
else if (this._y > 400){
_root.missed += 1
this.unloadMovie()
}
}
}
onEnterFrame = function() {
_root.timer -= .2
if (_root.timer <= 0) {
_root.timer = 10
SpawnDrop();
}
}
catcher.onEnterFrame = function() {
this._x = _xmouse
}
|
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Thu Jul 31, 2008 12:08 pm Post subject: |
|
|
I've tried everything. It just isn't working out.
Look at the attached image, it might show what im trying to do.
The star at the top stays still until the next one is drawn and then it disappears.
| Description: |
|
| Filesize: |
59.71 KB |
| Viewed: |
5376 Time(s) |

|
|
|
| Back to top |
|
 |
|