示例#1
0
文件: Bullet.cs 项目: tamutamu/chaos
        public virtual void MoveBy_Left(double d, ThingList targetThings)
        {
            position.X += d;
            foreach (Thing target in targetThings)
            {
                if (!target.Shootable)
                {
                    continue;
                }
                if (Left < target.Right && target.Left < Right && Top < target.Bottom && target.Top < Bottom)
                {
                    if (position.X > target.Center.X)
                    {
                        Left = target.Right;
                    }
                    target.Damage(damage);
                    Hit();
                    return;
                }
            }
            int topRow    = TopRow;
            int bottomRow = BottomRow;
            int leftCol   = LeftCol;
            Map map       = game.Map;

            if (map.IsObstacle(topRow, leftCol) || map.IsObstacle(bottomRow, leftCol))
            {
                Left = (leftCol + 1) * Settings.BLOCK_WDITH;
                Hit();
            }
        }
示例#2
0
文件: Bullet.cs 项目: tamutamu/chaos
        public virtual void MoveBy_Down(double d, ThingList targetThings)
        {
            position.Y += d;
            foreach (Thing target in targetThings)
            {
                if (!target.Shootable)
                {
                    continue;
                }
                if (Left < target.Right && target.Left < Right && Top < target.Bottom && target.Top < Bottom)
                {
                    if (position.Y < target.Center.Y)
                    {
                        Bottom = target.Top;
                    }
                    target.Damage(damage);
                    Hit();
                    return;
                }
            }
            int leftCol   = LeftCol;
            int rightCol  = RightCol;
            int bottomRow = BottomRow;
            Map map       = game.Map;

            if (map.IsObstacle(bottomRow, leftCol) || map.IsObstacle(bottomRow, rightCol))
            {
                Bottom = bottomRow * Settings.BLOCK_WDITH;
                Hit();
            }
        }
示例#3
0
 public GameScene(int numRows, int numCols)
 {
     random              = new Random();
     map                 = new Map(this, numRows, numCols);
     player              = null;
     camera              = Vector.Zero;
     players             = new ThingList();
     enemies             = new ThingList();
     enemyAddList        = new ThingList();
     playerBullets       = new BulletList();
     enemyBullets        = new BulletList();
     items               = new ThingList();
     door                = null;
     particles           = new ParticleList();
     particleAddList     = new ParticleList();
     quakeRadius         = 0;
     quakeVector         = Vector.Zero;
     flash               = 0;
     numTicks            = 0;
     cleared             = false;
     clearTimer          = 0;
     gameoverTimer       = 0;
     gameover            = false;
     backgroundParticles = new ParticleList();
     audio               = null;
 }
示例#4
0
        public override void Tick(ThingList targetThings)
        {
            stateCount++;
            if (stateCount < timer)
            {
                velocity = 0.0625 * (waitPos - position);
            }
            if (stateCount == timer)
            {
                if (facePlayer)
                {
                    direction = Math.Atan2(game.Player.Center.Y - position.Y, game.Player.Center.X - position.X);
                    velocity  = 8 * new Vector(Math.Cos(direction), Math.Sin(direction));
                }
                else
                {
                    direction = Math.PI / 2;
                    velocity  = new Vector(0, 8);
                }
                base.Tick(targetThings);
                base.Tick(targetThings);
            }

            base.Tick(targetThings);
            base.Tick(targetThings);
            base.Tick(targetThings);
            base.Tick(targetThings);
        }
示例#5
0
 public void Tick(ThingList targetThings)
 {
     foreach (Bullet bullet in bullets)
     {
         bullet.Tick(targetThings);
     }
 }
示例#6
0
 public void Tick(ThingList targetThings)
 {
     foreach (Bullet bullet in bullets)
     {
         bullet.Tick(targetThings);
     }
 }
