Exemplo n.º 1
0
        public Tank(Textures.ID idTank, Textures.ID idTurret, ResourceHolder resources, TankColor color) :
            base(idTank, resources)
        {
            // Создаем турель (башню) танка
            turret = new Turret(idTurret, resources, this);

            // Определяем цвет танка
            this.color = color;

            // Определяем номер танка
            number                  = new Text(((int)color + 1).ToString(), resources.GetFont(Fonts.ID.Sansation), 20);
            number.FillColor        = Color.Red;
            number.OutlineThickness = 0.75f;
            Utilities.CenterOrigin(number);
            TankMoved += delegate(object sender, MoveTankEventArgs e)
            {
                number.Position = e.newPosition + new Vector2f(Utilities.GetInstance().TILE_SIZE / 3, Utilities.GetInstance().TILE_SIZE / 3);
            };

            // Создаем полоску для указания направления танка
            direction           = new RectangleShape(new Vector2f(6, 16));
            direction.FillColor = Color.Yellow;
            Utilities.CenterOrigin(direction, 0, 16);
            TankMoved += delegate(object sender, MoveTankEventArgs e)
            {
                direction.Position = e.newPosition;
            };
            TankRotated += delegate(object sender, RotateTankEventArgs e)
            {
                direction.Rotation = sprite.Rotation;
            };

            // Выставляем Origin в центр картинки
            Utilities.CenterOrigin(sprite);
        }
Exemplo n.º 2
0
        public FlatRedBall.Instructions.Instruction InterpolateToState(TankColor stateToInterpolateTo, double secondsToTake)
        {
            switch (stateToInterpolateTo)
            {
            case  TankColor.Orange:
                TurretInstance.InterpolateToState(GreasyPlatypusSlapper.Entities.Turret.TurretColor.Orange, secondsToTake);
                break;

            case  TankColor.Red:
                TurretInstance.InterpolateToState(GreasyPlatypusSlapper.Entities.Turret.TurretColor.Red, secondsToTake);
                break;

            case  TankColor.Green:
                TurretInstance.InterpolateToState(GreasyPlatypusSlapper.Entities.Turret.TurretColor.Green, secondsToTake);
                break;

            case  TankColor.Olive:
                TurretInstance.InterpolateToState(GreasyPlatypusSlapper.Entities.Turret.TurretColor.Olive, secondsToTake);
                break;
            }
            var instruction = new FlatRedBall.Instructions.DelegateInstruction <TankColor>(StopStateInterpolation, stateToInterpolateTo);

            instruction.TimeToExecute = FlatRedBall.TimeManager.CurrentTime + secondsToTake;
            this.Instructions.Add(instruction);
            return(instruction);
        }
Exemplo n.º 3
0
    public override void OnLobbyServerSceneLoadedForPlayer(NetworkManager manager, GameObject lobbyPlayer, GameObject gamePlayer)
    {
        LobbyPlayer lobby = lobbyPlayer.GetComponent <LobbyPlayer>();
        TankColor   tank  = gamePlayer.GetComponent <TankColor>();

        tank.color = lobby.playerColor;
    }
Exemplo n.º 4
0
        //инициализация танков
        public List <Tank> InitTanks(int tanksCount, int tankVisible)
        {
            Random      rand;
            List <Tank> tanks = new List <Tank>();

            rand = new Random(DateTime.Now.Millisecond);

            Tank.CellCount   = cellCount;
            Tank.TankVisible = tankVisible;
            TankColor tankColor = TankColor.Blue;

            for (int i = 0; i < 2 * tanksCount; i++)
            {
                int  x, y;
                bool flag = false;

                if (i >= tanksCount)
                {
                    tankColor = TankColor.Red;
                }

                do
                {
                    //позиция на поле
                    if (tankColor == TankColor.Blue)
                    {
                        x = rand.Next(0, 15);
                    }
                    else
                    {
                        x = rand.Next(15, 30);
                    }
                    y = rand.Next(0, 30);
                    foreach (var tank in tanks)
                    {
                        if (tank.X == x && tank.Y == y)
                        {
                            flag = true;
                        }
                    }
                } while (flag);

                //ориентация
                int rotate = rand.Next(1, 4);

                Tank t = new Tank()
                {
                    X = x, Y = y, Orient = (Tank.Orientation)rotate, Color = (int)tankColor
                };
                tanks.Add(t);
            }
            return(tanks);
        }
Exemplo n.º 5
0
    public void Paint(TankColor color)
    {
        Material mat = Resources.Load("Colors/" + color.ToString()) as Material;

        foreach (Transform child in transform)
        {
            if (child.CompareTag("Colorized"))
            {
                child.GetComponent <Renderer>().material = mat;
            }
        }
    }
