Ejemplo n.º 1
0
    public void onClick(PlanetButton button)
    {
        Player claimant = ((Planet)button.data).Owner;

        if(claimant == null)
            return;

        Vector2 direction = button.LocalToGlobal(button.GetLocalMousePosition()) - button.GetPosition();
        direction = direction / direction.magnitude;
        int buttony = -1;
        int buttonx = -1;
        GetPlanetArrayPosition(button, ref buttony, ref buttonx);
        button = AllPlanets[buttony+Mathf.RoundToInt(direction.y), buttonx + Mathf.RoundToInt(direction.x)];

        if(((Planet)button.data).Owner != null)
            return;

        if(_haveAction && claimant.CollectedResources >= PlanetCost) {
            ClaimPlanet(button, claimant);
        } else {
            this.resLabel.alpha = 0;
            Go.to(this.resLabel, 0.1f, new TweenConfig().floatProp("alpha", 1).setIterations(4));
        }
    }
Ejemplo n.º 2
0
 void GetPlanetArrayPosition(PlanetButton button, ref int buttony, ref int buttonx)
 {
     for(int y = 0;y <= AllPlanets.GetUpperBound(0);y++) {
         for(int x = 0;x <= AllPlanets.GetUpperBound(1);x++) {
             if(button == AllPlanets[y, x]) {
                 buttony = y;
                 buttonx = x;
             }
         }
     }
 }
Ejemplo n.º 3
0
 private void ClaimPlanet(PlanetButton button, Player claimant)
 {
     claimant.CollectedResources -= PlanetCost;
     button.sprite.color = claimant.Color;
     ((Planet)button.data).Owner = claimant;
     claimant.MyPlanets.Add((Planet)button.data);
     _planetCost *= 1.10f;
     ActivateNeighbors(button);
 }
Ejemplo n.º 4
0
 void CreateGameMap(float width)
 {
     AllPlanets = new PlanetButton[(int)width / 64, (int)width / 64];
     float halfWidth = width / 2;
     int arrayLen = (int)width / 64;
     arrayLen--;
     Debug.Log (arrayLen);
     for (float y = -halfWidth; y < 0; y += 64) {
         for (float x = -halfWidth; x < halfWidth; x += 64) {
             Planet p1 = new Planet ();
             PlanetButton butt = new PlanetButton(x, y, p1, onClick);
     //				Debug.Log (string.Format ("{0},{1}", (int)(y + halfWidth) / 64, (int)(x + halfWidth) / 64));
             AllPlanets [(int)(y + halfWidth) / 64, (int)(x + halfWidth) / 64] = butt;
             Planet p2 = new Planet ();
             //Make the resource count the same as for player1 side to keep game fair
             p2.ResourceCount = p1.ResourceCount;
             butt = new PlanetButton((x * -1) - 64, (y * -1) - 64, p2, onClick);
             AllPlanets [arrayLen - ((int)(y + halfWidth) / 64), arrayLen - ((int)(x + halfWidth) / 64)] = butt;
         }
     }
 }
Ejemplo n.º 5
0
    private void ActivateNeighbors(PlanetButton button)
    {
        int buttony = -1;
        int buttonx = -1;
        GetPlanetArrayPosition(button, ref buttony, ref buttonx);

        if(buttonx - 1 >= 0)
            AddChild(AllPlanets[buttony,buttonx-1]);
        if(buttonx + 1 <= AllPlanets.GetUpperBound(1))
            AddChild(AllPlanets[buttony,buttonx+1]);
        if(buttony - 1 >= 0)
            AddChild(AllPlanets[buttony-1,buttonx]);
        if(buttony + 1 <= AllPlanets.GetUpperBound(0))
            AddChild(AllPlanets[buttony+1,buttonx]);
    }