示例#7
0
        public override void Tick(ThingList targetThings)
        {
            if (life > 0)
            {
                life--;
            }
            else
            {
                Hit();
                return;
            }

            double minRange = double.MaxValue;
            Thing target = null;
            foreach (Thing thing in targetThings)
            {
                double dx = thing.Center.X - position.X;
                double dy = thing.Center.Y - position.Y;
                double range = dx * dx + dy * dy;
                if (range < minRange)
                {
                    minRange = range;
                    target = thing;
                }
            }
            if (target != null)
            {
                double dx = target.Center.X - position.X;
                double dy = target.Center.Y - position.Y;
                double dr = (Math.Atan2(dy, dx) / Math.PI * 180) - direction;
                dr = (dr + 180) % 360;
                if (dr < 0) dr += 360;
                dr -= 180;
                if (Math.Abs(dr) < maxRotAngle * speed)
                {
                    direction += dr;
                }
                else
                {
                    direction += maxRotAngle * speed * Math.Sign(dr);
                }
            }

            if (speed < MAX_SPEED)
            {
                speed += 0.5;
            }

            velocity = speed * new Vector(Math.Cos(direction / 180.0 * Math.PI), Math.Sin(direction / 180.0 * Math.PI));

            double a = 2 * Math.PI * game.Random.NextDouble();
            if (animation % 2 == 0)
            {
                game.AddParticle(new PlayerRocketTail(game, position, 0.125 * new Vector(Math.Cos(a), Math.Sin(a))));
            }

            animation = (animation + 1) % 8;

            base.Tick(targetThings);
        }
示例#8
0
文件: GameScene.cs 项目: sinshu/chaos
 public GameScene(int numRows, int numCols)
 {
     random = new Random();
     map = new Map(this, numRows, numCols);
     player = null;
     camera = Vector.Zero;
     players = new ThingList();
     enemies = new ThingList();
     enemyAddList = new ThingList();
     playerBullets = new BulletList();
     enemyBullets = new BulletList();
     items = new ThingList();
     door = null;
     particles = new ParticleList();
     particleAddList = new ParticleList();
     quakeRadius = 0;
     quakeVector = Vector.Zero;
     flash = 0;
     numTicks = 0;
     cleared = false;
     clearTimer = 0;
     gameoverTimer = 0;
     gameover = false;
     backgroundParticles = new ParticleList();
     audio = null;
 }
示例#9
0
        public override void Tick(ThingList targetThings)
        {
            stateCount++;
            if (stateCount < timer)
            {
                velocity = 0.0625 * (waitPos - position);
            }
            if (stateCount == timer)
            {
                if (facePlayer)
                {
                    direction = Math.Atan2(game.Player.Center.Y - position.Y, game.Player.Center.X - position.X);
                    velocity = 8 * new Vector(Math.Cos(direction), Math.Sin(direction));
                }
                else
                {
                    direction = Math.PI / 2;
                    velocity = new Vector(0, 8);
                }
                base.Tick(targetThings);
                base.Tick(targetThings);
            }

            base.Tick(targetThings);
            base.Tick(targetThings);
            base.Tick(targetThings);
            base.Tick(targetThings);
        }
示例#10
0
文件: Bullet.cs 项目: tamutamu/chaos
 public virtual void MoveBy(Vector d, ThingList targetThings)
 {
     if (removed)
     {
         return;
     }
     MoveBy_Horizontal(d.X, targetThings);
     MoveBy_Vertical(d.Y, targetThings);
 }
示例#11
0
        public override void Tick(ThingList targetThings)
        {
            velocity.Y += 0.125;
            if (velocity.Y > 2)
            {
                velocity.Y = 2;
            }

            base.Tick(targetThings);
        }
示例#12
0
        public override void Tick(ThingList targetThings)
        {
            velocity.Y += 0.125;
            if (velocity.Y > 16)
            {
                velocity.Y = 16;
            }

            base.Tick(targetThings);
        }
示例#13
0
文件: Bullet.cs 项目: tamutamu/chaos
 public virtual void MoveBy_Vertical(double d, ThingList targetThings)
 {
     if (d < 0)
     {
         MoveBy_Up(d, targetThings);
     }
     else if (d > 0)
     {
         MoveBy_Down(d, targetThings);
     }
 }
示例#14
0
        public override void Tick(ThingList targetThings)
        {
            velocity.Y += 0.0625;
            if (velocity.Y > 16)
            {
                velocity.Y = 16;
            }


            base.Tick(targetThings);
        }
示例#15
0
文件: Bullet.cs 项目: tamutamu/chaos
 public virtual void MoveBy_Horizontal(double d, ThingList targetThings)
 {
     if (d < 0)
     {
         MoveBy_Left(d, targetThings);
     }
     else if (d > 0)
     {
         MoveBy_Right(d, targetThings);
     }
 }