Exemplo n.º 6
0
    public override void OnLobbyServerSceneLoadedForPlayer(NetworkManager manager, GameObject lobbyPlayer, GameObject gamePlayer)
    {
        LobbyPlayer  lobby      = lobbyPlayer.GetComponent <LobbyPlayer>();
        TankColor    tank       = gamePlayer.GetComponent <TankColor>();
        ClampName    playerName = gamePlayer.GetComponentInChildren <ClampName>();
        TankIdentity playerID   = gamePlayer.GetComponent <TankIdentity>();

        tank.color          = lobby.playerColor;
        playerName.nickName = lobby.playerName;
        playerName.color    = lobby.playerColor;
        totalPlayerCount    = ID;
        playerID.setIdentity(ID++);
    }
Exemplo n.º 7
0
 public AnimatedTank(Tank tank, Map map, int angle, TankColor color)
 {
     Frames           = 15;
     this.tank        = tank;
     this.Color       = color;
     currentBlock     = map.Blocks[tank.X, tank.Y];
     this.Angle       = angle;
     oldAngle         = angle;
     newAngle         = angle;
     oldX             = tank.X * 50;
     oldY             = tank.Y * 50;
     PhisicalPosition = new Vector2(oldX, oldY);
     this.map         = map;
 }
Exemplo n.º 8
0
        //стратегия
        public List <Tank> ApplyStrategy(List <Tank> tanks, TankColor tankColor, string player, bool attack)
        {
            int[] field2 = FillField(tanks);
            for (int i = 0; i < cellCount; i++)
            {
                for (int j = 0; j < cellCount; j++)
                {
                    field[i, j] = field2[i * cellCount + j];
                }
            }

            int x, y;

            foreach (var tank1 in tanks.ToList())
            {
                if (tank1.Color == (int)tankColor)
                {
                    tank1.Strategy(out x, out y, field, attack);
                    //если танк подбит
                    if (x != -1)
                    {
                        foreach (var tank2 in tanks.ToList())
                        {
                            if (tank2.X == x && tank2.Y == y)
                            {
                                tanks.Remove(tank2);
                            }
                        }
                    }
                }

                //заполнение журнала
                using (TankContext db = new TankContext()) {
                    TankDetail tank = new TankDetail {
                        X        = tank1.X,
                        Y        = tank1.Y,
                        Color    = (tank1.Color == -1)?"Красный":"Синий",
                        Orient   = Orient(tank1),
                        Player   = player,
                        Strategy = (attack) ? "Aтака" : "Оборона",
                    };

                    db.TankDetails.Add(tank);
                    db.SaveChanges();
                }
            }
            return(tanks);
        }
Exemplo n.º 9
0
        public void StopStateInterpolation(TankColor stateToStop)
        {
            switch (stateToStop)
            {
            case  TankColor.Orange:
                break;

            case  TankColor.Red:
                break;

            case  TankColor.Green:
                break;

            case  TankColor.Olive:
                break;
            }
            CurrentTankColorState = stateToStop;
        }
Exemplo n.º 10
0
    public void SetBaseValues(TankScriptableObjects configs)
    {
        speed     = configs.speed;
        health    = configs.health;
        attack    = configs.attack;
        tankColor = configs.tankColor;

        foreach (MeshRenderer mesh in meshes)
        {
            if (tankColor == TankColor.Blue)
            {
                mesh.material.color = Color.blue;
            }
            else if (tankColor == TankColor.Red)
            {
                mesh.material.color = Color.red;
            }
        }
    }
Exemplo n.º 11
0
        public static void PreloadStateContent(TankColor state, string contentManagerName)
        {
            ContentManagerName = contentManagerName;
            switch (state)
            {
            case  TankColor.Orange:
            {
                object throwaway = "OrangeBody";
            }
                {
                    object throwaway = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Orange;
                }
                break;

            case  TankColor.Red:
            {
                object throwaway = "RedBody";
            }
                {
                    object throwaway = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Red;
                }
                break;

            case  TankColor.Green:
            {
                object throwaway = "GreenBody";
            }
                {
                    object throwaway = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Green;
                }
                break;

            case  TankColor.Olive:
            {
                object throwaway = "OliveBody";
            }
                {
                    object throwaway = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Olive;
                }
                break;
            }
        }
Exemplo n.º 12
0
        public void ColorSelector(TankColor color)
        {
            for (int index = 0; index < 4; index++)
            {
                switch (color)
                {
                case TankColor.BLUE:
                    mesh[index].material = tankMaterialBlue;
                    break;

                case TankColor.GREEN:
                    mesh[index].material = tankMaterialGreen;
                    break;

                case TankColor.RED:
                    mesh[index].material = tankMaterialRed;
                    break;
                }
            }
        }
