コード例 #1
0
 IEnumerator RemoveOlds()
 {
     //Debug.Log ("Eliminamos " + fruitsCreated.Count / 4 + " frutas");
     fruitsCreated.RemoveRange (0, fruitsCreated.Count / 4);
     yield return null;
     state = FruitState.DuplicatePopulation;
 }
コード例 #2
0
        /// <summary>
        /// Renders Fruit.
        /// </summary>
        /// <param name="state"><see cref="FruitState"/></param>
        /// <param name="pickray"><see cref="Pickray"/></param>
        /// <param name="selected">true, if selected</param>
        /// <returns>distance from viewer to item, if <see cref="Pickray"/> hits</returns>
        public float RenderFruit(FruitState state, Pickray pickray, bool selected)
        {
            Matrix matrix =
                Matrix.Translation(state.PositionX - playgroundWidth, 0, -state.PositionY + playgroundHeight);

            matrix.M11                   = state.Radius / 4.5f;
            matrix.M22                   = state.Radius / 4.5f;
            matrix.M33                   = state.Radius / 4.5f;
            renderDevice.Material        = (selected ? selectionMaterial : fruitMaterial);
            renderDevice.Transform.World = matrix;
            fruitMesh.DrawSubset(0);

            // Check for pickray-collision
            matrix.M42 = 0.0f;
            matrix.Invert();
            pickray.Origin.TransformCoordinate(matrix);
            pickray.Direction.TransformNormal(matrix);
            if (collisionBox.Intersect(pickray.Origin, pickray.Direction))
            {
                return
                    (Vector3.Subtract
                     (
                         pickray.Origin,
                         new Vector3(state.PositionX - playgroundWidth, 0, -state.PositionY + playgroundHeight)).Length());
            }
            return(0.0f);
        }
コード例 #3
0
 public void _wa_grow(WisdominiObject waiter, float totalTime)
 {
     this.waitingRef = waiter;
     waiter.isWaitingForActionToComplete = true;
     timeToCompletion = totalTime;
     state            = FruitState.growing;
 }
コード例 #4
0
ファイル: FruitRun.cs プロジェクト: Mihqas/PacmanWinForms
 public void reset(int stage)
 {
     boxDoorList = PointLists.boxDoorPointList();
     wallList    = PointLists.mapList(stage, '0');
     fruitState  = FruitState.NORMAL;
     fruit       = (stage == 1) ? new Fruit(new Point(26, 33), Direction.RIGHT) : new Fruit(new Point(26, 33), Direction.LEFT);
 }
コード例 #5
0
    IEnumerator RemoveOlds()
    {
        //Debug.Log ("Eliminamos " + fruitsCreated.Count / 4 + " frutas");
        fruitsCreated.RemoveRange(0, fruitsCreated.Count / 4);
        yield return(null);

        state = FruitState.DuplicatePopulation;
    }
コード例 #6
0
ファイル: FruitRun.cs プロジェクト: Mihqas/PacmanWinForms
 private void Init()
 {
     boxDoorList = PointLists.boxDoorPointList();
     wallList    = PointLists.mapList(stage, '0');
     directionsInit();
     fruitState = FruitState.NORMAL;
     fruit      = (stage == 1) ? new Fruit(new Point(26, 33), Direction.RIGHT) : new Fruit(new Point(26, 33), Direction.LEFT);
     State      = GameState.GAMEOVER;
 }
コード例 #7
0
    public void generateFruit(List<int[]> roomCenters)
    {
        int[] roomCenter = roomCenters [0];

        for (int i = 0; i < numIAs; i++) {
            fruitsCreated.Add((GameObject)Instantiate (prefab, new Vector3 (8*roomCenter[1], (float)i, 8*roomCenter[0]), Quaternion.identity));
        }
        state = FruitState.DuplicatePopulation;
        StartCoroutine ("FSM");
    }
コード例 #8
0
    public void generateFruit(List <int[]> roomCenters)
    {
        int[] roomCenter = roomCenters [0];

        for (int i = 0; i < numIAs; i++)
        {
            fruitsCreated.Add((GameObject)Instantiate(prefab, new Vector3(8 * roomCenter[1], (float)i, 8 * roomCenter[0]), Quaternion.identity));
        }
        state = FruitState.DuplicatePopulation;
        StartCoroutine("FSM");
    }
