circle pong shinh forked:4favorite:3lines:83license : All rights reserved modified : 2009-02-01 02:20:25 Embed Tweet package { import flash.display.*; import flash.geom.*; import flash.text.*; import flash.events.*; public class FlashTest extends Sprite { private var screen:BitmapData; private const W:int = 465, H:int = 465; private var ba:Number, bv:Number; private var cnt:int, noColCnt:int; private var running:Boolean; private var ball:Shape = new Shape(); private var wall:Shape = new Shape(); private var score:TextField; private var text:TextField; private function makeTextField(x:int, y:int, s:int):TextField { var t:TextField = new TextField(); t.x = x; t.y = y; t.width = W; t.height = H; var fm:TextFormat = new TextFormat; fm.color = 0xffffff; fm.font = '_typewriter'; fm.size = s; fm.bold = true; t.defaultTextFormat = fm; return t; } public function FlashTest() { this.addEventListener(Event.ENTER_FRAME, update); screen = new BitmapData(W, H, false, 0); addChild(new Bitmap(screen)); ball.graphics.beginFill(0xffffff); ball.graphics.drawCircle(0, 0, 7); addChild(ball); wall.graphics.beginFill(0xffffff); wall.graphics.drawRect(-25, -2, 50, 5); addChild(wall); addChild(score = makeTextField(10, 10, 20)); score.text = '0'; addChild(text = makeTextField(110, 200, 30)); stage.addEventListener(MouseEvent.CLICK, init); ball.x = -20; running = true; } public function init(event:MouseEvent): void { if (running) return; running = true; bv = 2; ba = 0; ball.x = W / 2; ball.y = H / 2; score.text = '' + (cnt = 0); text.text = ''; } public function update(event:Event): void { var a:Number = Math.atan2(stage.mouseX - W / 2, stage.mouseY - H / 2); var bx:Number = ball.x - W / 2; var by:Number = ball.y - H / 2; var da:Number = Math.abs(Math.atan2(bx, by) - a); if ((noColCnt -= 1) < 0 && (da < 0.2 || da > Math.PI * 2 - 0.2) && Math.abs(Math.sqrt(bx*bx + by*by) - 200) < 10) { ba = Math.PI - ba + a * 2; bv += 0.3; score.text = '' + (cnt += 1); noColCnt = 10; } wall.rotation = - a / 3.141592 * 180; ball.x += bv * Math.sin(ba); ball.y += bv * Math.cos(ba); wall.x = W / 2 + Math.sin(a) * 200; wall.y = H / 2 + Math.cos(a) * 200; if ((ball.x < 0 || ball.x > W || ball.y < 0 || ball.y > H) && running) { text.text = ' GAME OVER\nCLICK TO START'; running = false; } } } } Code Fullscreen Preview Fullscreen blackwater : 碰碰球小游戏 oreorenji : 100linesgameまわりこんで一人pong k0rin : これは楽しい 100lines game Shape Math.atan2 Math.abs bold rotation mouseY mouseX MouseEvent.CLICK drawRect drawCircle Math.sqrt Math.PI Math.cos addChild MouseEvent beginFill text addEventListener Boolean font sort new page view favorite forked pv332 forked from: circle pong hacker_7bnhd5gd forked:0 favorite:0lines:83 (diff:1) pv0 forked from: circle pong reddog forked:0 favorite:0lines:83 (diff:1) pv3253 circle bullet shinh forked:2 favorite:4lines:95 (diff:66) tag: Bullet-Hell Shmup game 弹幕 游戏源码 碰撞判断 pv1927 forked from: circle pong h_sakurai forked:5 favorite:4lines:83 (diff:67) tag: fun game