※現在、「wonderfl build flash online」求人コンテンツ制作に関してのアンケートを実施中です!みなさまのお力添えを頂いて、続々とアンケート結果が集まっていますが、まだまだ募集しております。ご協力のほど、どうぞよろしくお願いいたします!

wonderfl運営事務局
→アンケートページ(※ログインしてからお答えいただけるようになっています。)

 notice: Flash editor updated! Join the development! Thanks to MiniBuilder


forked from : ABA's BallBlast [diff(1)]

flash swf thumbnail

FORKED
  1. // forked from hacker_5_bapbrq's forked from: BallBlast
  2. // forked from ABA's BallBlast
  3. // BallBlast.as
  4. //  - Blast while balls.
  5. //  - When the red ball is blasted or the ball reaches the celling,
  6. //    the game is over.
  7. //  <Control>
  8. //   Mouse: Move the red ring.
  9. //   Click: Blast balls in the red ring.
  10. package
  11. {
  12.     import flash.display.Sprite;
  13.     import flash.events.Event;
  14.     [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]
  15.     public class BallBlast extends Sprite
  16.     {
  17.         public function BallBlast()
  18.         {
  19.             main = this;
  20.             initialize();
  21.             addEventListener(Event.ENTER_FRAME, update);
  22.         }
  23.     }
  24. }
  25. import flash.display.Sprite;
  26. import flash.display.Bitmap;
  27. import flash.display.BitmapData;
  28. import flash.geom.Rectangle;
  29. import flash.geom.Vector3D;
  30. import flash.text.TextField;
  31. import flash.text.TextFormat;
  32. import flash.text.TextFormatAlign;
  33. import flash.events.Event;
  34. import flash.events.MouseEvent;
  35. const SCREEN_WIDTH:int = 465;
  36. const SCREEN_HEIGHT:int = 465;
  37. var main:Sprite;
  38. var buffer:BitmapData = new BitmapData(SCREEN_WIDTH, SCREEN_HEIGHT, false0);
  39. var isMouseClicked:Boolean;
  40. var mousePos:Vector3D = new Vector3D;
  41. var rect:Rectangle = new Rectangle;
  42. var offset:Vector3D = new Vector3D;
  43. var ticks:int;
  44. var scoreField:TextField = new TextField;
  45. var score:int;
  46. const GAME_OVER_DURATION:int = 150;
  47. const NO_START_DURATION:int = 30;
  48. var gameOverTicks:int;
  49. var lastBall:Ball;
  50. var messageField:TextField = new TextField;
  51. function initialize():void
  52. {
  53.     main.addChild(new Bitmap(buffer));
  54.     main.stage.addEventListener(MouseEvent.CLICK, function(e:Event):void { isMouseClicked = true; } );
  55.     Field.initialize();
  56.     initializeBlurs();
  57.     scoreField = createTextField(SCREEN_WIDTH - 100010024, 0xff6666, TextFormatAlign.RIGHT);
  58.     main.addChild(scoreField);
  59.     messageField = createTextField(SCREEN_WIDTH - 256025636, 0xff6666);
  60.     main.addChild(messageField);
  61.     startTitle();
  62. }
  63. function update(event:Event):void
  64. {
  65.     mousePos.x = main.stage.mouseX - SCREEN_WIDTH / 2;
  66.     mousePos.y = main.stage.mouseY - SCREEN_HEIGHT / 2;
  67.     if (isMouseClicked)
  68.     {
  69.         isMouseClicked = false;
  70.         if (gameOverTicks < 0) blastBalls(mousePos);
  71.         else if (gameOverTicks > NO_START_DURATION) startGame();
  72.     }
  73.     buffer.lock();
  74.     buffer.fillRect(buffer.rect, 0);
  75.     updateBlurs();
  76.     updateSparks();
  77.     var b:Ball;
  78.     for each (b in balls) b.update();
  79.     for each (b in balls) if (!b.isRed) b.draw();
  80.     for each (b in balls) if (b.isRed)  b.draw();
  81.     if (gameOverTicks < 0) drawBlastCircle();
  82.     buffer.unlock();
  83.     if (gameOverTicks < 0 || gameOverTicks > GAME_OVER_DURATION)
  84.     {
  85.         if (ticks % 5 == 0)    balls.push(new Ball(false));
  86.         if (ticks % 256 == 50) balls.push(new Ball(true));
  87.     }
  88.     ticks++;
  89.     if (gameOverTicks >= 0)
  90.     {
  91.         if (gameOverTicks == GAME_OVER_DURATION) startTitle();
  92.         gameOverTicks++;
  93.         if (lastBall != null) lastBall.draw();
  94.     }
  95. }
  96. function drawBlastCircle():void
  97. {
  98.     offset.x = 0; offset.y = BALL_BLAST_RADIUS;
  99.     rotation(offset, ticks * 0.05);
  100.     for (var i:int = 0; i < 16; i++)
  101.     {
  102.         drawBox(mousePos.x + offset.x, mousePos.y + offset.y, 7, 0xee0000,
  103.                 13200100100);
  104.         rotation(offset, Math.PI * 2 / 16);
  105.     }
  106. }
  107. function startTitle():void
  108. {
  109.     ticks = 0;
  110.     lastBall = null;
  111.     gameOverTicks = GAME_OVER_DURATION;
  112.     messageField.y = SCREEN_HEIGHT / 3;
  113.     messageField.text = "BallBlast";
  114. }
  115. function startGame():void
  116. {
  117.     blastAllBalls();
  118.     lastBall = null;
  119.     score = 0;
  120.     scoreField.text = String(score);
  121.     ticks = 0;
  122.     gameOverTicks = -1;
  123.     messageField.text = "";
  124. }
  125. function startGameOver():void
  126. {
  127.     blastAllBalls();
  128.     if (gameOverTicks >= 0return;
  129.     gameOverTicks = 0;
  130.     messageField.y = SCREEN_HEIGHT / 2;
  131.     messageField.text = "GAME OVER";
  132. }
  133. // Balls.
  134. const BALL_BLAST_RADIUS:Number = 64.0;
  135. var balls:Vector.<Ball> = new Vector.<Ball>;
  136. class Ball
  137. {
  138.     private const GRAVITY_FORCE:Number = 0.5;
  139.     private const MAX_VELOCITY_CHANGE:Number = 0.5;
  140.     public var pos:Vector3D = new Vector3D;
  141.     public var vel:Vector3D = new Vector3D;
  142.     public var radius:Number;
  143.     public var angle:Number, angleVel:Number;
  144.     public var isInAppearance:Boolean;
  145.     public var isRed:Boolean;
  146.     public function Ball(isRed:Boolean):void
  147.     {
  148.         if (!isRed)
  149.         {
  150.             radius = 20.0 + Math.random() * 20.0;
  151.             pos.x = (Math.random() * 2 - 1) * (Field.size.x - radius * 1.1);
  152.             pos.y = Field.size.y + radius * 1.1;
  153.             isInAppearance = true;
  154.         }
  155.         else
  156.         {
  157.             radius = 20.0;
  158.             pos.x = 0; pos.y = -Field.size.y * 0.8;
  159.             isInAppearance = false;
  160.         }
  161.         vel.x = vel.y = 0;
  162.         angle = Math.random() * Math.PI * 2;
  163.         angleVel = (Math.random() * 2 - 1) * 0.1;
  164.         this.isRed = isRed;
  165.     }
  166.     public function update():void
  167.     {
  168.         if (isInAppearance)
  169.         {
  170.             vel.y -= GRAVITY_FORCE * 2;
  171.             if (pos.y < Field.size.y - radius) isInAppearance = false;
  172.         }
  173.         else
  174.         {
  175.             if (pos.y > Field.size.y - radius) hit(pos.y - (Field.size.y - radius), 0);
  176.             vel.y += GRAVITY_FORCE;
  177.         }
  178.         vel.scaleBy(0.95);
  179.         pos.incrementBy(vel);
  180.         if (pos.y < -Field.size.y + radius)
  181.         {
  182.             if (gameOverTicks < 0) lastBall = this;
  183.             startGameOver();
  184.             return;
  185.         }
  186.         if (pos.x > Field.size.x - radius) hit(pos.x - (Field.size.x - radius), Math.PI / 2);
  187.         if (pos.x < -Field.size.x + radius) hit((-Field.size.y + radius) - pos.x, Math.PI / 2 * 3);
  188.         for each (var b:Ball in balls)
  189.         {
  190.             if (b == thiscontinue;
  191.             var d:Number = radius + b.radius - Vector3D.distance(pos, b.pos);
  192.             if (d > 0) hit(d, Math.atan2(b.pos.x - pos.x, b.pos.y - pos.y));
  193.         }
  194.         angle += angleVel; angleVel *= 0.95;
  195.     }
  196.     public function draw():void
  197.     {
  198.         offset.x = 0; offset.y = radius / 2;
  199.         rotation(offset, angle);
  200.         var color:int , r:int ,g:int, b:int;
  201.         if (!isRed)
  202.         {
  203.             color = 0xeeeeee; r = 200; g = 200; b = 200;
  204.         }
  205.         else
  206.         {
  207.             color = 0xff0000; r = 250; g = 200; b = 200;
  208.         }
  209.         for (var i:int = 0; i < 3; i++)
  210.         {
  211.             drawBox(pos.x + offset.x, pos.y + offset.y, radius, color, radius, r, g, b);
  212.             rotation(offset, Math.PI * 2 / 3);
  213.         }
  214.     }
  215.     private function hit(d:Number, a:Number):void
  216.     {
  217.         if (isInAppearance) return;
  218.         var sv:Number = Math.sin(a) * d, cv:Number = Math.cos(a) * d;
  219.         pos.x -= sv / 2; pos.y -= cv / 2;
  220.         angleVel += (-sv * 0.1 - angleVel) * 0.1;
  221.         sv *= 0.1 * vel.x; cv *= 0.1 * vel.y;
  222.         if (sv > MAX_VELOCITY_CHANGE) sv = MAX_VELOCITY_CHANGE;
  223.         if (sv < -MAX_VELOCITY_CHANGE) sv = -MAX_VELOCITY_CHANGE;
  224.         if (cv > MAX_VELOCITY_CHANGE) cv = MAX_VELOCITY_CHANGE;
  225.         if (cv < -MAX_VELOCITY_CHANGE) cv = -MAX_VELOCITY_CHANGE;
  226.         vel.x -= sv; vel.y -= cv;
  227.     }
  228. }
  229. function blastBalls(p:Vector3D):void
  230. {
  231.     var bc:int = 0;
  232.     var b:Ball;
  233.     for each (b in balls)
  234.     {
  235.         if (Vector3D.distance(b.pos, p) < BALL_BLAST_RADIUS + b.radius)
  236.         {
  237.             if (b.isRed)
  238.             {
  239.                 lastBall = b;
  240.                 startGameOver();
  241.                 return;
  242.             }
  243.             bc++;
  244.         }
  245.     }
  246.     score += bc;
  247.     scoreField.text = String(score);
  248.     for (var i:int = 0; i < balls.length; i++)
  249.     {
  250.         b = balls[i];
  251.         if (Vector3D.distance(b.pos, p) < BALL_BLAST_RADIUS + b.radius)
  252.         {
  253.             addSparks(10, b.pos, 20.020.0250250250);
  254.             balls.splice(i, 1); i--;
  255.         }
  256.     }
  257. }
  258. function blastAllBalls():void
  259. {
  260.     for each (var b:Ball in balls) addSparks(5, b.pos, 20.020.025000);
  261.     balls = new Vector.<Ball>;
  262. }
  263. // Sparks.
  264. var sparks:Vector.<Spark> = new Vector.<Spark>;
  265. class Spark
  266. {
  267.     public var pos:Vector3D = new Vector3D;
  268.     public var vel:Vector3D = new Vector3D;
  269.     public var size:Number;
  270.     public var r:int, g:int, b:int;
  271.     public var ticks:int;
  272.     public function update():Boolean
  273.     {
  274.         pos.incrementBy(vel);
  275.         vel.y += 0.5;
  276.         vel.scaleBy(0.99);
  277.         size *= 0.95;
  278.         r *= 0.98; g *= 0.98; b *= 0.98;
  279.         if (pos.x < -Field.size.x && vel.x < 0 ||
  280.             pos.x >  Field.size.x && vel.x > 0) vel.x *= -1;
  281.         if (pos.y < -Field.size.y && vel.y < 0 ||
  282.             pos.y >  Field.size.y && vel.y > 0) vel.y *= -1;
  283.         var cr:Number = Math.random();
  284.         drawBox(pos.x, pos.y, size, r * 0x10000 + g * 0x100 + b, size, r * cr, g * cr, b * cr);
  285.         ticks--;
  286.         return (ticks >= 0);
  287.     }
  288. }
  289. function addSparks(count:int, p:Vector3D, speed:Number, size:Number, r:int, g:int ,b:int):void
  290. {
  291.     for (var i:int = 0; i < count; i++)
  292.     {
  293.         var s:Spark = new Spark;
  294.         s.pos.x = p.x; s.pos.y = p.y;
  295.         var a:Number = Math.random() * Math.PI * 2;
  296.         var sp:Number = speed * (0.5 + Math.random());
  297.         s.vel.x = Math.sin(a) * sp; s.vel.y = Math.cos(a) * sp;
  298.         s.size = size;
  299.         s.r = r; s.g = g; s.b = b;
  300.         s.ticks = 15 + 15 * Math.random();
  301.         sparks.push(s);
  302.     }
  303. }
  304. function updateSparks():void
  305. {
  306.     for (var i:int = 0; i < sparks.length; i++)
  307.     {
  308.         if (!sparks[i].update())
  309.         {
  310.             sparks.splice(i, 1); i--;
  311.         }
  312.     }
  313. }
  314. // Game field.
  315. class Field
  316. {
  317.     public static var size:Vector3D = new Vector3D;
  318.     public static function initialize():void
  319.     {
  320.         size.x = SCREEN_WIDTH * 0.9 / 2; size.y = SCREEN_HEIGHT * 0.9 / 2;
  321.     }
  322.     public static function contains(p:Vector3D):Boolean
  323.     {
  324.         return (p.x >= -size.x && p.x <= size.x && p.y >= -size.y && p.y <= size.y);
  325.     }
  326. }
  327. // Blur effect.
  328. const BLUR_MAX_COUNT:int = 512;
  329. const BLUR_HISTORY_COUNT:int = 6;
  330. var blurs:Vector.<Vector.<Blur>> = new Vector.<Vector.<Blur>>(BLUR_HISTORY_COUNT, true);
  331. var blurCounts:Vector.<int> = new Vector.<int>(BLUR_HISTORY_COUNT, true);
  332. var blurIndex:int;
  333. class Blur
  334. {
  335.     public var pos:Vector3D = new Vector3D;
  336.     public var width:Number, height:Number;
  337.     public var r:int, g:int, b:int;
  338.     public function update():void
  339.     {
  340.         rect.x = pos.x - width / 2;
  341.         rect.y = pos.y - height / 2;
  342.         rect.width = width; rect.height = height;
  343.         buffer.fillRect(rect, r * 0x10000 + g * 0x100 + b);
  344.         width *= 1.2; height *= 1.2;
  345.         var a:int = (r + g + b) / 3;
  346.         r += (a - r) * 0.25;
  347.         g += (a - g) * 0.25;
  348.         b += (a - b) * 0.25;
  349.         r *= 0.65; g *= 0.65; b *= 0.65;
  350.     }
  351. }
  352. function drawBox(x:Number, y:Number, size:int, color:int,
  353.                  bsize:int, br:int, bg:int, bb:int):void
  354. {
  355.     rect.x = x - size / 2 + SCREEN_WIDTH / 2;
  356.     rect.y = y - size / 2 + SCREEN_HEIGHT / 2;
  357.     rect.width = rect.height = size;
  358.     buffer.fillRect(rect, color);
  359.     addBlur(x, y, bsize, bsize, br, bg, bb);
  360. }
  361. function addBlur(x:Number, y:Number, w:Number, h:Number,
  362.                  r:int, g:int, b:int):void
  363. {
  364.     if (blurCounts[blurIndex] >= BLUR_MAX_COUNT) return;
  365.     var bl:Blur = blurs[blurIndex][blurCounts[blurIndex]];
  366.     bl.pos.x = x + SCREEN_WIDTH / 2; bl.pos.y = y + SCREEN_HEIGHT / 2;
  367.     bl.width = w; bl.height = h;
  368.     bl.r = r; bl.g = g; bl.b = b;
  369.     blurCounts[blurIndex]++;
  370. }
  371. function updateBlurs():void
  372. {
  373.     var bi:int = blurIndex + 1;
  374.     for (var i:int = 0; i < BLUR_HISTORY_COUNT; i++)
  375.     {
  376.         if (bi >= BLUR_HISTORY_COUNT) bi = 0;
  377.         for (var j:int = 0; j < blurCounts[bi]; j++) blurs[bi][j].update();
  378.         bi++;
  379.     }
  380.     blurIndex++;
  381.     if (blurIndex >= BLUR_HISTORY_COUNT) blurIndex = 0;
  382.     blurCounts[blurIndex] = 0;
  383. }
  384. function initializeBlurs():void
  385. {
  386.     for (var i:int = 0; i < BLUR_HISTORY_COUNT; i++)
  387.     {
  388.         var bs:Vector.<Blur> = new Vector.<Blur>(BLUR_MAX_COUNT, true);
  389.         for (var j:int = 0; j < BLUR_MAX_COUNT; j++)
  390.         {
  391.             bs[j] = new Blur;
  392.         }
  393.         blurs[i] = bs;
  394.         blurCounts[i] = 0;
  395.     }
  396.     blurIndex = 0;
  397. }
  398. // Utility functions.
  399. function rotation(v:Vector3D, a:Number):void
  400. {
  401.     var sv:Number = Math.sin(a);
  402.     var cv:Number = Math.cos(a);
  403.     var rx:Number = cv * v.x - sv * v.y;
  404.     v.y = sv * v.x + cv * v.y;
  405.     v.x = rx;
  406. }
  407. function normalizeAngle(v:Number):Number
  408. {
  409.     if (v > Math.PI)       return v - Math.PI * 2;
  410.     else if (v < -Math.PI) return v + Math.PI * 2;
  411.     else                   return v;
  412. }
  413. function createTextField(x:int, y:int, width:int, size:int, color:int,
  414.                          align:String = TextFormatAlign.LEFT):TextField
  415. {
  416.     var fm:TextFormat = new TextFormat;
  417.     fm.font = "_typewriter"; fm.bold = true;
  418.     fm.size = size; fm.color = color;
  419.     fm.align = align;
  420.     var fi:TextField = new TextField;
  421.     fi.defaultTextFormat = fm;
  422.     fi.x = x; fi.y = y; fi.width = width;
  423.     fi.selectable = false;
  424.     return fi;
  425. }
noswf
Get Adobe Flash Player