Esempio n. 1
0
 public void MakeBackup()
 {
     LOCATION_OLD         = LOCATION;
     MOVE_DIRECTION_OLD   = MOVE_DIRECTION;
     ROTATE_ANGLE_OLD     = ROTATE_ANGLE;
     HEALTH_OLD           = HEALTH;
     BODY_TYPE_OLD        = BODY_TYPE;
     ROTATE_ANGLE_GUN_OLD = ROTATE_ANGLE_GUN;
 }
Esempio n. 2
0
 public SnakeSegment(Vector2 LOCATION_g, DIRRECTION MOVE_DIRECTION_g, float ROTATE_ANGLE_g, int HEALTH_g, BODY_TYPE BODY_TYPE_g, float ROTATE_ANGLE_GUN_g = 0)
 {
     LOCATION         = LOCATION_g;
     MOVE_DIRECTION   = MOVE_DIRECTION_g;
     ROTATE_ANGLE     = ROTATE_ANGLE_g;
     HEALTH           = HEALTH_g;
     BODY_TYPE        = BODY_TYPE_g;
     ROTATE_ANGLE_GUN = ROTATE_ANGLE_GUN_g;
 }
Esempio n. 3
0
 public Meteor(Enemy WHO_g, Vector2 LOCATION_g, DIRRECTION DIRRECTION_g)
 {
     LOCATION   = LOCATION_g;
     WHO        = WHO_g;
     DIRRECTION = DIRRECTION_g;
 }