示例#16
0
 public override void MoveBy_Right(double d, ThingList targetThings)
 {
     position.X += d;
     int topRow = TopRow;
     int bottomRow = BottomRow;
     int rightCol = RightCol;
     Map map = game.Map;
     if (map.IsObstacle(topRow, rightCol) || map.IsObstacle(bottomRow, rightCol))
     {
         Right = rightCol * Settings.BLOCK_WDITH;
         velocity.X = -velocity.X;
     }
 }
示例#17
0
 public override void MoveBy_Up(double d, ThingList targetThings)
 {
     position.Y += d;
     int leftCol = LeftCol;
     int rightCol = RightCol;
     int topRow = TopRow;
     Map map = game.Map;
     if (map.IsObstacle(topRow, leftCol) || map.IsObstacle(topRow, rightCol))
     {
         Top = (topRow + 1) * Settings.BLOCK_WDITH;
         velocity.Y = -velocity.Y;
     }
 }
示例#18
0
 public override void MoveBy_Left(double d, ThingList targetThings)
 {
     position.X += d;
     int topRow = TopRow;
     int bottomRow = BottomRow;
     int leftCol = LeftCol;
     Map map = game.Map;
     if (map.IsObstacle(topRow, leftCol) || map.IsObstacle(bottomRow, leftCol))
     {
         Left = (leftCol + 1) * Settings.BLOCK_WDITH;
         velocity.X = -velocity.X;
     }
 }
示例#19
0
文件: StageData.cs 项目: sinshu/chaos
 public ThingList GetEnemies(GameScene game)
 {
     ThingList enemies = new ThingList();
     for (int i = 0; i < thingData.Length; i++)
     {
         Thing enemy = CreateEnemyFromData(thingData[i], game);
         if (enemy != null)
         {
             enemies.AddThing(enemy);
         }
     }
     return enemies;
 }
示例#20
0
 public override void Tick(ThingList targetThings)
 {
     if (life > 0)
     {
         life--;
     }
     else
     {
         Hit();
         return;
     }
     animation = (animation + 1) % NUM_ANIMATIONS;
     base.Tick(targetThings);
 }
示例#21
0
        public override void MoveBy_Left(double d, ThingList targetThings)
        {
            position.X += d;
            int topRow    = TopRow;
            int bottomRow = BottomRow;
            int leftCol   = LeftCol;
            Map map       = game.Map;

            if (map.IsObstacle(topRow, leftCol) || map.IsObstacle(bottomRow, leftCol))
            {
                Left       = (leftCol + 1) * Settings.BLOCK_WDITH;
                velocity.X = -velocity.X;
            }
        }
示例#22
0
 public override void Tick(ThingList targetThings)
 {
     if (life > 0)
     {
         life--;
     }
     else
     {
         Hit();
         return;
     }
     animation = (animation + 1) % NUM_ANIMATIONS;
     base.Tick(targetThings);
 }
示例#23
0
        public override void MoveBy_Right(double d, ThingList targetThings)
        {
            position.X += d;
            int topRow    = TopRow;
            int bottomRow = BottomRow;
            int rightCol  = RightCol;
            Map map       = game.Map;

            if (map.IsObstacle(topRow, rightCol) || map.IsObstacle(bottomRow, rightCol))
            {
                Right      = rightCol * Settings.BLOCK_WDITH;
                velocity.X = -velocity.X;
            }
        }
示例#24
0
        public ThingList GetEnemies(GameScene game)
        {
            ThingList enemies = new ThingList();

            for (int i = 0; i < thingData.Length; i++)
            {
                Thing enemy = CreateEnemyFromData(thingData[i], game);
                if (enemy != null)
                {
                    enemies.AddThing(enemy);
                }
            }
            return(enemies);
        }
示例#25
0
        public override void MoveBy_Up(double d, ThingList targetThings)
        {
            position.Y += d;
            int leftCol  = LeftCol;
            int rightCol = RightCol;
            int topRow   = TopRow;
            Map map      = game.Map;

            if (map.IsObstacle(topRow, leftCol) || map.IsObstacle(topRow, rightCol))
            {
                Top        = (topRow + 1) * Settings.BLOCK_WDITH;
                velocity.Y = -velocity.Y;
            }
        }
示例#26
0
        public override void Tick(ThingList targetThings)
        {
            animation++;
            if (animation % 2 == 0)
            {
                if (damage > 1)
                {
                    damage--;
                }
            }

            if (animation >= NUM_ANIMATIONS)
            {
                Remove();
            }
            base.Tick(targetThings);
        }