コード例 #9
0
    new public void reset()
    {
        clampedScale = 0.0f;
        fruitScale   = Mathf.Lerp(minFruitScale, maxFruitScale, clampedScale);
        this.transform.localScale = new Vector3(fruitScale, fruitScale, fruitScale);
        Color curColor = Color.Lerp(immatureColor, ripeColor, clampedScale);

        mat.color   = curColor;
        elapsedTime = 0.0f;
        state       = FruitState.idle;
    }
コード例 #10
0
ファイル: FruitRun.cs プロジェクト: Mihqas/PacmanWinForms
 public void Run(int fruitIndex, int stage)
 {
     this.stage      = stage;
     State           = GameState.GAMERUN;
     wallList        = PointLists.mapList(stage, '0');
     fruitState      = FruitState.NORMAL;
     fruit           = (stage == 1) ? new Fruit(new Point(26, 33), Direction.RIGHT) : new Fruit(new Point(26, 33), Direction.LEFT);
     fruitRunner     = new Task(runfruit);
     this.fruitIndex = fruitIndex;
     fruitRunner.Start();
 }
コード例 #11
0
ファイル: CoreFruit.cs プロジェクト: Bluesky787/SmartassAnts
        /// <summary>
        /// Erzeugt ein ObstZustand-Objekt mit dem Daten Zustand des Obststücks.
        /// </summary>
        internal FruitState ErzeugeInfo()
        {
            FruitState info = new FruitState((ushort)Id);

            info.PositionX    = (ushort)(koordinate.X / SimulationEnvironment.PLAYGROUND_UNIT);
            info.PositionY    = (ushort)(koordinate.Y / SimulationEnvironment.PLAYGROUND_UNIT);
            info.Radius       = (ushort)(koordinate.Radius / SimulationEnvironment.PLAYGROUND_UNIT);
            info.Amount       = (ushort)menge;
            info.CarryingAnts = (byte)TragendeInsekten.Count;
            return(info);
        }
コード例 #12
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (fruitState == FruitState.Dropping)
        {
            // Collision to Floor
            if (collision.gameObject.tag.Contains("Floor"))
            {
                GameManager.gameManagerInstance.gameState = GameState.StandBy;
                fruitState = FruitState.Collision;                //Fruit Step 3

                GameManager.gameManagerInstance.hitSource.Play();
            }
            // Collision to Fruit
            if (collision.gameObject.tag.Contains("Fruit"))
            {
                GameManager.gameManagerInstance.gameState = GameState.StandBy;
                fruitState = FruitState.Collision;                //Fruit Step 3

                GameManager.gameManagerInstance.furitCollied.Play();
            }
        }

        //Dropping,Collision,Can be combined
        if ((int)fruitState >= (int)FruitState.Dropping)
        {
            if (collision.gameObject.tag.Contains("Fruit"))
            {
                if (fruitType == collision.gameObject.GetComponent <Fruit>().fruitType&&fruitType != FruitType.Eleven)
                {
                    //Restrict to only perform one combined
                    float thisPosxy      = this.transform.position.x + this.transform.position.y;
                    float collisionPosxy = collision.transform.position.x + collision.transform.position.y;
                    if (thisPosxy > collisionPosxy) // greater than means they have different position.
                    // Combine only in this case
                    {
                        //Combined, generate a new size one fruit at the collision position,
                        //and the size will change from small to large
                        GameManager.gameManagerInstance.CombineNewFruit(fruitType, this.transform.position, collision.transform.position);
                        //Score
                        GameManager.gameManagerInstance.TotalScore     += fuirtScore;
                        GameManager.gameManagerInstance.totalScore.text = GameManager.gameManagerInstance.TotalScore.ToString();

                        Destroy(this.gameObject);
                        Destroy(collision.gameObject);                        // If it is not destroyed, it will be executed twice
                        // In this case, two identical fruits will always be combined, because the program is constantly monitoring
                        // The only difference between them is the location
                    }
                }
            }
        }
    }
