示例#1
0
 public virtual void onCollide(BasicSprite collided)
 {
     if (eventCallback != null)
     {
         eventCallback(this);
     }
 }
示例#2
0
        public void collisionEvents(BasicSprite caller, BasicSprite collided, Rectangle data, GameTime time)
        {
            //collision detection so we can manipulate gravity to simulate real jumping
            if (caller.ToString() == "KeysToInsanity.Code.Interactive_Objects.Key")
            {
                gotKey = true;
                Console.WriteLine("A Key was picked up!");
            }

            if (caller.ToString() == "KeysToInsanity.Code.TheGentleman")
            {
                if (collided.collidable)
                    if (data.Height >= 1.0f)
                    {
                        if (theGentleman.inAir)
                            landedOnGround.play(false);

                        theGentleman.inAir = false;
                        theGentleman.jumps = 2;
                        theGentleman.velocity.setY(0.0f);
                        theGentleman.spritePos = new Vector2(theGentleman.spritePos.X, collided.spritePos.Y - theGentleman.spriteSize.Y);
                        physics.resetTime(time);
                    }
                if (collided.ToString() == "KeysToInsanity.Code.Nurse") // collided with Nurse
                {
                    theGentleman.health -= 10;
                }

                if (collided.ToString() == "KeysToInsanity.Code.Interactive_Objects.HatHanger")
                {
                    inCheckpoint = true;
                }
            }
        }
示例#3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            if (DRAW_BOUNDING_BOXES)
            {
                BOUNDING_BOX = new Texture2D(GraphicsDevice, 1, 1);
                BOUNDING_BOX.SetData(new[] { Color.White });
            }

            if (DRAW_MOVEMENT_VECTORS)
                MOVEMENT_VECTOR = Content.Load<Texture2D>("arrow");

            // Gentleman
            theGentleman = new TheGentleman(this);
            theGentleman.addTo(characterSprites);
            theGentleman.spritePos = new Vector2(370, 790);

            // Heads up display (HUD)
            hud = new HUD(this, GraphicsDevice);

            // static sprites - test code. To be replaced by a level loader (XML maybe)
            background = new BasicBackground(this, "padded_background");
            BasicSprite leftWall = new BasicSprite(this, "padded_wall_left", true);
            leftWall.spritePos = new Vector2(0, 0);
            leftWall.spriteSize = new Point(30, GraphicsDevice.Viewport.Height);
            BasicSprite rightWall = new BasicSprite(this, "padded_wall_right", true);
            rightWall.spritePos = new Vector2(GraphicsDevice.Viewport.Width - 30, 0);
            rightWall.spriteSize = new Point(30, GraphicsDevice.Viewport.Height);
            BasicSprite door = new BasicSprite(this, "closed_door_left_metal", false);
            door.spritePos = new Vector2(GraphicsDevice.Viewport.Width - 35, GraphicsDevice.Viewport.Height - 140);
            door.spriteSize = new Point(25, 120);
            BasicSprite floor = new BasicSprite(this, "padded_floor", true);
            floor.spritePos = new Vector2(0, GraphicsDevice.Viewport.Height - 30);
            floor.spriteSize = new Point(GraphicsDevice.Viewport.Width, 30);
            Key key = new Key(this, hud); // key requires a HUD to go to
            key.spritePos = new Vector2(30, GraphicsDevice.Viewport.Height - 80);
            key.eventCallback += new GameEventHandler(testEvents);
            HatHanger hanger = new HatHanger(this);
            hanger.spritePos = new Vector2(550, GraphicsDevice.Viewport.Height - 120);
            BasicSprite bed = new BasicSprite(this, "bed", false);
            bed.spritePos = new Vector2(350, GraphicsDevice.Viewport.Height - 60);
            bed.spriteSize = new Point(70, 55);

            floor.addTo(staticSprites);
            rightWall.addTo(staticSprites);
            leftWall.addTo(staticSprites);
            key.addTo(staticSprites);
            hanger.addTo(staticSprites);
            bed.addTo(staticSprites);
            door.addTo(staticSprites);

            /* for now, the input is created here, however later we will want
               to create it earlier in order to provide input before everything is loaded
            */
            input = new BasicInput(this, theGentleman);

            //testSound = new Sound(this, "SoundFX/Music/Op9No2Session");
            //testSound.play(true);

            // TODO: use this.Content to load your game content here
            // ^ this is now being done in our Basic classes
        }