示例#27
0
 public override void MoveBy_Down(double d, ThingList targetThings)
 {
     position.Y += d;
     int leftCol = LeftCol;
     int rightCol = RightCol;
     int bottomRow = BottomRow;
     Map map = game.Map;
     if (map.IsObstacle(bottomRow, leftCol) || map.IsObstacle(bottomRow, rightCol))
     {
         Bottom = bottomRow * Settings.BLOCK_WDITH;
         if (game.Enemies.Count < 64)
         {
             game.AddEnemy(new Mushroom(game, new Vector(position.X - 16, Bottom - 32)));
         }
         Hit();
     }
 }
示例#28
0
        public override void Tick(ThingList targetThings)
        {
            animation++;
            if (animation % 2 == 0)
            {
                if (damage > 1)
                {
                    damage--;
                }
            }

            if (animation >= NUM_ANIMATIONS)
            {
                Remove();
            }
            base.Tick(targetThings);
        }
示例#29
0
        public override void MoveBy_Down(double d, ThingList targetThings)
        {
            position.Y += d;
            int leftCol   = LeftCol;
            int rightCol  = RightCol;
            int bottomRow = BottomRow;
            Map map       = game.Map;

            if (map.IsObstacle(bottomRow, leftCol) || map.IsObstacle(bottomRow, rightCol))
            {
                Bottom = bottomRow * Settings.BLOCK_WDITH;
                if (game.Enemies.Count < 64)
                {
                    game.AddEnemy(new Mushroom(game, new Vector(position.X - 16, Bottom - 32)));
                }
                Hit();
            }
        }
示例#30
0
        public override void MoveBy_Down(double d, ThingList targetThings)
        {
            position.Y += d;
            int leftCol   = LeftCol;
            int rightCol  = RightCol;
            int bottomRow = BottomRow;
            Map map       = game.Map;

            if (map.IsObstacle(bottomRow, leftCol) || map.IsObstacle(bottomRow, rightCol))
            {
                Bottom = bottomRow * Settings.BLOCK_WDITH;
                if (isWormEgg)
                {
                    if (game.Enemies.Count < 6)
                    {
                        if (!(position.X < game.Map.Width - 256 && position.X > 256) && position.Y > game.Map.Height - 128)
                        {
                            game.AddEnemy(new Worm(game, new Vector(position.X - 16, Bottom - 32)));
                        }
                    }
                }
                Hit();
            }
            else
            {
                foreach (Thing target in targetThings)
                {
                    if (!target.Shootable)
                    {
                        continue;
                    }
                    if (Left < target.Right && target.Left < Right && Top < target.Bottom && target.Top < Bottom)
                    {
                        if (position.Y < target.Center.Y)
                        {
                            Bottom = target.Top;
                        }
                        target.Damage(damage);
                        Hit();
                        break;
                    }
                }
            }
        }
示例#31
0
        public override void Tick(ThingList targetThings)
        {
            count++;
            double a;
            if (count < 16)
            {
                a = 2 * count;
            }
            else
            {
                a = 32;
            }
            double newHeight = baseHeight + a * Math.Sin((double)count / 16.0 * Math.PI + x);
            velocity.Y = newHeight - position.Y;
            if (Math.Abs(velocity.X) < 8)
            {
                velocity.X += Math.Sign(velocity.X) * 0.125;
            }

            base.Tick(targetThings);
        }
示例#32
0
 public override void MoveBy_Down(double d, ThingList targetThings)
 {
     position.Y += d;
     int leftCol = LeftCol;
     int rightCol = RightCol;
     int bottomRow = BottomRow;
     Map map = game.Map;
     if (map.IsObstacle(bottomRow, leftCol) || map.IsObstacle(bottomRow, rightCol))
     {
         Bottom = bottomRow * Settings.BLOCK_WDITH;
         if (isWormEgg)
         {
             if (game.Enemies.Count < 6)
             {
                 if (!(position.X < game.Map.Width - 256 && position.X > 256) && position.Y > game.Map.Height - 128)
                 {
                     game.AddEnemy(new Worm(game, new Vector(position.X - 16, Bottom - 32)));
                 }
             }
         }
         Hit();
     }
     else
     {
         foreach (Thing target in targetThings)
         {
             if (!target.Shootable) continue;
             if (Left < target.Right && target.Left < Right && Top < target.Bottom && target.Top < Bottom)
             {
                 if (position.Y < target.Center.Y)
                 {
                     Bottom = target.Top;
                 }
                 target.Damage(damage);
                 Hit();
                 break;
             }
         }
     }
 }
