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.
9 Responses to “Game prototype involving shape drawing and a ball”
Leave a Reply
Trackbacks
-
Flash tutorials | Drawing with AS3 | Lemlinh.com on
August 30th, 2008 1:15 pm
[...] Read more [...]
- Create incredible particle effects with Partigen 2
- PixelBlitz AS3 game framework
- Being a geek in Venezuela
- Box2D tutorial for the absolute beginners – revamped
- Triqui’s Picks #16
- Are you ready for this?
- Box2DFlash 2.1a released – what changed
- Get detailed statistics about your Flash game with SWFStats
- Games that Challenge the World Come2Play contest – $8,000 in prizes
- Triqui’s Picks #15
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 1
- Create a Flash Racing Game Tutorial
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash draw game like Line Rider or others - part 1
- Create a flash artillery game - step 1
- Triqui MochiAds Arcade plugin for WordPress official page
- Flash game creation tutorial – part 5.2 (4.87/5)
- Create a flash artillery game – step 1 (4.78/5)
- Create a Flash Racing Game Tutorial (4.76/5)
- Create a survival horror game in Flash tutorial – part 1 (4.73/5)
- Flash game creation tutorial – part 3 (4.73/5)
- Creation of a Flash arcade site using WordPress – step 2 (4.73/5)
- Flash game creation tutorial – part 2 (4.70/5)
- Create a flash artillery game – step 2 (4.70/5)
- Flash game creation tutorial – part 1 (4.69/5)
- Create a flash draw game like Line Rider or others – part 1 (4.69/5)

(10 votes, average: 4.00 out of 5)



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.
Very nice idea. I’d like to see a real game come out of it.
nice!
The ball keeps getting suck on the edges.
I’ve already seen something really really similar on FlashGameLicense.com a few days ago.
Not a bad prototype. This sort of game is really well done here:
http://www.bigfooty.com.au/rules/
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.
Oh, Marco’s already seen it.