PDA

View Full Version : Random ITEM fall? with hitTest



igotgames
January 21st, 2006, 05:11 PM
ok, i got a game with balls falling, and u have to get them to fall into the hoop.. and where do i post the AS code.. i have Flash 8 pro

this is the code places on the MC of the hoop

onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
this.gotoAndStop(2);
this._x -= 10;
_xscale = 100;
} else if (Key.isDown(Key.RIGHT)) {
this.gotoAndStop(2);
this._x += 10;
_xscale = -100;
} else {
gotoAndStop(1);
}
}
onClipEvent (load) {
maximumBottom = Stage.height;
minimumLeft = 0;
maximumRight = Stage.width;
minimumTop = 0;
}
onClipEvent (enterFrame) {
if (this._x<minimumLeft) {
this._x = minimumLeft;
} else if (this._x>maximumRight) {
this._x = maximumRight;
}
if (this._y<minimumTop) {
this._y = minimumTop;
} else if (this._y>maximumBottom) {
this._y = maximumBottom;
}
}


thts for moving left and right, anda kinda hitTest with the FRAMES boundries.. sense i jst want left and right.. i could get raid of Ys right


ok.. i got 10diff kinds of balls.. i want them to fall at random times, places< from a stright line fromt the top....>... then when they hit the hoop.. (disappear)

igotgames
January 21st, 2006, 06:49 PM
i would also like only the WHOLE of the loop for the items.. and the sides smack or at least not take the item

bombsledder
January 21st, 2006, 09:23 PM
umm how can you get the code yet not no where to put it lol....besides you put it in the mc... >.>

igotgames
January 21st, 2006, 09:47 PM
yes i know u put it on the MC ..but... i have 10 MCs if i put a standard drop item.. its going to drop ALL of them at the same time,,

bombsledder
January 21st, 2006, 09:59 PM
can you post a .fla of the whole project your working on so i can edit it for ya.. and see what your dealing with

igotgames
January 21st, 2006, 10:50 PM
i would but i really dnt think thts going to help much..
this is how its setup right now

i got the maintime line,, stops on frame 1
then i got a layer with the HOOPmc
then a layer for the ground
and a TOP layer for BALLS <i got ten MCs of balls>

right now i just have AS for moving, and stopings, the hoop...



i would like AS for randomsly droping the X value for the BALLs.. randomly picking 1 out of the 10.. and 3 or 4 at once... and this._y = 30; for Y..

igotgames
January 22nd, 2006, 02:58 AM
onClipEvent (load) {
function reset() {
this._x = random(480)+100;
this._y = 30;
fallSpeed = random(4)+4;
this.gotoAndStop(1);
}
reset();
}
onClipEvent (enterFrame) {

this._y += fallSpeed;
}
if (this._y>680) {
reset();
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.Basket_MC)) {
_root.score = _root.score +=10;
this.gotoAndStop(2);
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.Ground_MC)) {
_root.score = _root.score -=10;
this.gotoAndStop(3);
}
}




i worked out a random code..



numBall = 3;
for (i=2; i<=numFruits; i++) {
ball0.duplicateMovieClip("ball"+i, i+100);
}

and how to make it show 3 at a time..

how can i make this pick a random movie clip?

bombsledder
January 22nd, 2006, 11:04 AM
you would do something like do

ball1=eval("ball"+random(10))
ball2=eval("ball"+random(10))
ball3=eval("ball"+random(10))

as a pointer to ball but then you might not get 3 balls you might only get 1 i mean i could give ya the code completly but sometimes its better to think =P

igotgames
January 22nd, 2006, 05:04 PM
hmm let me see if i can figure this script out.. i might not thou...

bombsledder
January 22nd, 2006, 06:14 PM
alright make a loop maybe just an easy one like
onLoad=function(){
time=10
curTime=0
}
onEnterFrame=function(){
if(curTime<time){
curTime++
}
if(curTime==time){
curTime=0
ball1=eval("ball"+random(10))
ball2=eval("ball"+random(10))
ball3=eval("ball"+random(10))
}
}

igotgames
January 22nd, 2006, 11:15 PM
can u explain it more..maybe

igotgames
January 22nd, 2006, 11:46 PM
ok.. this is posted in all the MCs of balls

