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.

ACTIONSCRIPT:
  1. drawing = false;
  2. angle = Math.random()*360;
  3. speed = 5;
  4. precision = 16;
  5. xspeed = speed*Math.cos(angle*0.0174532925);
  6. yspeed = speed*Math.sin(angle*0.0174532925);
  7. _root.createEmptyMovieClip("drawclip", 1);
  8. _root.attachMovie("ball", "ball", 2, {_x:250, _y:200});
  9. _root.onMouseDown = function() {
  10.     x_points = new Array();
  11.     y_points = new Array();
  12.     drawing = true;
  13.     drawclip.clear();
  14.     still_inside = true;
  15.     drawclip.lineStyle(5, 0x000000);
  16.     x_points.push(_root._xmouse);
  17.     y_points.push(_root._ymouse);
  18.     drawclip.moveTo(x_points[0], y_points[0]);
  19. };
  20. _root.onMouseUp = function() {
  21.     drawing = false;
  22. };
  23. _root.onMouseMove = function() {
  24.     if (drawing) {
  25.         end_x = _root._xmouse;
  26.         end_y = _root._ymouse;
  27.         dist_x = x_points[0]-end_x;
  28.         dist_y = y_points[0]-end_y;
  29.         dist = dist_x*dist_x+dist_y*dist_y;
  30.         if (dist>400) {
  31.             still_inside = false;
  32.             drawclip.lineTo(end_x, end_y);
  33.             x_points.push(end_x);
  34.             y_points.push(end_y);
  35.         } else {
  36.             if (still_inside) {
  37.                 drawclip.lineTo(end_x, end_y);
  38.                 x_points.push(end_x);
  39.                 y_points.push(end_y);
  40.             } else {
  41.                 x_points.push(x_points[0]);
  42.                 y_points.push(y_points[0]);
  43.                 drawclip.lineTo(x_points[0], y_points[0]);
  44.                 drawing = false;
  45.                 drawclip.clear();
  46.                 drawclip.lineStyle(5, 0x00ff00);
  47.                 drawclip.beginFill(0x00ff00, 30);
  48.                 drawclip.moveTo(x_points[0], y_points[0]);
  49.                 for (x=1; x<x_points.length; x++) {
  50.                     drawclip.lineTo(x_points[x], y_points[x]);
  51.                 }
  52.                 if (drawclip.hitTest(ball._x, ball._y, true)) {
  53.                     ball._x = 250;
  54.                     ball._y = 200;
  55.                 }
  56.             }
  57.         }
  58.     }
  59. };
  60. ball.onEnterFrame = function() {
  61.     this._x += xspeed;
  62.     this._y += yspeed;
  63.     if ((this._x<10) or (this._x>490)) {
  64.         xspeed *= -1;
  65.     }
  66.     if ((this._y<10) or (this._y>390)) {
  67.         yspeed *= -1;
  68.     }
  69. };
  70. _root.onEnterFrame = function() {
  71.     if (drawing) {
  72.         for (x=1; x<precision; x++) {
  73.             spot_x = ball._x+10*Math.sin(x*360/precision*0.0174532925);
  74.             spot_y = ball._y+10*Math.cos(x*360/precision*0.0174532925);
  75.             if (drawclip.hitTest(spot_x, spot_y, true)) {
  76.                 drawing = false;
  77.                 drawclip.clear();
  78.                 break;
  79.             }
  80.         }
  81.     }
  82. };

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.

Download the source code.

Improve the blog rating this post
Tell me what do you think about this post. I'll write better and better entries.
1 Star2 Stars3 Stars4 Stars5 Stars (10 votes, average: 4 out of 5)
Loading ... Loading ...

» Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.

9 Responses to “Game prototype involving shape drawing and a ball”

  1. Will on August 11th, 2008 6:32 pm

    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.

  2. Mr Sun on August 11th, 2008 6:51 pm

    Very nice idea. I’d like to see a real game come out of it.

  3. Jack Hopkins on August 11th, 2008 7:05 pm

    nice!

  4. Prankard on August 12th, 2008 2:48 am

    The ball keeps getting suck on the edges.

  5. Marco Sgnaolin on August 12th, 2008 2:52 am

    I’ve already seen something really really similar on FlashGameLicense.com a few days ago.

  6. Andrew on August 12th, 2008 11:42 pm

    Not a bad prototype. This sort of game is really well done here:

    http://www.bigfooty.com.au/rules/

  7. Graham on August 13th, 2008 4:10 am

    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.

  8. Graham on August 13th, 2008 4:11 am

    Oh, Marco’s already seen it.

Leave a Reply




Trackbacks

  1. Flash tutorials | Drawing with AS3 | Lemlinh.com on August 30th, 2008 1:15 pm

    [...] Read more [...]