root/as3/GameAI/trunk/src/BoidsTest.as

リビジョン 1292, 1.5 kB (コミッタ: hael, コミット時期: 3 年 前)

--

Line 
1 package
2 {
3         import flash.display.Sprite;
4         import flash.events.Event;
5         import flash.text.TextField;
6        
7         import jp.dip.hael.gameai.boids.mover.Mover;
8
9         [SWF(width="1024", height="768")]
10         public class BoidsTest extends Sprite
11         {
12                 private var m1:Mover, m2:Mover;
13                 private var s1:Sprite;
14                 private var t:TextField;
15                
16                 public function BoidsTest()
17                 {
18                         m1 = new Mover(stage.stageWidth/2, stage.stageHeight/2, 5);
19                         m2 = new Mover(0, 0, 0);
20                        
21                         s1 = new Sprite();
22                         s1.graphics.lineStyle(1, 0xFFFF0000);
23                         s1.graphics.moveTo( 10,   0);
24                         s1.graphics.lineTo(-10,  10);
25                         s1.graphics.lineTo(-10, -10);
26                         s1.graphics.lineTo( 10,   0);
27                         addChild(s1);
28                        
29                         graphics.lineStyle(1);
30                         graphics.moveTo(m1.x, m1.y);
31                        
32                         t = new TextField();
33                         t.x = 0;
34                         t.y = 20;
35                         addChild(t);
36                                                
37                         addEventListener(Event.ENTER_FRAME, onEnterFrame);
38                 }
39                
40                 private function onEnterFrame(e:Event):void
41                 {
42                         t.text = stage.frameRate.toString();
43                        
44                         m2.x = mouseX;
45                         m2.y = mouseY;
46                        
47                         m1.clearForce();
48                         m1.wander(graphics);
49                         m1.update();
50                        
51                         if(m1.x < 0) m1.x = stage.stageWidth, graphics.moveTo(m1.x, m1.y);
52                         else if(m1.x > stage.stageWidth) m1.x = 0, graphics.moveTo(m1.x, m1.y);
53                         if(m1.y < 0) m1.y = stage.stageHeight, graphics.moveTo(m1.x, m1.y);
54                         else if(m1.y > stage.stageHeight) m1.y = 0, graphics.moveTo(m1.x, m1.y);
55                        
56                         s1.x = m1.x;
57                         s1.y = m1.y;
58                         s1.rotation = m1.rotation;
59                        
60                         graphics.lineTo(m1.x, m1.y);
61                 }
62                
63         }
64 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。