Esempio n. 4
0
        /// <param name="GAME_TIME">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime GAME_TIME)
        {
            TIMERS[0] += GAME_TIME.ElapsedGameTime.Milliseconds; TIMERS[1] += GAME_TIME.ElapsedGameTime.Milliseconds; TIMERS[2] += GAME_TIME.ElapsedGameTime.Milliseconds;

            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            PLAYER.Update(GAME_TIME);
            if (PLAYER.IS_ALIVE)
            {
                if (TIMERS[0] > 80)
                {
                    float GFmp = PLAYER.SNAKE[0].LOCATION.X == GFj ? 0 : PLAYER.SNAKE[0].LOCATION.X + 1;
                    float GFmm = PLAYER.SNAKE[0].LOCATION.X == 0 ? GFj : PLAYER.SNAKE[0].LOCATION.X - 1;
                    float GFnp = PLAYER.SNAKE[0].LOCATION.Y == GFi ? 0 : PLAYER.SNAKE[0].LOCATION.Y + 1;
                    float GFnm = PLAYER.SNAKE[0].LOCATION.Y == 0 ? GFi : PLAYER.SNAKE[0].LOCATION.Y - 1;
                    PLAYER.SNAKE[0].MakeBackup();
                    switch (PLAYER.SNAKE[0].MOVE_DIRECTION)
                    {
                    case DIRRECTION.UP:
                        PLAYER.SNAKE[0].ROTATE_ANGLE = 0;
                        PLAYER.SNAKE[0].LOCATION.Y   = GFnm;
                        break;

                    case DIRRECTION.DOWN:
                        PLAYER.SNAKE[0].ROTATE_ANGLE = 180;
                        PLAYER.SNAKE[0].LOCATION.Y   = GFnp;
                        break;

                    case DIRRECTION.LEFT:
                        PLAYER.SNAKE[0].ROTATE_ANGLE = 270;
                        PLAYER.SNAKE[0].LOCATION.X   = GFmm;
                        break;

                    case DIRRECTION.RIGHT:
                        PLAYER.SNAKE[0].ROTATE_ANGLE = 90;
                        PLAYER.SNAKE[0].LOCATION.X   = GFmp;
                        break;
                    }
                    for (int i = 1; i < PLAYER.SNAKE.Count; i++)
                    {
                        PLAYER.SNAKE[i].MakeBackup();
                        PLAYER.SNAKE[i].LOCATION         = PLAYER.SNAKE[i - 1].LOCATION_OLD;
                        PLAYER.SNAKE[i].MOVE_DIRECTION   = PLAYER.SNAKE[i - 1].MOVE_DIRECTION_OLD;
                        PLAYER.SNAKE[i].ROTATE_ANGLE     = PLAYER.SNAKE[i - 1].ROTATE_ANGLE_OLD;
                        PLAYER.SNAKE[i].HEALTH           = PLAYER.SNAKE[i - 1].HEALTH_OLD;
                        PLAYER.SNAKE[i].ROTATE_ANGLE_GUN = PLAYER.SNAKE[i - 1].ROTATE_ANGLE_GUN_OLD;
                    }
                    int REM_ITEM = -1, REM_ENEMY = -1;
                    for (int i = 0; i < ItemPack.list.Count; i++)
                    {
                        if (PLAYER.SNAKE[0].LOCATION == ItemPack.list[i].LOCATION)
                        {
                            REM_ITEM = i;
                        }
                    }
                    if (REM_ITEM != -1)
                    {
                        ItemPack.ItemAction(ItemPack.list[REM_ITEM].ITEMTYPE, PLAYER.SNAKE[PLAYER.SNAKE.Count - 1]);
                        if (PLAYER.SNAKE.Count <= MAX_SEGMENT_COUNT + 2 && ItemPack.list[REM_ITEM].ITEMTYPE != ItemType.Segment)
                        {
                            ItemPack.list.Add(ItemPack.ItemRandomGenerate(ItemPack.list[REM_ITEM].ITEMTYPE));
                        }
                        ItemPack.list.Remove(ItemPack.list[REM_ITEM]);
                    }
                    for (int i = 1; i < PLAYER.SNAKE.Count; i++)
                    {
                        if (PLAYER.SNAKE[0].LOCATION == PLAYER.SNAKE[i].LOCATION)
                        {
                            PLAYER.HEALTH = 0;
                        }
                        if (i < PLAYER.SNAKE.Count - 1)
                        {
                            PLAYER.SNAKE[i].ROTATE_ANGLE_GUN = 270 + MathHelper.ToDegrees((float)Math.Atan2(PLAYER.SNAKE[i].LOCATION.Y * 64 + 128 - Mouse.GetState().Y, PLAYER.SNAKE[i].LOCATION.X * 64 + 64 - Mouse.GetState().X));
                            PLAYER.SNAKE[i].ROTATE_ANGLE_GUN = (PLAYER.SNAKE[i].ROTATE_ANGLE_GUN < 0) ? PLAYER.SNAKE[i].ROTATE_ANGLE_GUN + 360 : PLAYER.SNAKE[i].ROTATE_ANGLE_GUN;
                        }
                    }
                    for (int j = 0; j < Enemy.list.Count; j++)
                    {
                        if (PLAYER.SNAKE[0].LOCATION == Enemy.list[j].LOCATION)
                        {
                            PLAYER.HEALTH -= 30;
                        }
                    }
                    for (int i = 0; i < Enemy.list.Count; i++)
                    {
                        if (PLAYER.IS_ATTACK_KEY_DOWN)
                        {
                            if (new Vector2((int)((Mouse.GetState().X - 32) / 64), (int)((Mouse.GetState().Y - 96) / 64)) == Enemy.list[i].LOCATION)
                            {
                                Enemy.list[i].HEALTH -= 10;
                            }
                        }
                        if (Enemy.list[i].HEALTH <= 0)
                        {
                            REM_ENEMY          = i;
                            PLAYER.KILL_COUNT += 1;
                            PLAYER.SCORE      += Enemy.list[i].ENEMY_TYPE == EnemyType.Planetroid1 ? 300 : 500;
                        }
                        Enemy.list[i].ROTATE_ANGLE = 270 + MathHelper.ToDegrees((float)Math.Atan2(Enemy.list[i].LOCATION.Y - PLAYER.SNAKE[0].LOCATION.Y, Enemy.list[i].LOCATION.X - PLAYER.SNAKE[0].LOCATION.X));
                        Enemy.list[i].ROTATE_ANGLE = (Enemy.list[i].ROTATE_ANGLE < 0) ? Enemy.list[i].ROTATE_ANGLE + 360 : Enemy.list[i].ROTATE_ANGLE;
                    }
                    if (REM_ENEMY != -1)
                    {
                        Enemy.EnemyGenerate(Enemy.list[REM_ENEMY].ENEMY_TYPE);
                        Enemy.list.Remove(Enemy.list[REM_ENEMY]);
                        SOUND_BANK["Explose"].Play();
                    }

                    TIMERS[0] = 0;
                }
                if (TIMERS[1] > 1000)
                {
                    for (int i = 0; i < Enemy.list.Count; i++)
                    {
                        switch (RANDOM_GENERATOR.Next(0, 4))
                        {
                        case 0:
                            if (Enemy.list[i].LOCATION.X != GFj)    // && Enemies[i].LOCATION.X != Enemies[j].LOCATION.X - 1 && Enemies[i].LOCATION.X != Snake[j].LOCATION.X - 1)
                            {
                                Enemy.list[i].LOCATION.X += 1;
                            }
                            break;

                        case 1:
                            if (Enemy.list[i].LOCATION.X != 0)    // && Enemies[i].LOCATION.X != Enemies[j].LOCATION.X + 1 && Enemies[i].LOCATION.X != Snake[j].LOCATION.X + 1)
                            {
                                Enemy.list[i].LOCATION.X -= 1;
                            }
                            break;

                        case 2:
                            if (Enemy.list[i].LOCATION.Y != GFi)    // && Enemies[i].LOCATION.Y != Enemies[j].LOCATION.Y - 1 && Enemies[i].LOCATION.Y != Snake[j].LOCATION.Y - 1)
                            {
                                Enemy.list[i].LOCATION.Y += 1;
                            }
                            break;

                        case 3:
                            if (Enemy.list[i].LOCATION.Y != 0)    // && Enemies[i].LOCATION.Y != Enemies[j].LOCATION.Y + 1 && Enemies[i].LOCATION.Y != Snake[j].LOCATION.Y + 1)
                            {
                                Enemy.list[i].LOCATION.Y -= 1;
                            }
                            break;
                        }
                    }
                    TIMERS[1] = 0;
                }
                if (TIMERS[2] > 100)
                {
                    for (int i = 0; i < Enemy.list.Count; i++)
                    {
                        if (Enemy.list[i].isShoot)
                        {
                            bool isTrue = true;
                            for (int j = 0; j < Meteor.list.Count; j++)
                            {
                                if (Meteor.list[j].WHO == Enemy.list[i])
                                {
                                    isTrue = false;
                                }
                            }
                            if (isTrue)
                            {
                                DIRRECTION DIR = DIRRECTION.RIGHT;
                                if (PLAYER.SNAKE[0].LOCATION.X <= Enemy.list[i].LOCATION.X && PLAYER.SNAKE[0].LOCATION.Y <= Enemy.list[i].LOCATION.Y)
                                {
                                    if (Math.Abs(PLAYER.SNAKE[0].LOCATION.X - Enemy.list[i].LOCATION.X) > Math.Abs(PLAYER.SNAKE[0].LOCATION.Y - Enemy.list[i].LOCATION.Y))
                                    {
                                        DIR = DIRRECTION.LEFT;
                                    }
                                    else if (Math.Abs(PLAYER.SNAKE[0].LOCATION.X - Enemy.list[i].LOCATION.X) < Math.Abs(PLAYER.SNAKE[0].LOCATION.Y - Enemy.list[i].LOCATION.Y))
                                    {
                                        DIR = DIRRECTION.UP;
                                    }
                                    else
                                    {
                                        int a = RANDOM_GENERATOR.Next(0, 2);
                                        if (a == 0)
                                        {
                                            DIR = DIRRECTION.LEFT;
                                        }
                                        else
                                        {
                                            DIR = DIRRECTION.UP;
                                        }
                                    }
                                }
                                if (PLAYER.SNAKE[0].LOCATION.X > Enemy.list[i].LOCATION.X && PLAYER.SNAKE[0].LOCATION.Y <= Enemy.list[i].LOCATION.Y)
                                {
                                    if (Math.Abs(PLAYER.SNAKE[0].LOCATION.X - Enemy.list[i].LOCATION.X) > Math.Abs(PLAYER.SNAKE[0].LOCATION.Y - Enemy.list[i].LOCATION.Y))
                                    {
                                        DIR = DIRRECTION.RIGHT;
                                    }
                                    else if (Math.Abs(PLAYER.SNAKE[0].LOCATION.X - Enemy.list[i].LOCATION.X) < Math.Abs(PLAYER.SNAKE[0].LOCATION.Y - Enemy.list[i].LOCATION.Y))
                                    {
                                        DIR = DIRRECTION.UP;
                                    }
                                    else
                                    {
                                        int a = RANDOM_GENERATOR.Next(0, 2);
                                        if (a == 0)
                                        {
                                            DIR = DIRRECTION.RIGHT;
                                        }
                                        else
                                        {
                                            DIR = DIRRECTION.UP;
                                        }
                                    }
                                }
                                if (PLAYER.SNAKE[0].LOCATION.X <= Enemy.list[i].LOCATION.X && PLAYER.SNAKE[0].LOCATION.Y > Enemy.list[i].LOCATION.Y)
                                {
                                    if (Math.Abs(PLAYER.SNAKE[0].LOCATION.X - Enemy.list[i].LOCATION.X) > Math.Abs(PLAYER.SNAKE[0].LOCATION.Y - Enemy.list[i].LOCATION.Y))
                                    {
                                        DIR = DIRRECTION.LEFT;
                                    }
                                    else if (Math.Abs(PLAYER.SNAKE[0].LOCATION.X - Enemy.list[i].LOCATION.X) < Math.Abs(PLAYER.SNAKE[0].LOCATION.Y - Enemy.list[i].LOCATION.Y))
                                    {
                                        DIR = DIRRECTION.DOWN;
                                    }
                                    else
                                    {
                                        int a = RANDOM_GENERATOR.Next(0, 2);
                                        if (a == 0)
                                        {
                                            DIR = DIRRECTION.LEFT;
                                        }
                                        else
                                        {
                                            DIR = DIRRECTION.DOWN;
                                        }
                                    }
                                }
                                if (PLAYER.SNAKE[0].LOCATION.X > Enemy.list[i].LOCATION.X && PLAYER.SNAKE[0].LOCATION.Y > Enemy.list[i].LOCATION.Y)
                                {
                                    if (Math.Abs(PLAYER.SNAKE[0].LOCATION.X - Enemy.list[i].LOCATION.X) > Math.Abs(PLAYER.SNAKE[0].LOCATION.Y - Enemy.list[i].LOCATION.Y))
                                    {
                                        DIR = DIRRECTION.RIGHT;
                                    }
                                    else if (Math.Abs(PLAYER.SNAKE[0].LOCATION.X - Enemy.list[i].LOCATION.X) < Math.Abs(PLAYER.SNAKE[0].LOCATION.Y - Enemy.list[i].LOCATION.Y))
                                    {
                                        DIR = DIRRECTION.DOWN;
                                    }
                                    else
                                    {
                                        int a = RANDOM_GENERATOR.Next(0, 2);
                                        if (a == 0)
                                        {
                                            DIR = DIRRECTION.RIGHT;
                                        }
                                        else
                                        {
                                            DIR = DIRRECTION.DOWN;
                                        }
                                    }
                                }

                                Meteor.list.Add(new Meteor(Enemy.list[i], Enemy.list[i].LOCATION, DIR));
                                Enemy.list[i].isShoot = false;
                            }
                        }
                    }
                    int REM_METEOR = -1;
                    for (int i = 0; i < Meteor.list.Count; i++)
                    {
                        Meteor.list[i].Update();
                        if (Meteor.list[i].LOCATION.X > GFj || Meteor.list[i].LOCATION.X == 0 || Meteor.list[i].LOCATION.Y > GFi || Meteor.list[i].LOCATION.Y == 0)
                        {
                            REM_METEOR = i;
                        }
                        for (int j = 0; j < PLAYER.SNAKE.Count; j++)
                        {
                            if (Meteor.list[i].LOCATION == PLAYER.SNAKE[j].LOCATION)
                            {
                                REM_METEOR     = i;
                                PLAYER.HEALTH -= 10;
                            }
                        }
                        if (PLAYER.IS_ATTACK_KEY_DOWN)
                        {
                            if (new Vector2((int)((Mouse.GetState().X - 32) / 64), (int)((Mouse.GetState().Y - 96) / 64)) == Meteor.list[i].LOCATION)
                            {
                                REM_METEOR = i;
                            }
                        }
                    }
                    if (REM_METEOR != -1)
                    {
                        Meteor.list.Remove(Meteor.list[REM_METEOR]);
                    }
                    TIMERS[2] = 0;
                }
                for (int i = 0; i < Enemy.list.Count; i++)
                {
                    if (Enemy.list[i].gTime > 3000)
                    {
                        Enemy.list[i].isShoot = true;
                        Enemy.list[i].gTime   = 0;
                    }
                }
            }
            base.Update(GAME_TIME);
        }