onClipEvent (load) {
function reset() {
this._x = random(480)+100;
this._y = 30;
fallSpeed = random(4)+4;
this.gotoAndStop(1);
}
reset();
}
onClipEvent (enterFrame) {
if (this.scrollStart) {
this._y += fallSpeed+_root.mainGround.groundSpeed;
} else {
this._y += fallSpeed;
}
if (this._y>680) {
reset();
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.Basket_MC)) {
_root.score = _root.score +=10;
this.gotoAndStop(2);
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.Ground_MC)) {
_root.score = _root.score -=10;
this.gotoAndStop(2);
}
}


this for main timeline under ACTIONS frame1..
numBall = 3;
for (i=2; i<=numFruits; i++) {
ball10.duplicateMovieClip("ball"+i, i+100);
}




ok.. first i did this to 4 MCs of fruit, and it dropped only 3.. but with all 10... it drops like all of them/?? why...

nathan99
January 23rd, 2006, 02:10 AM
ok i wasnt sure wat ur asking, so i havent posted, but, i thnk u want something like this, let me know if its not

igotgames
January 23rd, 2006, 01:50 PM
ok heres my files
http://www.filefactory.com/get/f.php?f=ea7454784e3ebc3d45287f9f
for some reason it was to big... oh well...
as u can see iv got it bare right now,,,i want to work things out first..

ok i got this script on all the balls

onClipEvent (load) {
function reset() {
this._x = random(480)+100;
this._y = 30;
fallSpeed = random(4)+4;
this.gotoAndStop(1);
}
reset();
}
onClipEvent (enterFrame) {
if (this.scrollStart) {
this._y += fallSpeed+_root.mainGround.groundSpeed;
} else {
this._y += fallSpeed;
}
if (this._y>680) {
reset();
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.Basket_MC)) {
_root.score = _root.score +=10;
this.gotoAndStop(2);
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.Ground_MC)) {
_root.score = _root.score -=10;
this.gotoAndStop(2);
}
}

id like help with the code in red.. i dnt want the <fallSpeed+_root.mainGround.groundSpeed> ..becuz my screen isnt a scrolling one.........

ok and for the actions frame1 layer.. i have

numBall = 3;
for (i=2; i<=numFruits; i++) {
ball10.duplicateMovieClip("ball"+i, i+100);
}

now if i have it say ball0-9.. which ever number i put, it wont catch tht ball...
also.. if i just put 4 balls instead of all 10,, it will do this code right..BUT with all 10 it drops them all the time.. instead of how flawless it looks with just four balls...

can u guys help me tweak it



ALSO.. i would like the balls to only fall between.. X.20-X.520 ...Y is fine at 30
and i dnt like how un random it looks.. they seem to only drop next to each other... is the a script i could add to make sure its spaced out something like 25X points


ok so heres a break down of wht id like help with
the red code fixed for just a fall speed... no detect screen scroll
the number of balls tht falls, i would like 3-5 only
them the fall in range of x20 x520
and spacing between balls,, dnt like them grouping.. free points yo

nathan99
January 23rd, 2006, 08:24 PM
well with my eg
replace code with


paddle.xs = e=0;
////EDIT THESE
startBalls = 9;
paddleBounce = 1;
ballImages = 3;
k = true;
//true for keys false for mouse
mouseSpeed = 2;
KeySpeed = 1;
gravity = .25;
hitZone = 10;
hitHeight = 10;
///LEAVE
function create() {
_root["ball"+random(ballImages)].duplicateMovieClip("ballBouncy"+(e++), getNextHighestDepth(), {k:random(2), xs:Math.random()*5+1, _y:0, _x:random(Stage.width), sp:Math.random()*5+2, onEnterFrame:function () {
this.hitTest(paddle._x+hitZone, paddle._y-hitHeight, true) || this.hitTest(paddle._x-hitZone, paddle._y-hitHeight, true) ? this.removeMovieClip() : this.hitTest(paddle) ? (this.sp>1.5 ? this.sp *= -paddleBounce : null) : null;
this._y>=Stage.height ? (create(), this.removeMovieClip()) : this._y += (this.sp += gravity);
}});
}
for (var i:Number = 0; i<startBalls; i++) {
create();
}
var myK = new Object();
Key.addListener(myK);
myK.onKeyDown = function() {
Key.isDown(Key.SHIFT) ? (k=!k) : Key.isDown(Key.CONTROL) ? create() : Key.isDown(Key.SPACE) ? removeLast() : null;
};
function removeLast() {
_root["ballBouncy"+(e -= 1)].removeMovieClip();
}
paddle.onEnterFrame = function() {
this._x += (this.xs *= .85);
if (k) {
Key.isDown(Key.LEFT) ? (this.getBounds(_root).xMin>0 ? this.xs -= KeySpeed : null) : Key.isDown(Key.RIGHT) ? (this.getBounds(_root).xMax<Stage.width ? this.xs += KeySpeed : null) : null;
} else {
_xmouse<=this._x ? (this.getBounds(_root).xMin>0 ? this.xs -= mouseSpeed : null) : _xmouse>this._x ? (this.getBounds(_root).xMax<Stage.width ? this.xs += mouseSpeed : null) : null;
}
};