示例#4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            if (DRAW_BOUNDING_BOXES)
            {
                BOUNDING_BOX = new Texture2D(GraphicsDevice, 1, 1);
                BOUNDING_BOX.SetData(new[] { Color.White });
            }

            if (DRAW_MOVEMENT_VECTORS)
            {
                MOVEMENT_VECTOR = Content.Load <Texture2D>("arrow");
            }

            // Gentleman
            theGentleman = new TheGentleman(this);
            theGentleman.addTo(characterSprites);
            theGentleman.spritePos = new Vector2(370, 790);

            // Heads up display (HUD)
            hud = new HUD(this, GraphicsDevice);

            // static sprites - test code. To be replaced by a level loader (XML maybe)
            background = new BasicBackground(this, "padded_background");
            BasicSprite leftWall = new BasicSprite(this, "padded_wall_left", true);

            leftWall.spritePos  = new Vector2(0, 0);
            leftWall.spriteSize = new Point(30, GraphicsDevice.Viewport.Height);
            BasicSprite rightWall = new BasicSprite(this, "padded_wall_right", true);

            rightWall.spritePos  = new Vector2(GraphicsDevice.Viewport.Width - 30, 0);
            rightWall.spriteSize = new Point(30, GraphicsDevice.Viewport.Height);
            BasicSprite door = new BasicSprite(this, "closed_door_left_metal", false);

            door.spritePos  = new Vector2(GraphicsDevice.Viewport.Width - 35, GraphicsDevice.Viewport.Height - 140);
            door.spriteSize = new Point(25, 120);
            BasicSprite floor = new BasicSprite(this, "padded_floor", true);

            floor.spritePos  = new Vector2(0, GraphicsDevice.Viewport.Height - 30);
            floor.spriteSize = new Point(GraphicsDevice.Viewport.Width, 30);
            Key key = new Key(this, hud); // key requires a HUD to go to

            key.spritePos      = new Vector2(30, GraphicsDevice.Viewport.Height - 80);
            key.eventCallback += new GameEventHandler(testEvents);
            HatHanger hanger = new HatHanger(this);

            hanger.spritePos = new Vector2(550, GraphicsDevice.Viewport.Height - 120);
            BasicSprite bed = new BasicSprite(this, "bed", false);

            bed.spritePos  = new Vector2(350, GraphicsDevice.Viewport.Height - 60);
            bed.spriteSize = new Point(70, 55);

            floor.addTo(staticSprites);
            rightWall.addTo(staticSprites);
            leftWall.addTo(staticSprites);
            key.addTo(staticSprites);
            hanger.addTo(staticSprites);
            bed.addTo(staticSprites);
            door.addTo(staticSprites);

            /* for now, the input is created here, however later we will want
             * to create it earlier in order to provide input before everything is loaded
             */
            input = new BasicInput(this, theGentleman);

            //testSound = new Sound(this, "SoundFX/Music/Op9No2Session");
            //testSound.play(true);

            // TODO: use this.Content to load your game content here
            // ^ this is now being done in our Basic classes
        }
示例#5
0
 public void applyFriction(BasicSprite s, Rectangle data)
 {
     if (s.collidable)
     {
         if (data.Height >= 1)
         {
             velocity.setX(velocity.getX() / s.friction);
         }
     }
 }
示例#6
0
 // gets collision data
 // first parameter is who i've collided with
 public virtual void onCollide(BasicSprite s, Rectangle data, GameTime time)
 {
     if (collisionCallback != null)
         collisionCallback(this, s, data, time);
 }
示例#7
0
 public virtual void onCollide(BasicSprite collided)
 {
     if (eventCallback != null)
         eventCallback(this);
 }