示例#1
0
文件: Hud.cs 项目: crast/GameJam
 public Hud(Game1 game, Player player)
 {
     this.screenBox = new Rectangle(0, 0, game.mapWidth, game.mapHeight);
     this.player = player;
     this.thermoFrame = game.ConditionalLoadSprite("thermoframe", "sprites/thermo_frame-01");
     this.thermoFill = game.ConditionalLoadSprite("thermofill", "sprites/thermo_fill-01");
     this.warningCool = game.ConditionalLoadSprite("tiles/warning_cool-01");
     this.warningHot = game.ConditionalLoadSprite("tiles/warning_heat-01");
 }
示例#2
0
文件: Game1.cs 项目: crast/GameJam
        /// <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);

            //LEGACY
            //load all textures into a dictionary
            //LoadSprite("char1", @"sprites\ninja_large");
            LoadSprite("char1", @"sprites\ninja_01-01");
            LoadSprite("tile1", @"tiles\tile1");
            LoadSprite("startScreen", @"sprites/titlescreen-01");
            LoadSprite("endScreen", @"sprites/endgame-01");

            startScreen = new Sprite(textures["startScreen"]);
            endScreen = new Sprite(textures["endScreen"]);
            player = new Player(0, 0, new Sprite(textures["char1"], TILE_SIZE*1, TILE_SIZE*2), this, viewArea);
            this.hud = new Hud(this, player);
            LoadNextMap();

            //player.PositionX = 5 * TILE_SIZE;
            //player.PositionY = 10 * TILE_SIZE;

            this.parallax = new Parallax(this);

            viewArea.Register(parallax);
        }
示例#3
0
        /// <summary>
        /// Checks collisions against the player object
        /// </summary>
        public bool CheckCollisions(Player p)
        {
            bool collided = false;
            List<Rectangle> test = new List<Rectangle>(); //list of colliding rectangles

            //test against BLOCKS in the map
            foreach (CollisionBlock block in currentMap.CollisionBlocks)
            {
                Rectangle i = block.Rectangle;
                if (p.Rectangle.Intersects(i))
                {
                    test.Add(i); //add this block's Rectangle to the list
                    collided = true;
                    //FixCollisions((Rectangle)i, p);
                }
            }

            if (collided)
            {
                if (test.Count == 1)
                {
                    FixCollisions(test[0], p);
                }
                else if (test.Count == 2)
                {
                    //if tops = same, treat differently
                    if ((test[0].Y == test[1].Y) && (test[0].Y > p.PositionY))
                    {
                        //do something different.
                        if (Math.Abs(p.CenterX - test[0].Center.X) > Math.Abs(p.CenterX - test[1].Center.X))
                        {
                            FixCollisions(test[1], p);
                        }
                        else
                        {
                            FixCollisions(test[0], p);
                        }
                    }
                    else
                    {
                        //if tops != same, treat as separate
                        FixCollisions(test[0], p);
                        FixCollisions(test[1], p);
                    }
                }
                else if (test.Count == 3)
                {
                    FixCollisions(test[0], p);
                    FixCollisions(test[1], p);
                    FixCollisions(test[2], p);
                }
            }

            //TODO: Handle special corner cases (to resolve current collision issues)//
            /*
            //handle different number of block collisions differently
            if (collided)
            {
                if (test.Count == 1)
                    FixCollisions((Rectangle)test[0], p);
                if (test.Count == 2)
                {
                    FixCollisions(combine(test[0], test[1]), p); //COMBINES into one block!!
                }
                if (test.Count == 3)
                {
                    //whoa nelly... this works right now but it may not in super special cases.
                    FixCollisions(combine(combine(test[0], test[1]),test[2]), p); //COMBINES into one block!!

                    //with three, separate collisions
                    FixCollisions((Rectangle)test[0], p);
                    FixCollisions((Rectangle)test[1], p);
                    FixCollisions((Rectangle)test[2], p);
                }
                if (test.Count == 4)
                {
                    //with four, separate collisions
                    FixCollisions((Rectangle)test[0], p);
                    FixCollisions((Rectangle)test[1], p);
                    FixCollisions((Rectangle)test[2], p);
                    FixCollisions((Rectangle)test[3], p);
                }
            }*/

            //Console.WriteLine("Colliding = " + collided);

            return collided;
        }
示例#4
0
        public float isHeatingUp(Player p)
        {
            float heatRatio = 1f;
            float zoneRatio = .4f;
            float dHeat = 0;

            foreach (Block s in currentMap.Interactables)
            {
                if (s is HeatBlock)
                {
                    //Console.WriteLine("Found a heat block!");
                    if (s.Rectangle.Intersects(p.Rectangle))
                    {
                        //Console.WriteLine("Intersecting WHEE!");
                        HeatBlock hb = (HeatBlock)s;
                        if (hb.AddsHeat)
                        {
                            if (hb.IsPad)
                            {
                                dHeat += heatRatio;
                            }
                            else
                            {
                                //Console.WriteLine("heat zoning!");
                                dHeat += zoneRatio;
                            }
                        }
                        else
                        {
                            if (hb.IsPad)
                            {
                                dHeat -= heatRatio;
                            }
                            else
                            {
                                //Console.WriteLine("cold zone");
                                dHeat -= zoneRatio;
                            }
                        }
                    }
                }
            }

            return dHeat;
        }
示例#5
0
        /// <summary>
        /// Resolves player collisions with rectangles (using a minimum distance formula)
        /// </summary>
        public void FixCollisions(Rectangle rect, Player p)
        {
            Vector2 result = Vector2.Zero;

            float dx = 0.0f;
            float minDist = 0.0f; //min dist to move to not be colliding

            dx = rect.Right - p.PositionX; // check right side of block
            minDist = dx;
            int axis = 0; //axis at which it has to move
            int side = 1; //direction it has to move

            dx = p.PositionX + p.Sprite.Width - rect.Left; //check left side of block
            if (dx < minDist)
            {
                minDist = dx;
                axis = 0;
                side = -1;
            }

            dx = rect.Bottom - p.PositionY; // check bottom
            if (dx < minDist)
            {
                minDist = dx;
                axis = 1;
                side = 1;
            }

            dx = p.PositionY + p.Sprite.Height - rect.Top; // check Top
            if (dx < minDist)
            {
                minDist = dx;
                axis = 1;
                side = -1;
            }

            //axis, side, and minDist give us enough information to resolve the collision
            if (axis == 0)
            {
                //p.PlayerState = 2; //set to SLIDING!!

                if (side == 1) //right
                {
                    //Console.WriteLine("right");
                    p.PositionX += minDist;
                }
                else //left
                {
                    //Console.WriteLine("left");
                    p.PositionX -= minDist-1;
                }

                p.isSliding = true;
                p.Velocity *= new Vector2(0, 1); //stop all velocity in the X direction
            }
            else
            {

                if (side == 1) //bottom
                {
                    //Console.WriteLine("bottom");
                    p.PositionY += minDist;
                }
                else //top
                {
                    //Console.WriteLine("top");
                    p.PositionY -= minDist-1;

                    if(p.PlayerState != (int)Player.states.DYING)
                        p.PlayerState = 0; //set back to RUNNING
                }

                p.Velocity *= new Vector2(1,0); //stop all velocity in the Y direction
            }
        }