Beispiel #1
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)
        {
            // if (!oneTime)
            // {
            GraphicsDevice.Clear(DIRT_COLOR);
            // oneTime = true;
            //}
            spriteBatch.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend);
            if (!isSimulation)
            {
                spriteBatch.Draw(startScreen, new Rectangle(0, 0, startScreen.Width, startScreen.Height), Color.White);
            }
            else
            {
                spriteBatch.Draw(home, new Rectangle(50, 50, home.Width, home.Height), Color.SandyBrown);

                for (int i = 0; i < 800; i++)
                {
                    for (int j = 0; j < 600; j++)
                    {
                        // Color pixelColor;
                        if (food.dmapVals[i, j] == true)
                        {
                            //  Console.WriteLine(i + " " + j);
                            //    // Draw food
                            //    // pixelColor = FOOD_COLOR;
                            spriteBatch.Draw(whiteRectangle, new Vector2((float)i, (float)j), null,
                                             FOOD_COLOR, 0f, Vector2.Zero, new Vector2(.56f, .56f),
                                             SpriteEffects.None, 0f);
                        }
                    }
                }

                for (int i = 0; i < col.ants.Length; i++)
                {
                    // Console.WriteLine(col.ants.Length);
                    Ant thisAnt = col.ants[i];
                    TrackColor = DIRT_COLOR;
                    oneTime    = false;
                    thisAnt.step();

                    int   thisXi = thisAnt.intX;
                    int   thisYi = thisAnt.intY;
                    float thisXf = (float)thisAnt.x;
                    float thisYf = (float)thisAnt.y;

                    FillColor = (ANT_COLOR);

                    if (thisAnt.hasFood)
                    {
                        oneTime    = true;
                        TrackColor = PHER_FOOD_COLOR;
                        FillColor  = (FOOD_COLOR);
                        if (thisXi > col.x - 10 && thisXi < col.x + 10 && thisYi > col.y - 10 && thisYi < col.y + 10)
                        {
                            // Close enough to home
                            thisAnt.hasFood  = false;
                            thisAnt.homePher = 100;
                            TrackColor       = PHER_FOOD_COLOR;
                        }
                    }
                    else if (food.getValue(thisXi, thisYi))
                    {
                        oneTime          = true;
                        thisAnt.hasFood  = true;
                        thisAnt.foodPher = 100;
                        food.bite(thisXi, thisYi);
                        TrackColor = PHER_FOOD_COLOR;
                    }

                    if (Math.Abs(thisAnt.dx) > Math.Abs(thisAnt.dy))
                    {
                        // Horizontal ant
                        spriteBatch.Draw(whiteRectangle, new Vector2(thisXf, thisYf), null,
                                         FillColor, 0f, Vector2.Zero, new Vector2(3f, 2f),
                                         SpriteEffects.None, 0f);
                        if (oneTime)
                        {
                            trackpoints.Add(new trackpoint(new Vector2(thisXf, thisYf), TrackColor));
                        }
                    }
                    else
                    {
                        // Vertical ant
                        spriteBatch.Draw(whiteRectangle, new Vector2(thisXf, thisYf), null,
                                         FillColor, 0f, Vector2.Zero, new Vector2(2f, 3f),
                                         SpriteEffects.None, 0f);
                        if (oneTime)
                        {
                            trackpoints.Add(new trackpoint(new Vector2(thisXf, thisYf), TrackColor));
                        }
                    }
                }

                foreach (trackpoint p in trackpoints)
                {
                    spriteBatch.Draw(whiteRectangle, new Vector2(p.getPoint().X, p.getPoint().Y), null,
                                     p.getColor() * p.alpha, 0f, Vector2.Zero, new Vector2(0.8f, 0.8f),
                                     SpriteEffects.None, 0f);
                }
            }
            spriteBatch.End();
            base.Draw(gameTime);
        }