コード例 #13
0
    // Update is called once per frame
    void Update()
    {
        //Game status StandBy&Fruit status StandBy, you can click the mouse to control movement,
        //and release the mouse to drop
        if (GameManager.gameManagerInstance.gameState == GameState.StandBy && fruitState == FruitState.StandBy)
        {
            if (Input.GetMouseButtonDown(0))
            {
                IsMove = true;
            }
            // release the mouse
            if (Input.GetMouseButtonUp(0) && IsMove)
            {
                IsMove = false;
                //Change the gravity and let the fruit fall by itself
                this.gameObject.GetComponent <Rigidbody2D>().gravityScale = 1.0f;
                fruitState = FruitState.Dropping;                                 //Fruit Step 2
                GameManager.gameManagerInstance.gameState = GameState.InProgress; //Step2

                //Create a new standby fruit
                GameManager.gameManagerInstance.InvokeCreateFruit(0.5f);
                GameManager.gameManagerInstance.dropSource.Play();
            }
            if (IsMove)
            {
                //change posotion
                Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                this.gameObject.GetComponent <Transform>().position = new Vector3(mousePos.x, this.gameObject.GetComponent <Transform>().position.y, this.gameObject.GetComponent <Transform>().position.z);
            }
        }

        //limit the range in the x direction
        if (this.transform.position.x > limit_x)
        {
            this.transform.position = new Vector3(limit_x, this.transform.position.y, this.transform.position.z);
        }
        if (this.transform.position.x < -limit_x)
        {
            this.transform.position = new Vector3(-limit_x, this.transform.position.y, this.transform.position.z);
        }

        //Size recovery
        if (this.transform.localScale.x < originalScale.x)      //If it's smaller than the original size, it grows faster
        {
            this.transform.localScale += new Vector3(1, 1, 1) * scaleSpeed;
        }
        if (this.transform.localScale.x > originalScale.x)
        {
            this.transform.localScale = originalScale;
        }
    }
コード例 #14
0
        public float DrawFruit(FruitState state, Pickray pickray, bool selected)
        {
            Matrix matrix = Matrix.CreateTranslation(state.PositionX - playgroundWidth, 0, -state.PositionY + playgroundHeight);

            matrix.M11 = state.Radius / 4.5f;
            matrix.M22 = state.Radius / 4.5f;
            matrix.M33 = state.Radius / 4.5f;
            foreach (var mesh in apple.Meshes)
            {
                foreach (BasicEffect eff in mesh.Effects)
                {
                    eff.World      = matrix;
                    eff.View       = camera.ViewMatrix;
                    eff.Projection = camera.ProjectionMatrix;

                    eff.LightingEnabled = true;
                    eff.DiffuseColor    = new Vector3(0.6f, 0.7f, 0.1f);
                    eff.EmissiveColor   = new Vector3(0.1f, 0.3f, 0f);

                    eff.DirectionalLight0.Enabled       = true;
                    eff.DirectionalLight0.Direction     = LIGHT_0_DIRECTION;
                    eff.DirectionalLight0.DiffuseColor  = new Vector3(0.7f, 0.4f, 0f);
                    eff.DirectionalLight0.SpecularColor = new Vector3(0.1f, 0.5f, 0f);

                    eff.DirectionalLight1.Enabled      = true;
                    eff.DirectionalLight1.Direction    = LIGHT_1_DIRECTION;
                    eff.DirectionalLight1.DiffuseColor = new Vector3(0.3f, 0.1f, 0f);

                    eff.DirectionalLight2.Enabled       = false;
                    eff.DirectionalLight2.Direction     = LIGHT_2_DIRECTION;
                    eff.DirectionalLight2.DiffuseColor  = new Vector3(0.3f, 0.4f, 0f);
                    eff.DirectionalLight0.SpecularColor = new Vector3(0.1f, 0.5f, 0f);
                }
                mesh.Draw();
            }

            //// Check for pickray-collision

            float?distance = getBoundingSphere(apple, matrix).Intersects(new Ray(pickray.Origin, pickray.Direction));

            if (distance.HasValue)
            {
                return(distance.Value);
            }

            return(0.0f);
        }
