Пример #1
0
 public ShootingEnemy(Texture2D mytexture, Game1 game, Vector2 myposition, Vector2 myshootdirection)
     : base(mytexture, game, myposition)
 {
     position = myposition;
     texture = mytexture;
     shootdirection = myshootdirection;
 }
Пример #2
0
 public void checkCollision(Entity entity, Game1 game)
 {
     if (entity.getRectangle().Intersects(getRectangle()))
     {
         onCollide(entity, game);
     }
 }
Пример #3
0
 public TalkingNPC(Texture2D mytexture, Vector2 myposition, String mytext, Game1 mygame)
 {
     position = myposition;
     texture = mytexture;
     text = mytext;
     game = mygame;
 }
Пример #4
0
        public override void update(Game1 game, GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
            animation.UpdateFrame(elapsed);

            base.update(game, gameTime);
        }
Пример #5
0
 public override void onCollide(Entity entity, Game1 game)
 {
     if (entity is Enemy)
     {
         health--;
     }
 }
Пример #6
0
 public Projectile(Game1 game, Vector2 myposition, Vector2 mydirection, Entity myshooter)
 {
     velocity = mydirection * speed;
     position = myposition;
     texture = game.projectileTexture;
     shooter = myshooter;
 }
Пример #7
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (Game1 game = new Game1())
     {
         game.Run();
     }
 }
Пример #8
0
        public override void onCollide(Entity entity, Game1 game)
        {
            if (entity is Player)
            {
                Boolean allEnemiesKilled = true;
                foreach (Entity e in game.entities)
                {
                    if (e is Enemy)
                    {
                        allEnemiesKilled = false;
                    }
                }

                if (allEnemiesKilled)
                {
                    game.loadLevel(nextLevel);
                }
                else
                {
                    game.showText("The door is still closed!");
                }
            }

            base.onCollide(entity, game);
        }
Пример #9
0
 public override void onCollide(Entity entity, Game1 game)
 {
     if (entity is Player)
     {
         game.showText(text);
         //game.entities.Remove(this);
     }
 }
Пример #10
0
 public Player(Game1 game, AnimatedTexture playerAnimation)
 {
     position.X = 5 * Constants.tileSizeX;
     position.Y = 5 * Constants.tileSizeY;
     shootCounter = shootSpeed; // Start with full shoot counter so that we can shoot immediately
     direction = new Vector2(0, -1);
     animation = playerAnimation;
 }
Пример #11
0
        public override void onCollide(Entity entity, Game1 game)
        {
            if (entity is Player)
            {
                startedTimer = true;
            }

            base.onCollide(entity, game);
        }
Пример #12
0
        public override void onCollide(Entity entity, Game1 game)
        {
            if (entity is Player)
            {
                ((Player)entity).health = 100;
            }

            base.onCollide(entity, game);
        }
Пример #13
0
 public MovingEnemy(Texture2D mytexture, Game1 game, Vector2 myposition, Vector2 myvelocity, int mydistance)
     : base(mytexture, game, myposition)
 {
     position = myposition;
     texture = mytexture;
     origVelocity = velocity = myvelocity;
     distanceMax = mydistance;
     distanceCount = 0;
 }
Пример #14
0
 public override void update(Game1 game, GameTime gameTime)
 {
     if (timer > 200)
     {
         game.loadLevel(1);
     }
     if (startedTimer)
     {
         timer++;
     }
 }
Пример #15
0
        public override void update(Game1 game, GameTime gameTime)
        {
            KeyboardState keyboard = Keyboard.GetState();

            if (keyboard.IsKeyDown(Keys.R))
            {
                game.loadLevel(0);
            }

            base.update(game, gameTime);
        }
Пример #16
0
        public override void update(Game1 game, GameTime gameTime)
        {
            shootCounter++;

            if (shootCounter > shootSpeed) {
                Vector2 projectilePosition = position;
                projectilePosition.X += texture.Width / 2;
                projectilePosition.Y += texture.Height / 2;
                game.entities.Add(new Projectile(game, projectilePosition, shootdirection, this));
                shootCounter = 0;
            }
        }
Пример #17
0
        public override void update(Game1 game, GameTime gameTime)
        {
            KeyboardState keyboard = Keyboard.GetState();

            if (keyboard.IsKeyDown(Keys.R))
            {
                game.loadLevel(0);
            }

            //            game.showText("You died while trying to escape the asylum. Press \"r\" to restart.");

            base.update(game, gameTime);
        }
Пример #18
0
        public override void update(Game1 game, GameTime gameTime)
        {
            flashTimer++;
            endTimer++;

            if (endTimer > 250)
            {
                game.loadLevel(4);
            }
            else if (endTimer > 200)
            {
                show = true;
            }
            else if (flashTimer > flashMaxTimer)
            {
                flashTimer = 0;
                show = !show;
            }
        }