示例#33
0
        public GameScene(StageData data)
        {
            random = new Random();
            map    = data.GetMap(this);
            // player = new Player(this, 6, 1, Player.Direction.Right);
            player = data.GetPlayer(this);
            MoveCameraFast(player.Focus);
            players = new ThingList();
            players.AddThing(player);
            // enemies = new ThingList();
            enemies             = data.GetEnemies(this);
            enemyAddList        = new ThingList();
            playerBullets       = new BulletList();
            enemyBullets        = new BulletList();
            items               = new ThingList();
            door                = data.GetExitDoor(this);
            particles           = new ParticleList();
            particleAddList     = new ParticleList();
            quakeRadius         = 0;
            quakeVector         = Vector.Zero;
            flash               = 0;
            numTicks            = 0;
            cleared             = false;
            clearTimer          = 0;
            gameoverTimer       = 0;
            gameover            = false;
            backgroundParticles = new ParticleList();

            audio = null;

            /*
             * enemies.AddThing(new TestEnemy(this, 7, 24, TestEnemy.Direction.Left));
             * enemies.AddThing(new TestEnemy(this, 12, 11, TestEnemy.Direction.Left));
             * enemies.AddThing(new TestEnemy(this, 12, 24, TestEnemy.Direction.Left));
             * enemies.AddThing(new TestEnemy(this, 16, 8, TestEnemy.Direction.Left));
             * enemies.AddThing(new TestEnemy(this, 22, 17, TestEnemy.Direction.Left));
             */
        }
示例#34
0
文件: GameScene.cs 项目: sinshu/chaos
        public GameScene(StageData data)
        {
            random = new Random();
            map = data.GetMap(this);
            // player = new Player(this, 6, 1, Player.Direction.Right);
            player = data.GetPlayer(this);
            MoveCameraFast(player.Focus);
            players = new ThingList();
            players.AddThing(player);
            // enemies = new ThingList();
            enemies = data.GetEnemies(this);
            enemyAddList = new ThingList();
            playerBullets = new BulletList();
            enemyBullets = new BulletList();
            items = new ThingList();
            door = data.GetExitDoor(this);
            particles = new ParticleList();
            particleAddList = new ParticleList();
            quakeRadius = 0;
            quakeVector = Vector.Zero;
            flash = 0;
            numTicks = 0;
            cleared = false;
            clearTimer = 0;
            gameoverTimer = 0;
            gameover = false;
            backgroundParticles = new ParticleList();

            audio = null;

            /*
            enemies.AddThing(new TestEnemy(this, 7, 24, TestEnemy.Direction.Left));
            enemies.AddThing(new TestEnemy(this, 12, 11, TestEnemy.Direction.Left));
            enemies.AddThing(new TestEnemy(this, 12, 24, TestEnemy.Direction.Left));
            enemies.AddThing(new TestEnemy(this, 16, 8, TestEnemy.Direction.Left));
            enemies.AddThing(new TestEnemy(this, 22, 17, TestEnemy.Direction.Left));
            */
        }
示例#35
0
        public override void Tick(ThingList targetThings)
        {
            count++;
            double a;

            if (count < 16)
            {
                a = 2 * count;
            }
            else
            {
                a = 32;
            }
            double newHeight = baseHeight + a * Math.Sin((double)count / 16.0 * Math.PI + x);

            velocity.Y = newHeight - position.Y;
            if (Math.Abs(velocity.X) < 8)
            {
                velocity.X += Math.Sign(velocity.X) * 0.125;
            }

            base.Tick(targetThings);
        }
示例#36
0
文件: Bullet.cs 项目: sinshu/chaos
 public virtual void Tick(ThingList targetThings)
 {
     MoveBy(velocity, targetThings);
 }
示例#37
0
文件: Bullet.cs 项目: sinshu/chaos
 public virtual void MoveBy_Vertical(double d, ThingList targetThings)
 {
     if (d < 0)
     {
         MoveBy_Up(d, targetThings);
     }
     else if (d > 0)
     {
         MoveBy_Down(d, targetThings);
     }
 }