コード例 #15
0
    private void Start()
    {
        //load all references
        _fruitTransform         = transform;
        _rigidbody              = _fruitTransform.GetComponent <Rigidbody>();
        _collider               = _fruitTransform.GetComponent <Collider>();
        _renderer               = _fruitTransform.GetComponent <Renderer>();
        _fruitMaterial          = _renderer.material;
        _parentTreeFruitSpawner = _fruitTransform.GetComponentInParent <FruitSpawner>();
        _audioSource            = gameObject.GetComponent <AudioSource>();
        _gravityBodyScript      = gameObject.GetComponent <GravityBody>();

        //fruit is growing on tree
        _rigidbody.isKinematic     = true;
        _collider.enabled          = false;
        _fruitTransform.localScale = Vector3.zero;
        fruitState = FruitState.Growing;
        StartCoroutine(GrowOnTree());
    }
コード例 #16
0
    private IEnumerator OverRipening()
    {
        var   timeToOverRipen       = Random.Range(minOverRipeningTime, maxOverRipeningTime);
        float timeOverRipening      = 0;
        float baseGravityMultiplier = _gravityBodyScript.gravityMultiplier;

        while (timeOverRipening < timeToOverRipen)
        {
            var lerpRatio = timeOverRipening / timeToOverRipen;
            _fruitMaterial.color                 = Color.Lerp(ripeColor, overRipeColor, lerpRatio);
            _fruitTransform.localScale           = Vector3.Slerp(ripeStageSizeScale, overRipeStageSizeScale, lerpRatio);
            _gravityBodyScript.gravityMultiplier =
                Mathf.Lerp(baseGravityMultiplier, overRipeStageGravityMultiplier, lerpRatio);
            timeOverRipening += Time.deltaTime;
            yield return(null);
        }

        fruitState = FruitState.Overripe;
        StartCoroutine(DestroyFruit());
    }
コード例 #17
0
    // Update is called once per frame
    new void Update()
    {
        switch (state)
        {
        case FruitState.invisible:
            break;

        case FruitState.idle:
            break;

        case FruitState.growing:
            elapsedTime += Time.deltaTime;
            float tParam = elapsedTime / timeToCompletion;
            fruitScale = Mathf.Lerp(minFruitScale, maxFruitScale, tParam);
            this.transform.localScale = new Vector3(fruitScale, fruitScale, fruitScale);
            Color curColor = Color.Lerp(immatureColor, ripeColor, tParam);
            mat.color = curColor;
            if (tParam > 1)
            {
                state = FruitState.idle;
                notifyFinishAction();
            }
            break;

        case FruitState.appearing:
            elapsedTime += Time.deltaTime;
            tParam       = elapsedTime / timeToCompletion;
            if (tParam > 1)
            {
                tParam = 1;
                state  = FruitState.idle;
                notifyFinishAction();
            }
            fruitScale = Mathf.Lerp(0.0f, minFruitScale, tParam);
            this.transform.localScale = new Vector3(fruitScale, fruitScale, fruitScale);

            break;
        }
    }
コード例 #18
0
    // State Change
    void ChangeState(FruitState fs)
    {
        this.fruitState = fs;
        switch (fs)
        {
        case FruitState.Carried:
            this.Initialize();
            break;

        case FruitState.Grabbed:
            break;

        case FruitState.Released:
            break;

        case FruitState.Stand:
            break;

        default:
            break;
        }
    }
コード例 #19
0
        public void ReadWriteEnumFlags()
        {
            FruitState[] values = new FruitState[]
            {
                FruitState.Ripe | FruitState.HasWorm,
                FruitState.Rotten | FruitState.IsRed | FruitState.HasWorm | FruitState.Ripe,
                FruitState.Ripe,
                0
            };
            using (MemoryStream stream = new MemoryStream())
            {
                // Prepare test data.
                foreach (FruitState value in values)
                {
                    stream.WriteEnum(value, true);
                }
                foreach (FruitState value in values)
                {
                    stream.WriteEnum(value, true, TestTools.ReverseByteConverter);
                }

                // Read test data.
                stream.Position = 0;
                foreach (FruitState value in values)
                {
                    Assert.AreEqual(value, stream.ReadEnum <FruitState>(true));
                }
                foreach (FruitState value in values)
                {
                    Assert.AreEqual(value, stream.ReadEnum <FruitState>(true, TestTools.ReverseByteConverter));
                }

                // Read test data all at once.
                stream.Position = 0;
                CollectionAssert.AreEqual(values, stream.ReadEnums <FruitState>(values.Length, true));
                CollectionAssert.AreEqual(values, stream.ReadEnums <FruitState>(values.Length, true, TestTools.ReverseByteConverter));
            }
        }