igotgames
January 24th, 2006, 02:22 AM
how can i add tht to my current codes..
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
this.gotoAndStop(2);
this._x -= 10;
_xscale = 100;
} else if (Key.isDown(Key.RIGHT)) {
this.gotoAndStop(2);
this._x += 10;
_xscale = -100;
} else {
gotoAndStop(1);
}
}

id like tht to be able to swith from key, to mouse...with SPACEbar
but im moving two MCs at once


and can u removie the bounce and stuff.. like i fixed how the hoop was taking the ball.. its how i wanted it now.. so no bounce...would be ok.. i editord urs some and, i jst got it to sit on the padle..

id like just the option to hit Basket_MC(gotoPlay(2),{{{how would i add score))) .. or Ground_MC<gotoStop(10):::how would i minus score:::::

nathan99
January 24th, 2006, 03:12 AM
how do u want it to react insteqad of bounce?

igotgames
January 24th, 2006, 01:26 PM
man ur code is smart as fck, im like burning to figure it out, its tuff

ok im Trying to make it where, 10sec, delay, then drop 5 (random) out of 10 balls, Which each had there own (odds) of falling, mainly cuz ones worth 150,120,100,80, so that makes the count rack up.
as its falling, when it (hits) Basket_MC, gotoandPlay(2) ,, then the ball looks like its rolling down the hoop,behide the net..... then if miss tht (hit) ground_MC and (delete)?or i could runto a frame and have ball rollin away

and how about a rule like, if numBalls = 2 , run(drop)
so tht it looks harder,

and i would like to control the space of the balls?,,

igotgames
January 26th, 2006, 12:00 AM
help?

igotgames
January 27th, 2006, 10:38 AM
ok, nathan helped alot, he fixed how hardcore it is.. heres my code.. besides wht makes it move
stop();
score = 0;
lifes = 10;
numFruit = 5;
for (i=2; i<=numFruit; i++) {
fruits.duplicateMovieClip("fruit"+i, i+100);
}
<thts on the main frame timeline>

onClipEvent (load) {
function reset() {
this._x = random(480)+100;
this._y = 30;
fallSpeed = random(4)+4;
this.gotoAndStop(random(10)+1);
}
reset();
}
onClipEvent (enterFrame) {
if (this.scrollStart) {
this._y += fallSpeed+_root.mainGround.groundSpeed;
} else {
this._y += fallSpeed;
}
if (this._y>680) {
reset();
}
} <thts wht needs fix, fall code., just a little needs fixed>
onClipEvent (enterFrame) {
if (this.hitTest(_root.Basket_MC)) {
_root.score = _root.score += 60;
this.gotoAndPlay(2);
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.Ground_MC)) {
_root.score = _root.score -= 10;
_root.lifes = _root.lifes -= 1;
this.gotoAndStop(10);
}
}
<this just gives u an idea when it hits something>




ok on the part tht needs fixed.. mainly <<<< if (this.scrollStart) {
this._y += fallSpeed+_root.mainGround.groundSpeed;>>>>>>>>>

whts happening is this... when i push left or right.. the falling items slow down.. ....i got them code from a howto..but the game was a side scrolling shooter... which is why it slows down... now iv tryed a few things...

my game doesnt need tht real effect.. it just needs to fall same speed always onClipEvent (load) {
function reset() {
this._x = random(400)+100;
this._y = 20;
fallSpeed = random(4)+4;
this.gotoAndStop(random(10)+1);
}
reset();
}
onClipEvent (enterFrame) {
this._y += fallSpeed;
if (this._y>680) {
reset();
}
}
new code,,, changed frame rate to 20 works fine.. but how can i make tht code end when the game is reseted , by ENTER. or game over.. it stillplays?