Game prototype involving shape drawing and a ball
Sometimes I play and mess with code to get some interesting game prototypes.
Although I am not satisfied about this one, I want to share it with you anyway.
You have to draw a lasso with the mouse trying to catch the ball inside the shape you will create. In this case you’ll win.
If the ball touches the line before you close the shape, you die.
Uncommented code because it’s just an early stage, but if you are interested I will try to turn it into something playable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | drawing = false;
angle = Math.random()*360;
speed = 5;
precision = 16;
xspeed = speed*Math.cos(angle*0.0174532925);
yspeed = speed*Math.sin(angle*0.0174532925);
_root.createEmptyMovieClip("drawclip", 1);
_root.attachMovie("ball", "ball", 2, {_x:250, _y:200});
_root.onMouseDown = function() {
x_points = new Array();
y_points = new Array();
drawing = true;
drawclip.clear();
still_inside = true;
drawclip.lineStyle(5, 0x000000);
x_points.push(_root._xmouse);
y_points.push(_root._ymouse);
drawclip.moveTo(x_points[0], y_points[0]);
};
_root.onMouseUp = function() {
drawing = false;
};
_root.onMouseMove = function() {
if (drawing) {
end_x = _root._xmouse;
end_y = _root._ymouse;
dist_x = x_points[0]-end_x;
dist_y = y_points[0]-end_y;
dist = dist_x*dist_x+dist_y*dist_y;
if (dist>400) {
still_inside = false;
drawclip.lineTo(end_x, end_y);
x_points.push(end_x);
y_points.push(end_y);
} else {
if (still_inside) {
drawclip.lineTo(end_x, end_y);
x_points.push(end_x);
y_points.push(end_y);
} else {
x_points.push(x_points[0]);
y_points.push(y_points[0]);
drawclip.lineTo(x_points[0], y_points[0]);
drawing = false;
drawclip.clear();
drawclip.lineStyle(5, 0x00ff00);
drawclip.beginFill(0x00ff00, 30);
drawclip.moveTo(x_points[0], y_points[0]);
for (x=1; x<x_points.length; x++) {
drawclip.lineTo(x_points[x], y_points[x]);
}
if (drawclip.hitTest(ball._x, ball._y, true)) {
ball._x = 250;
ball._y = 200;
}
}
}
}
};
ball.onEnterFrame = function() {
this._x += xspeed;
this._y += yspeed;
if ((this._x<10) or (this._x>490)) {
xspeed *= -1;
}
if ((this._y<10) or (this._y>390)) {
yspeed *= -1;
}
};
_root.onEnterFrame = function() {
if (drawing) {
for (x=1; x<precision; x++) {
spot_x = ball._x+10*Math.sin(x*360/precision*0.0174532925);
spot_y = ball._y+10*Math.cos(x*360/precision*0.0174532925);
if (drawclip.hitTest(spot_x, spot_y, true)) {
drawing = false;
drawclip.clear();
break;
}
}
}
}; |
and enjoy the result…
When you “die”, you just lose your drawing. When the ball dies, it simply respawns at the centre of the stage.
They can be easily customized to meet the unique requirements of your project.















(10 votes, average: 4.00 out of 5)









This post has 9 comments
Will
It’s interesting though doesn’t really work properly. Would be interesting to see it ‘themed’ so maybe instead of a ball it’s an insect you have to catch.
Mr Sun
Very nice idea. I’d like to see a real game come out of it.
Jack Hopkins
nice!
Prankard
The ball keeps getting suck on the edges.
Marco Sgnaolin
I’ve already seen something really really similar on FlashGameLicense.com a few days ago.
Andrew
Not a bad prototype. This sort of game is really well done here:
http://www.bigfooty.com.au/rules/
Graham
Hey! Thats like my game! I released it on FGL two weeks ago.
Weird. Anyway, good tutorial.
Check out “wires” on FGL. Its exactly like this.
Graham
Oh, Marco’s already seen it.
Flash tutorials | Drawing with AS3 | Lemlinh.com
[...] Read more [...]