Exemplo n.º 13
0
        //Constructors
        public TankObject(Coordinate spawnPosition, TankColor type) : base()
        {
            camera         = Camera.Instance;
            this.color     = type;
            model          = new TankModel(this.color);
            Position       = spawnPosition;
            maxHP          = 100;
            currentHP      = maxHP;
            speed          = 0;
            acceleration   = 0;
            turningAngle   = 0;
            directionBody  = 3 * Math.PI / 2;
            cannonTarget   = Position; //So that cannon is facing forward
            cannonTarget.x = (model.AllSprites["TankBody"].SubRect.w) * Math.Cos(directionBody) + Position.x;
            cannonTarget.y = (model.AllSprites["TankBody"].SubRect.w) * Math.Sin(directionBody) + Position.y;
            UpdateCannonDirection();
            model.UpdateModel(this, directionBody, directionCannon);
            cannonBulletPrototype = new BulletObject(this, this.GetBarrelEndPosition(), this.DirectionCannon);
            cannonBulletSpawner   = new WeaponProjectileSpawner(cannonBulletPrototype);
            //initialize Timers only after setting spawners and their prototypes!
            InitializeTimers();

            tankPhysics = new TankPhysicsComponent(this);

            if (color == TankColor.PLAYER)
            {
                aiComponent    = new DefaultAiComponent();
                currentFaction = Faction.PLAYER;
            }
            else
            {
                aiComponent = new TankAiComponent();
                //Use only for debugging, it neuters Tanks AI
                //aiComponent = new DefaultAiComponent();
                currentFaction = Faction.AI;
            }
        }
Exemplo n.º 14
0
        public void InterpolateBetween(TankColor firstState, TankColor secondState, float interpolationValue)
        {
            #if DEBUG
            if (float.IsNaN(interpolationValue))
            {
                throw new System.Exception("interpolationValue cannot be NaN");
            }
            #endif
            bool setTurretInstanceCurrentTurretColorState = true;
            Entities.Turret.TurretColor TurretInstanceCurrentTurretColorStateFirstValue  = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Orange;
            Entities.Turret.TurretColor TurretInstanceCurrentTurretColorStateSecondValue = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Orange;
            switch (firstState)
            {
            case  TankColor.Orange:
                if (interpolationValue < 1)
                {
                    this.SpriteInstanceCurrentChainName = "OrangeBody";
                }
                TurretInstanceCurrentTurretColorStateFirstValue = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Orange;
                break;

            case  TankColor.Red:
                if (interpolationValue < 1)
                {
                    this.SpriteInstanceCurrentChainName = "RedBody";
                }
                TurretInstanceCurrentTurretColorStateFirstValue = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Red;
                break;

            case  TankColor.Green:
                if (interpolationValue < 1)
                {
                    this.SpriteInstanceCurrentChainName = "GreenBody";
                }
                TurretInstanceCurrentTurretColorStateFirstValue = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Green;
                break;

            case  TankColor.Olive:
                if (interpolationValue < 1)
                {
                    this.SpriteInstanceCurrentChainName = "OliveBody";
                }
                TurretInstanceCurrentTurretColorStateFirstValue = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Olive;
                break;
            }
            switch (secondState)
            {
            case  TankColor.Orange:
                if (interpolationValue >= 1)
                {
                    this.SpriteInstanceCurrentChainName = "OrangeBody";
                }
                TurretInstanceCurrentTurretColorStateSecondValue = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Orange;
                break;

            case  TankColor.Red:
                if (interpolationValue >= 1)
                {
                    this.SpriteInstanceCurrentChainName = "RedBody";
                }
                TurretInstanceCurrentTurretColorStateSecondValue = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Red;
                break;

            case  TankColor.Green:
                if (interpolationValue >= 1)
                {
                    this.SpriteInstanceCurrentChainName = "GreenBody";
                }
                TurretInstanceCurrentTurretColorStateSecondValue = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Green;
                break;

            case  TankColor.Olive:
                if (interpolationValue >= 1)
                {
                    this.SpriteInstanceCurrentChainName = "OliveBody";
                }
                TurretInstanceCurrentTurretColorStateSecondValue = GreasyPlatypusSlapper.Entities.Turret.TurretColor.Olive;
                break;
            }
            if (setTurretInstanceCurrentTurretColorState)
            {
                TurretInstance.InterpolateBetween(TurretInstanceCurrentTurretColorStateFirstValue, TurretInstanceCurrentTurretColorStateSecondValue, interpolationValue);
            }
            if (interpolationValue < 1)
            {
                mCurrentTankColorState = (int)firstState;
            }
            else
            {
                mCurrentTankColorState = (int)secondState;
            }
        }