示例#38
0
文件: Bullet.cs 项目: sinshu/chaos
 public virtual void MoveBy_Up(double d, ThingList targetThings)
 {
     position.Y += d;
     foreach (Thing target in targetThings)
     {
         if (!target.Shootable) continue;
         if (Left < target.Right && target.Left < Right && Top < target.Bottom && target.Top < Bottom)
         {
             if (position.Y > target.Center.Y)
             {
                 Top = target.Bottom;
             }
             target.Damage(damage);
             Hit();
             return;
         }
     }
     int leftCol = LeftCol;
     int rightCol = RightCol;
     int topRow = TopRow;
     Map map = game.Map;
     if (map.IsObstacle(topRow, leftCol) || map.IsObstacle(topRow, rightCol))
     {
         Top = (topRow + 1) * Settings.BLOCK_WDITH;
         Hit();
     }
 }
示例#39
0
文件: Bullet.cs 项目: sinshu/chaos
 public virtual void MoveBy_Right(double d, ThingList targetThings)
 {
     position.X += d;
     foreach (Thing target in targetThings)
     {
         if (!target.Shootable) continue;
         if (Left < target.Right && target.Left < Right && Top < target.Bottom && target.Top < Bottom)
         {
             if (position.X < target.Center.X)
             {
                 Right = target.Left;
             }
             target.Damage(damage);
             Hit();
             return;
         }
     }
     int topRow = TopRow;
     int bottomRow = BottomRow;
     int rightCol = RightCol;
     Map map = game.Map;
     if (map.IsObstacle(topRow, rightCol) || map.IsObstacle(bottomRow, rightCol))
     {
         Right = rightCol * Settings.BLOCK_WDITH;
         Hit();
     }
 }
示例#40
0
文件: Bullet.cs 项目: sinshu/chaos
 public virtual void MoveBy_Horizontal(double d, ThingList targetThings)
 {
     if (d < 0)
     {
         MoveBy_Left(d, targetThings);
     }
     else if (d > 0)
     {
         MoveBy_Right(d, targetThings);
     }
 }
示例#41
0
文件: Bullet.cs 项目: sinshu/chaos
 public virtual void MoveBy(Vector d, ThingList targetThings)
 {
     if (removed)
     {
         return;
     }
     MoveBy_Horizontal(d.X, targetThings);
     MoveBy_Vertical(d.Y, targetThings);
 }
示例#42
0
        public override void Tick(ThingList targetThings)
        {
            if (life > 0)
            {
                life--;
            }
            else
            {
                Hit();
                return;
            }

            double minRange = double.MaxValue;
            Thing  target   = null;

            foreach (Thing thing in targetThings)
            {
                double dx    = thing.Center.X - position.X;
                double dy    = thing.Center.Y - position.Y;
                double range = dx * dx + dy * dy;
                if (range < minRange)
                {
                    minRange = range;
                    target   = thing;
                }
            }
            if (target != null)
            {
                double dx = target.Center.X - position.X;
                double dy = target.Center.Y - position.Y;
                double dr = (Math.Atan2(dy, dx) / Math.PI * 180) - direction;
                dr = (dr + 180) % 360;
                if (dr < 0)
                {
                    dr += 360;
                }
                dr -= 180;
                if (Math.Abs(dr) < rotate)
                {
                    direction += dr;
                }
                else
                {
                    direction += rotate * Math.Sign(dr);
                }
            }

            if (speed < MAX_SPEED)
            {
                speed += 0.5;
            }

            this.velocity = speed * new Vector(Math.Cos((double)direction / 180.0 * Math.PI), Math.Sin((double)direction / 180.0 * Math.PI));

            double a = 2 * Math.PI * game.Random.NextDouble();

            // if (animation % 2 == 0)
            {
                game.AddParticle(new PlayerRocketTail(game, position, 0.125 * new Vector(Math.Cos(a), Math.Sin(a))));
            }

            animation = (animation + 1) % 8;

            base.Tick(targetThings);
        }