コード例 #20
0
    private IEnumerator GrowOnTree()
    {
        var   timeToFullyGrow = Random.Range(minRipeningTime, maxRipeningTime);
        float timeGrowing     = 0;

        while (timeGrowing < timeToFullyGrow)
        {
            var lerpRatio = timeGrowing / timeToFullyGrow;
            _fruitMaterial.color       = Color.Lerp(growingColor, ripeColor, lerpRatio);
            _fruitTransform.localScale = Vector3.Lerp(Vector3.zero, ripeStageSizeScale, lerpRatio);
            timeGrowing += Time.deltaTime;
            yield return(null);
        }

        //fruit is fully ripe - clear parent & activate rb so that fruit falls from tree
        _fruitTransform.parent = null;
        _rigidbody.isKinematic = false;
        _collider.enabled      = true;
        fruitState             = FruitState.Ripe;

        //start overripening
        yield return(StartCoroutine(OverRipening()));
    }
コード例 #21
0
 void Start()
 {
     state = FruitState.DuplicatePopulation;
     StartCoroutine ("FSM");
 }
コード例 #22
0
 public void _wm_appear()
 {
     timeToCompletion = 3.0f;
     state            = FruitState.appearing;
     mat.color        = immatureColor;
 }
コード例 #23
0
 void Start()
 {
     state = FruitState.DuplicatePopulation;
     StartCoroutine("FSM");
 }
