Exemplo n.º 1
0
 internal CritterWrapper(string file, CritterBrains.CritterBrain brain)
 {
     this.file  = file;
     this.brain = brain;
     critter    = null;
     if (waitingCritterImage == null)
     {
         waitingCritterImage = Utility.GetImageFromResource("CritterWaiting.png");
     }
 }
Exemplo n.º 2
0
        public static Critter CreateCritter(String fileName, CritterBrains.CritterBrain critterBrain, World world, Point position)
        {
            if (deadCritterImage == null)
            {
                deadCritterImage = Utility.GetImageFromResource("DeadCritter.png");
            }
            if (winnerCritterImage == null)
            {
                winnerCritterImage = Utility.GetImageFromResource("WinnerCritter.png");
            }
            AnimationFramesInMultipleFiles critterImages = null;

            if (critterBrain.Images == null)
            {
                // The critter does not have any built-in
                // images, so use two of our 'stock' images
                critterImages = new AnimationFramesInMultipleFiles();
                critterImages.Add(Utility.GetImageFromResource("Robo" + nextCritterNumber.ToString() + "_01.png"));
                critterImages.Add(Utility.GetImageFromResource("Robo" + nextCritterNumber.ToString() + "_02.png"));
                nextCritterNumber = (nextCritterNumber + 1) % 10;
            }
            else
            {
                critterImages = new AnimationFramesInMultipleFiles();
                foreach (Image image in critterBrain.Images)
                {
                    // Copy the images, resizing if necessary
                    Image    newImage = new Bitmap(CritterWidth, CritterHeight);
                    Graphics graphic  = Graphics.FromImage(newImage);
                    graphic.DrawImage(image, 0, 0, CritterWidth, CritterHeight);
                    critterImages.Add(newImage);
                }
            }
            SpriteImage critterAnimator = new SpriteImageMultipleFiles(critterImages);

            critterAnimator.FPS        = 4;
            critterAnimator.IsAnimated = true;
            Sprite critterSprite = new Sprite(critterAnimator);

            return(new Critter(fileName, critterBrain, world, critterSprite, CritterBoundingRadius, position));
        }
Exemplo n.º 3
0
 public Critter(String fileName, CritterBrains.CritterBrain critterBrain, World world, Sprite sprite, int boundingRadius, Point position)
     : base(world, sprite, boundingRadius)
 {
     this.critterBrain        = critterBrain;
     this.fileContainingBrain = fileName;
     critterBrain.Body        = this;
     Energy               = Utility.GetConfiguration().CritterEnergyWhenBorn;
     Position             = position;
     maximumAge           = 0;
     energyTimer          = new Timer();
     energyTimer.Interval = 1000;
     energyTimer.Tick    += new EventHandler(EnergyTimer_Tick);
     energyTimer.Start();
     ageTimer          = new Timer();
     ageTimer.Interval = 1000 * 60;
     ageTimer.Tick    += new EventHandler(AgeTimer_Tick);
     ageTimer.Start();
     poopTimer          = new Timer();
     poopTimer.Interval = Utility.NextRandom(1000, 10000);
     poopTimer.Tick    += new EventHandler(PoopTimer_Tick);
     poopTimer.Start();
 }