Пример #19
0
        public override void update(Game1 game, GameTime gameTime)
        {
            distanceCount++;

            if (distanceCount > distanceMax)
            {
                origVelocity = velocity = velocity * -1;
                distanceCount = 0;
            }

            // Check for collisions
            Rectangle simulatedRectangle = getRectangle();
            simulatedRectangle.X += (int)velocity.X;
            simulatedRectangle.Y += (int)velocity.Y;

            Boolean collided = false;

            foreach (Entity e in game.entities)
            {
                if (e != this && (e is SolidObject || e is Enemy))
                {
                    if (e.testCollision(simulatedRectangle))
                    {
                        collided = true;
                        break;
                    }
                }
            }

            // don't move if collided
            if (!collided)
            {
                position.X += velocity.X;
                position.Y += velocity.Y;
            }
            // collided with player - stand still
            if (game.player.testCollision(getRectangle()))
            {
                velocity.X = 0;
                velocity.Y = 0;
            }
        }
Пример #20
0
 public Enemy(Texture2D mytexture, Game1 game, Vector2 myposition)
 {
     position = myposition;
     texture = mytexture;
 }
Пример #21
0
 public override void onCollide(Entity entity, Game1 game)
 {
     if (entity != shooter) // don't kill yourself
     {
         if (entity is Enemy)
         {
             game.entities.Remove(entity);
             game.entities.Remove(this);
         }
         else if (entity is Player)
         {
             ((Player)entity).health -= 10;
             game.entities.Remove(this);
         }
     }
 }
Пример #22
0
        public override void update(Game1 game, GameTime gameTime)
        {
            if (position.X < 0 || position.X > 840 || position.Y < 0 || position.Y > 680)
            {
                game.entities.Remove(this);
            }

            base.update(game, gameTime);
        }
Пример #23
0
 public Nurse(Texture2D mytexture, Vector2 myposition, String mytext, Game1 mygame)
     : base(mytexture, myposition, mytext, mygame)
 {
 }
Пример #24
0
 public Receptionist(Texture2D mytexture, Vector2 myposition, String mytext, Game1 mygame)
     : base(mytexture, myposition, mytext, mygame)
 {
 }
Пример #25
0
 public virtual void update(Game1 game, GameTime gameTime)
 {
     position.X += velocity.X;
     position.Y += velocity.Y;
 }
Пример #26
0
 public Door(Texture2D mytexture, Vector2 myposition, int mynextLevel, Game1 mygame)
 {
     position = myposition;
     texture = mytexture;
     nextLevel = mynextLevel;
 }
Пример #27
0
        public override void update(Game1 game, GameTime gameTime)
        {
            shootCounter++;

            position.X = MathHelper.Clamp(position.X, 0, 840);
            position.Y = MathHelper.Clamp(position.Y, 0, 580);

            KeyboardState keyboard = Keyboard.GetState();

            Vector2 newDirection = new Vector2(0, 0);

            if (keyboard.IsKeyDown(Keys.Up))
            {
                newDirection.Y = -1;
                animation.StartFrame = 9;
                animation.EndFrame = 11;
            }

            if (keyboard.IsKeyDown(Keys.Down))
            {
                newDirection.Y = 1;
                animation.StartFrame = 6;
                animation.EndFrame = 8;
            }

            if (keyboard.IsKeyDown(Keys.Left))
            {
                newDirection.X = -1;
                animation.StartFrame = 3;
                animation.EndFrame = 5;
            }

            if (keyboard.IsKeyDown(Keys.Right))
            {
                newDirection.X = 1;
                animation.StartFrame = 0;
                animation.EndFrame = 2;
            }

            if (keyboard.IsKeyUp(Keys.Left) && keyboard.IsKeyUp(Keys.Right) && keyboard.IsKeyUp(Keys.Up) && keyboard.IsKeyUp(Keys.Down))
            {
                animation.Pause();
            }
            else
            {
                animation.Play();
            }

            if (newDirection.X != 0 || newDirection.Y != 0)
            {
                Vector2 newVelocity = newDirection * speed;

                Rectangle simulatedRectangle = getRectangle();
                simulatedRectangle.X += (int)newVelocity.X;
                simulatedRectangle.Y += (int)newVelocity.Y;

                // Check for collisions
                Boolean collided = false;

                foreach (Entity e in game.entities)
                {
                    if (e is SolidObject)
                    {
                        if (e.testCollision(simulatedRectangle))
                        {
                            collided = true;
                            break;
                        }
                    }
                }

                direction = newDirection;

                if (collided)
                {
                    velocity = new Vector2(0, 0);
                }
                else
                {
                    velocity = newVelocity;
                }
            }
            else
            {
                velocity = new Vector2(0, 0);
            }

            if (keyboard.IsKeyDown(Keys.Space))
            {
                if (shootCounter > shootSpeed)
                {
                    Vector2 projectilePosition = position;
                    projectilePosition.X += animation.getWidth() / 2;
                    projectilePosition.Y += animation.getHeight() / 2;
                    game.entities.Add(new Projectile(game, projectilePosition, direction, this));
                    shootCounter = 0;
                }
            }

            base.update(game, gameTime);
        }
Пример #28
0
 public virtual void onCollide(Entity entity, Game1 game)
 {
 }