コード例 #24
0
ファイル: RenderForm.cs プロジェクト: Bluesky787/SmartassAnts
        private void render(object sender, PaintEventArgs e)
        {
            if (Visible && renderDevice != null)
            {
                if (watch.ElapsedMilliseconds > 40)
                {
                    watch.Reset();
                    watch.Start();

                    Selection selectedItem = new Selection();

                    // Selektionsinfos zurücksetzen
                    selectedItem.SelectionType = SelectionType.Nothing;
                    selectedItem.Item          = null;
                    float distanceToSelectedItem = VIEWRANGE_MAX * VIEWRANGE_MAX;

                    renderDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb(51, 153, 255), 1.0f, 0);
                    renderDevice.BeginScene();

                    //// Falls schon ein Zustand da ist kann gezeichnet werden
                    if (simulationState != null)
                    {
                        SimulationState currentState = simulationState;

                        // Update Camera
                        camera.Update(currentState.PlaygroundWidth, currentState.PlaygroundHeight);
                        renderDevice.Transform.View = camera.ViewMatrix;
                        Pickray pickray       = camera.Pickray;
                        Point   mousePosition = camera.MousePosition;

                        // render Playerground
                        modelManager.SetPlaygroundSize(currentState.PlaygroundWidth, currentState.PlaygroundHeight);
                        modelManager.RenderPlayground();

                        // render these preaty little, blue items...
                        float distance;
                        for (int i = 0; i < currentState.BugStates.Count; i++)
                        {
                            if ((distance = modelManager.RenderBug(currentState.BugStates[i], pickray, false)) > 0)
                            {
                                // select, if pickray collides with item
                                if (distance < distanceToSelectedItem)
                                {
                                    distanceToSelectedItem     = distance;
                                    selectedItem.Item          = currentState.BugStates[i];
                                    selectedItem.SelectionType = SelectionType.Bug;
                                }
                            }
                        }

                        // Render sugar
                        for (int i = 0; i < currentState.SugarStates.Count; i++)
                        {
                            if ((distance = modelManager.RenderSugar(currentState.SugarStates[i], pickray, false)) >
                                0)
                            {
                                // select, if pickray collides with item
                                if (distance < distanceToSelectedItem)
                                {
                                    distanceToSelectedItem     = distance;
                                    selectedItem.Item          = currentState.SugarStates[i];
                                    selectedItem.SelectionType = SelectionType.Sugar;
                                }
                            }
                        }

                        // Render Fruit
                        for (int i = 0; i < currentState.FruitStates.Count; i++)
                        {
                            if ((distance = modelManager.RenderFruit(currentState.FruitStates[i], pickray, false)) >
                                0)
                            {
                                // select, if pickray collides with item
                                if (distance < distanceToSelectedItem)
                                {
                                    distanceToSelectedItem     = distance;
                                    selectedItem.Item          = currentState.FruitStates[i];
                                    selectedItem.SelectionType = SelectionType.Fruit;
                                }
                            }
                        }

                        // Colony-specific stuff
                        int count = 0;
                        for (int teamIndex = 0; teamIndex < currentState.TeamStates.Count; teamIndex++)
                        {
                            for (int colonyIndex = 0;
                                 colonyIndex < currentState.TeamStates[teamIndex].ColonyStates.Count;
                                 colonyIndex++)
                            {
                                ColonyState colony = currentState.TeamStates[teamIndex].ColonyStates[colonyIndex];

                                // Ensure available materials for that colony
                                modelManager.PrepareColony(count);

                                // Render Anthills
                                for (int anthillIndex = 0; anthillIndex < colony.AnthillStates.Count; anthillIndex++)
                                {
                                    if (
                                        (distance =
                                             modelManager.RenderAnthill(
                                                 count,
                                                 colony.AnthillStates[anthillIndex],
                                                 pickray,
                                                 false)) >
                                        0) // select, if pickray collides with item
                                    {
                                        if (distance < distanceToSelectedItem)
                                        {
                                            distanceToSelectedItem      = distance;
                                            selectedItem.Item           = colony.AnthillStates[anthillIndex];
                                            selectedItem.SelectionType  = SelectionType.Anthill;
                                            selectedItem.AdditionalInfo = colony.ColonyName;
                                        }
                                    }
                                }

                                // Render Ants
                                for (int antIndex = 0; antIndex < colony.AntStates.Count; antIndex++)
                                {
                                    if (
                                        (distance =
                                             modelManager.RenderAnt(
                                                 count,
                                                 colony.AntStates[antIndex],
                                                 pickray,
                                                 false)) > 0)
                                    {
                                        // select, if pickray collides with item
                                        if (distance < distanceToSelectedItem)
                                        {
                                            distanceToSelectedItem      = distance;
                                            selectedItem.Item           = colony.AntStates[antIndex];
                                            selectedItem.SelectionType  = SelectionType.Ant;
                                            selectedItem.AdditionalInfo = colony.ColonyName;
                                        }
                                    }
                                }

                                count++;
                            }
                        }

                        // Render Marker
                        // This must happen at the end, cause of alpha-tranperency
                        count = 0;
                        for (int teamIndex = 0; teamIndex < currentState.TeamStates.Count; teamIndex++)
                        {
                            TeamState team = currentState.TeamStates[teamIndex];
                            for (int colonyIndex = 0; colonyIndex < team.ColonyStates.Count; colonyIndex++)
                            {
                                ColonyState colony = team.ColonyStates[colonyIndex];
                                for (int markerIndex = 0; markerIndex < colony.MarkerStates.Count; markerIndex++)
                                {
                                    MarkerState marker = colony.MarkerStates[markerIndex];
                                    modelManager.RenderMarker(count, marker);
                                }
                                count++;
                            }
                        }

                        // Render Statistics in the upper left corner
                        modelManager.RenderInfobox(currentState);

                        // Render Info-Tag at selected item
                        if (selectedItem.SelectionType != SelectionType.Nothing)
                        {
                            string line1;
                            string line2;
                            switch (selectedItem.SelectionType)
                            {
                            case SelectionType.Ant:

                                AntState ameise = (AntState)selectedItem.Item;
                                string   name;
                                if (!antNames.ContainsKey(ameise.Id))
                                {
                                    name = names[random.Next(names.Length)];
                                    antNames.Add(ameise.Id, name);
                                }
                                else
                                {
                                    name = antNames[ameise.Id];
                                }

                                line1 = string.Format(Resource.HovertextAntLine1, name, selectedItem.AdditionalInfo);
                                line2 = string.Format(Resource.HovertextAntLine2, ameise.Vitality);
                                break;

                            case SelectionType.Anthill:
                                line1 = Resource.HovertextAnthillLine1;
                                line2 = string.Format(Resource.HovertextAnthillLine2, selectedItem.AdditionalInfo);
                                break;

                            case SelectionType.Bug:
                                BugState bugState = (BugState)selectedItem.Item;
                                line1 = Resource.HovertextBugLine1;
                                line2 = string.Format(Resource.HovertextBugLine2, bugState.Vitality);
                                break;

                            case SelectionType.Fruit:
                                FruitState fruitState = (FruitState)selectedItem.Item;
                                line1 = Resource.HovertextFruitLine1;
                                line2 = string.Format(Resource.HovertextFruitLine2, fruitState.Amount);
                                break;

                            case SelectionType.Sugar:
                                SugarState sugar = (SugarState)selectedItem.Item;
                                line1 = Resource.HovertextSugarLine1;
                                line2 = string.Format(Resource.HovertextSugarLine2, sugar.Amount);
                                break;

                            default:
                                line1 = String.Empty;
                                line2 = String.Empty;
                                break;
                            }

                            // Text an Mausposition ausgeben
                            if (line1 != String.Empty || line2 != String.Empty)
                            {
                                modelManager.RenderInfoTag(mousePosition, line1, line2);
                            }
                        }
                    }

                    renderDevice.EndScene();
                    renderDevice.Present();
                }

                Application.DoEvents();
                Invalidate();
            }
        }
