Sunday, August 19, 2007

Plunko v1.3

Still can't get the brain juices flowing. Got so many projects I'm working on, so I never get anything done.

But, to make sure that I don't start ignoring the blog, here's another older project. I spiced it up a bit with a new menu, but it's still incomplete. For those who have already seen it, there won't be much more to see. Enjoy anyway!







Use the arrow keys to move your "coin" across the map. Hit the spacebar to drop it. Reset if you need to.


If anyone has a stage idea they want me to include. Draw a rough sketch and send it to me!

Stage 3 doesn't work because the ball code doesn't like moving objects. Speaking of which, if any of you are interested in what it takes to get that ball to fall like that, here's the code. Dig in!

onClipEvent (load) {
yspeed = 0;
xspeed = 0;
gravity = 0.2;
radius = 9;
friction = 0.8;
precision = 360;
bounces = 0;
}
onClipEvent (enterFrame) {
if(_root.init == true){
if(Key.isDown(Key.LEFT) && _x>45.6){
_x -= 5
}
if(Key.isDown(Key.RIGHT) && _x<400.6){
_x += 5
}
if(Key.isDown(Key.SPACE)){
_root.go = true
_root.init = false
}
}
if (_root.go == true) {
collisions = 0;
sum_x = 0;
sum_y = 0;
yspeed = yspeed+gravity;
for (x=1; x spot_x = _x+radius*Math.sin(x*360/precision);
spot_y = _y-radius*Math.cos(x*360/precision);
if (_root.stage.hitTest(spot_x, spot_y, true)) {
collisions++;
sum_x += spot_x;
sum_y += spot_y;
}
}
if (collisions>0) {
ball_dir = Math.atan(yspeed/(xspeed*-1))/(Math.PI/180);
if ((xspeed*-1)<0) {
ball_dir += 180;
}
if ((xspeed*-1)>=0 && yspeed<0) {
ball_dir += 360;
}
spot_x = sum_x/collisions;
spot_y = sum_y/collisions;
x_cat = spot_x-_x;
y_cat = spot_y-_y;
ball_coll = Math.atan(y_cat/x_cat)/(Math.PI/180);
if (x_cat<0) {
ball_coll += 180;
}
if (x_cat>=0 && y_cat<0) {
ball_coll += 360;
}
ground_rotation = ball_coll-90;
if (ground_rotation<0) {
ground_rotation += 180;
}
bounce_angle = 180-ball_dir-2*(ground_rotation);
if (bounce_angle<0) {
bounce_angle += 360;
}
speed = Math.sqrt((yspeed*yspeed)+(xspeed*xspeed));
xspeed = (speed*Math.cos(bounce_angle*Math.PI/180)*friction)*.75;
yspeed = ((speed*Math.sin(bounce_angle*Math.PI/180))*-1*friction)*.75;
_x = old_x;
_y = old_y;
if(xspeed < .3 && xspeed > -.3){
xspeed = 0
}
if(yspeed < .3 && yspeed > -.3){
yspeed = 0
}
}
else{
old_x = _x;
old_y = _y;
}
_y = _y+yspeed;
_x = _x+xspeed;
}
if(_root.scores.score_0.hitTest(_x, _y, true) && _root.scored == false){
_root.score.gotoAndPlay(2)
_root.scored = true
}
if(_root.scores.score_100.hitTest(_x, _y, true) && _root.scored == false){
_root.score.gotoAndPlay(122)
_root.scored = true
}
if(_root.scores.score_200.hitTest(_x, _y, true) && _root.scored == false){
_root.score.gotoAndPlay(183)
_root.scored = true
}
if(_root.scores.score_50.hitTest(_x, _y, true) && _root.scored == false){
_root.score.gotoAndPlay(62)
_root.scored = true
}
}

5 comments:

Troy said...

200! Yes!

Elicia said...

Wow, that's a lot of info.. when did you make it?

Ben said...

I made that when I got bored in one of my computer classes. Still incomplete, though, like so many of my other projects.

D'N'J said...

hey, my coin got stuck on top of a peg and just sat there bouncing. sad.

MStevenson said...

I got 200 twice! Awesome Ben.