Exemplo n.º 1
0
 public Predator(Point position, int size = 4, double minspeed = 1, double maxspeed = 1)
     : base(position, size, minspeed, maxspeed, Color.Red)
 {
     #if SHOW_HUNGER
     hungerText = new Text(Hunger.ToString(), 12);
     hungerText.X = X;
     hungerText.Y = Y - 10;
     #endif
     TargetCaptured = false;
     Hunger = 300;
     GrowLimit = 5;
     Global.Predators.Add(this);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Draws a graphic to this surface.
 /// </summary>
 /// <param name="graphic">The Graphic to draw.</param>
 /// <param name="x">The X position of the Graphic.</param>
 /// <param name="y">The Y position of the Graphic.</param>
 public void Draw(Graphic graphic, float x = 0, float y = 0)
 {
     Surface tempSurface = Otter.Draw.Target;
     Otter.Draw.SetTarget(this);
     graphic.Render(x, y);
     Otter.Draw.SetTarget(tempSurface);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Renders a Graphic to the current target Surface.
 /// </summary>
 /// <param name="graphic">The Graphic to render.</param>
 /// <param name="x">The x offset to position the Graphic at.</param>
 /// <param name="y">The y offset to position the Graphic at.</param>
 public static void Graphic(Graphic graphic, float x = 0, float y = 0)
 {
     graphic.Render(x, y);
 }
Exemplo n.º 4
0
        void InitializeTexture() {
            visibleTexture = new Texture((int)Width, (int)Height);

            for (var x = 0; x < Width; x++) {
                for (var y = 0; y < Height; y++) {
                    if (PixelAt(x, y)) {
                        visibleTexture.SetPixel(x, y, Color.Red);
                    }
                    else {
                        visibleTexture.SetPixel(x, y, Color.None);
                    }
                }
            }

            visibleImage = new Image(visibleTexture);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Set the position of the Graphic.
 /// </summary>
 /// <param name="g">The Graphic to get the position from.</param>
 public void SetPosition(Graphic g, float offsetX = 0, float offsetY = 0) {
     SetPosition(g.X + offsetX, g.Y + offsetY);
 }
Exemplo n.º 6
0
        public override void Update()
        {
            #if SHOW_HUNGER
            Scene.RemoveGraphic(hungerText);
            hungerText = new Text(Hunger.ToString(), 12);
            Scene.AddGraphic(hungerText);
            hungerText.X = X - 8;
            hungerText.Y = Y - 15 - Size;
            #endif
            if (AITickCounter == 0)
            {
                AITick();
                AITickCounter = Global.AITickDelay;

            }
            Hunger--;

            var nearestHerbivore = Global.Herbivores
                .Where(cell => Global.DistanceSquared(cell, this) < Size*Size && cell.Size <= Size)
                .OrderBy(cell => Global.DistanceSquared(cell, this))
                .FirstOrDefault() as IHerbivore;
            if (nearestHerbivore != null && Target == nearestHerbivore)
            {
                Eat(nearestHerbivore);
                UnlockTarget();
            }

            dynamic currentTarget;
            if (Target is Point)
                currentTarget = (Target as Point?).Value;
            else
                currentTarget = Target as Cell;

            if (Target == null || ((int)currentTarget.X == (int)X && (int)currentTarget.Y == (int)Y))
                UnlockTarget();
            base.Update();
        }