コード例 #25
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            SimulationState state = CurrentState;

            if (state == null)
            {
                return;
            }

            DrawSky();

            effect.CurrentTechnique.Passes[0].Apply();
            effect.Projection = camera.ProjectionMatrix;
            effect.View       = camera.ViewMatrix;

            DrawPlayground();

            Selection selectedItem  = new Selection();
            Pickray   pickray       = camera.Pickray;
            Point     mousePosition = camera.MousePosition;

            // Selektionsinfos zurücksetzen
            selectedItem.SelectionType = SelectionType.Nothing;
            selectedItem.Item          = null;
            float distanceToSelectedItem = VIEWRANGE_MAX * VIEWRANGE_MAX;


            // Draw Bugs
            float distance;

            foreach (var bug in state.BugStates)
            {
                if ((distance = DrawBug(bug, pickray, false)) > 0)
                {
                    if (distance < distanceToSelectedItem)
                    {
                        distanceToSelectedItem     = distance;
                        selectedItem.Item          = bug;
                        selectedItem.SelectionType = SelectionType.Bug;
                    }
                }
            }

            // Draw Sugar
            foreach (var sugar in state.SugarStates)
            {
                if ((distance = DrawSugar(sugar, pickray, false)) > 0)
                {
                    if (distance < distanceToSelectedItem)
                    {
                        distanceToSelectedItem     = distance;
                        selectedItem.Item          = sugar;
                        selectedItem.SelectionType = SelectionType.Sugar;
                    }
                }
            }

            // Draw Fruit
            foreach (var fruit in state.FruitStates)
            {
                if ((distance = DrawFruit(fruit, pickray, false)) > 0)
                {
                    if (distance < distanceToSelectedItem)
                    {
                        distanceToSelectedItem     = distance;
                        selectedItem.Item          = fruit;
                        selectedItem.SelectionType = SelectionType.Fruit;
                    }
                }
            }

            // Draw Colony Base
            foreach (var colony in state.ColonyStates)
            {
                // Draw AntHills
                foreach (var anthill in colony.AnthillStates)
                {
                    if ((distance = DrawAnthill(colony.Id, anthill, pickray, false)) > 0)
                    {
                        if (distance < distanceToSelectedItem)
                        {
                            distanceToSelectedItem      = distance;
                            selectedItem.Item           = anthill;
                            selectedItem.SelectionType  = SelectionType.Anthill;
                            selectedItem.AdditionalInfo = CurrentState.ColonyStates[anthill.ColonyId - 1].ColonyName;
                        }
                    }
                }

                // Draw Ants
                foreach (var ant in colony.AntStates)
                {
                    // Debug Messages aktualisieren
                    if (!string.IsNullOrEmpty(ant.DebugMessage))
                    {
                        DebugMessage msg;
                        if (debugMessages.ContainsKey(ant.Id))
                        {
                            msg = debugMessages[ant.Id];
                        }
                        else
                        {
                            msg = new DebugMessage();
                            debugMessages.Add(ant.Id, msg);
                        }

                        msg.CreateRound = state.CurrentRound;
                        msg.Message     = ant.DebugMessage;
                    }

                    // Draw
                    if ((distance = DrawAnt(colony.Id, ant, pickray, false)) > 0)
                    {
                        if (distance < distanceToSelectedItem)
                        {
                            distanceToSelectedItem      = distance;
                            selectedItem.Item           = ant;
                            selectedItem.SelectionType  = SelectionType.Ant;
                            selectedItem.AdditionalInfo = CurrentState.ColonyStates[ant.ColonyId - 1].ColonyName;
                        }
                    }
                }

                // Remove old Messages
                foreach (var key in debugMessages.Keys.ToArray())
                {
                    DebugMessage msg = debugMessages[key];
                    if (state.CurrentRound - msg.CreateRound > DebugMessage.ROUNDS_TO_LIFE)
                    {
                        debugMessages.Remove(key);
                    }
                }
            }

            // Draw Marker
            foreach (var colony in state.ColonyStates)
            {
                foreach (var marker in colony.MarkerStates)
                {
                    DrawMarker(colony.Id, marker);
                }
            }

            // render all sprites in one SpriteBatch.Begin()-End() cycle to save performance
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);



            // Draw debug ant-thoughts
            if (showDebugInfo)
            {
                foreach (var colony in CurrentState.ColonyStates)
                {
                    foreach (var ant in colony.AntStates)
                    {
                        // Draw actual debug text
                        if (debugMessages.ContainsKey(ant.Id))
                        {
                            DebugMessage msg       = debugMessages[ant.Id];
                            Vector3      pos       = new Vector3(ant.PositionX - playgroundWidth, 4, -ant.PositionY + playgroundHeight);
                            Vector2      screenPos = debugRenderer.WorldToScreen(pos, new Vector2(0, -20));
                            Color        boxCol    = new Color(0.5f * playerColors[ant.ColonyId - 1]);
                            boxCol.A = 128;
                            DrawTextBox(msg.Message, screenPos, boxCol, Color.White);
                        }
                    }
                }
            }

            // Draw Infobox
            DrawInfobox(state);

            // Draw Info-Tag at selected item
            if (selectedItem.SelectionType != SelectionType.Nothing)
            {
                string line1;
                string line2;
                switch (selectedItem.SelectionType)
                {
                case SelectionType.Ant:

                    AntState ameise  = (AntState)selectedItem.Item;
                    string   antName = NameHelper.GetFemaleName(ameise.Id);
                    line1 = string.Format(Strings.HovertextAntLine1, antName, selectedItem.AdditionalInfo);
                    line2 = string.Format(Strings.HovertextAntLine2, ameise.Vitality);
                    break;

                case SelectionType.Anthill:
                    line1 = Strings.HovertextAnthillLine1;
                    line2 = string.Format(Strings.HovertextAnthillLine2, selectedItem.AdditionalInfo);
                    break;

                case SelectionType.Bug:
                    BugState bugState = (BugState)selectedItem.Item;
                    string   bugName  = NameHelper.GetMaleName(bugState.Id);
                    line1 = string.Format(Strings.HovertextBugLine1, bugName);
                    line2 = string.Format(Strings.HovertextBugLine2, bugState.Vitality);
                    break;

                case SelectionType.Fruit:
                    FruitState fruitState = (FruitState)selectedItem.Item;
                    line1 = Strings.HovertextFruitLine1;
                    line2 = string.Format(Strings.HovertextFruitLine2, fruitState.Amount);
                    break;

                case SelectionType.Sugar:
                    SugarState sugar = (SugarState)selectedItem.Item;
                    line1 = Strings.HovertextSugarLine1;
                    line2 = string.Format(Strings.HovertextSugarLine2, sugar.Amount);
                    break;

                default:
                    line1 = String.Empty;
                    line2 = String.Empty;
                    break;
                }

                // Text an Mausposition ausgeben
                if (line1 != String.Empty || line2 != String.Empty)
                {
                    DrawInfoTag(mousePosition, line1, line2);
                }
            }


            spriteBatch.End();

            base.Draw(gameTime);
        }