示例#43
0
        public override void Tick(ThingList targetThings)
        {
            if (life > 0)
            {
                life--;
            }
            else
            {
                Hit();
                return;
            }

            double minRange = double.MaxValue;
            Thing target = null;
            foreach (Thing thing in targetThings)
            {
                if (!thing.Shootable || thing is AtField || thing is EggMachine)
                {
                    continue;
                }
                double dx = thing.Center.X - position.X;
                double dy = thing.Center.Y - position.Y;
                double angle = direction / 180.0 * Math.PI;
                double dr = dx * Math.Cos(angle) + dy * Math.Sin(angle);
                if (dr < 0)
                {
                    continue;
                }
                double ds = 4 * (dx * Math.Cos(angle + Math.PI / 2) + dy * Math.Sin(angle + Math.PI / 2));
                double range = dr * dr + ds * ds;
                if (range < minRange)
                {
                    minRange = range;
                    target = thing;
                }
            }
            if (target != null)
            {
                double dx = target.Center.X - position.X;
                double dy = target.Center.Y - position.Y;
                double dr = (Math.Atan2(dy, dx) / Math.PI * 180) - direction;
                dr = (dr + 180) % 360;
                if (dr < 0) dr += 360;
                dr -= 180;
                if (Math.Abs(dr) < 0.0625 * speed)
                {
                    direction += dr;
                }
                else
                {
                    direction += 0.0625 * speed * Math.Sign(dr);
                }
            }

            if (speed < MAX_SPEED)
            {
                velocity = speed * new Vector(Math.Cos(direction / 180.0 * Math.PI), Math.Sin(direction / 180.0 * Math.PI));
            }
            else
            {
                velocity = MAX_SPEED * new Vector(Math.Cos(direction / 180.0 * Math.PI), Math.Sin(direction / 180.0 * Math.PI));
            }
            if (speed < 2 * MAX_SPEED)
            {
                speed++;
            }

            double a = 2 * Math.PI * game.Random.NextDouble();
            game.AddParticle(new PlayerRocketTail(game, position, 0.125 * new Vector(Math.Cos(a), Math.Sin(a))));

            animation = (animation + 1) % 8;

            base.Tick(targetThings);
        }
示例#44
0
        public override void Tick(ThingList targetThings)
        {
            if (life > 0)
            {
                life--;
            }
            else
            {
                Hit();
                return;
            }

            double minRange = double.MaxValue;
            Thing  target   = null;

            foreach (Thing thing in targetThings)
            {
                if (!thing.Shootable || thing is AtField || thing is EggMachine)
                {
                    continue;
                }
                double dx    = thing.Center.X - position.X;
                double dy    = thing.Center.Y - position.Y;
                double angle = direction / 180.0 * Math.PI;
                double dr    = dx * Math.Cos(angle) + dy * Math.Sin(angle);
                if (dr < 0)
                {
                    continue;
                }
                double ds    = 4 * (dx * Math.Cos(angle + Math.PI / 2) + dy * Math.Sin(angle + Math.PI / 2));
                double range = dr * dr + ds * ds;
                if (range < minRange)
                {
                    minRange = range;
                    target   = thing;
                }
            }
            if (target != null)
            {
                double dx = target.Center.X - position.X;
                double dy = target.Center.Y - position.Y;
                double dr = (Math.Atan2(dy, dx) / Math.PI * 180) - direction;
                dr = (dr + 180) % 360;
                if (dr < 0)
                {
                    dr += 360;
                }
                dr -= 180;
                if (Math.Abs(dr) < 0.0625 * speed)
                {
                    direction += dr;
                }
                else
                {
                    direction += 0.0625 * speed * Math.Sign(dr);
                }
            }

            if (speed < MAX_SPEED)
            {
                velocity = speed * new Vector(Math.Cos(direction / 180.0 * Math.PI), Math.Sin(direction / 180.0 * Math.PI));
            }
            else
            {
                velocity = MAX_SPEED * new Vector(Math.Cos(direction / 180.0 * Math.PI), Math.Sin(direction / 180.0 * Math.PI));
            }
            if (speed < 2 * MAX_SPEED)
            {
                speed++;
            }

            double a = 2 * Math.PI * game.Random.NextDouble();

            game.AddParticle(new PlayerRocketTail(game, position, 0.125 * new Vector(Math.Cos(a), Math.Sin(a))));

            animation = (animation + 1) % 8;

            base.Tick(targetThings);
        }
示例#45
0
文件: Bullet.cs 项目: tamutamu/chaos
 public virtual void Tick(ThingList targetThings)
 {
     MoveBy(velocity, targetThings);
 }