Exemplo n.º 1
0
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(GraphicsDevice);
     font = Content.Load<SpriteFont>("Fonts\\Font1");
     TextManager.load(Content);
     Lobby.load(Content);
     Rat.load(Content);
     MainMenu.load(Content);
     mainMenu.generateMenu();
     World.load(Content);
     World1 = new World("1");
 }
Exemplo n.º 2
0
        void moveHere(Vector2 npos,World world1)
        {
            bool iCanMoveHere = true;

            Rectangle nbb = new Rectangle((int)npos.X - 32, (int)npos.Y - 16, 64, 12);

            if (!justHitGround) //skip this for when you hit the ground
            {
                foreach (Tile t in world1.solidTiles) //same as intensive above but it seems to be fine
                {
                    if (nbb.Intersects(t.getBB()))
                    {
                        iCanMoveHere = false;
                        vel = new Vector2(0, 0);
                    }
                }
            }
            if (iCanMoveHere)
            {
                pos = npos;
            }
        }
Exemplo n.º 3
0
        void ResolveForces(World world1)
        {
            vel+= acc;
            acc = new Vector2(0, 0);

            //simulate friction
            if (vel.X > .1f)
            {
                vel.X -= .1f;
            }
            else if (vel.X < -.1f)
            {
                vel.X += .1f;
            }
            else
            {
                vel.X = 0;
            }
            if (vel.Y > .1f)
            {
                vel.Y -= .1f;
            }
            if (vel.Y < -.1f)
            {
                vel.Y += .1f;
            }

            moveHere(pos + vel,world1);
        }
Exemplo n.º 4
0
        public bool update(World world1)
        {
            KeyboardState kb = Keyboard.GetState();

            bb = new Rectangle((int)pos.X-32,(int)pos.Y-16,64,17);
            onGround = false;
            justHitGround = false;
            foreach (Tile t in world1.solidTiles) //super intensive consider a map probally fine though
            {
                if (pos.Y <= t.getBB().Bottom && t.getBB().Intersects(bb)&& vel.Y > 0)
                {
                    pos.Y = t.pos.Y;
                    onGround = true;
                    vel.Y = 0;
                }

                if (t.getBB().Intersects(bb))
                {
                    vel.Y = 0;
                }
            }

            if (isControled &&!iFinshed)
            {
                if (kb.IsKeyDown(Keys.Right))
                {
                    acc.X += .2f;
                    facingRight = true;
                }
                if (kb.IsKeyDown(Keys.Left))
                {
                    acc.X -= .2f;
                    facingRight = false;
                }

                if ((kb.IsKeyDown(Keys.Space) || kb.IsKeyDown(Keys.Up)) && onGround)
                {
                    acc.Y = -13f;
                    onGround = false;
                }
            }

            if (!onGround)
            {
                acc.Y += .3f;
                onGround = false;
            }

            ResolveForces(world1);

            if (pos.Y > 1600) //you fell off the map reset at start
            {
                pos = startPos;
            }

            if (Lobby.connected &&isControled)
            {
                //if the finish line is crossed
                if (!iFinshed)
                {
                    foreach (Tile t in world1.finshLine)
                    {
                        if (bb.Intersects(t.getBB()))
                        {
                            iFinshed = true;
                            sendIFinshed();
                        }
                    }
                    try
                    {
                        sendPosToServer();
                    }
                    catch
                    {
                        Lobby.state = 0;
                        Lobby.lostConnection = true;
                        Lobby.connected = false;
                        Lobby.resetLobbyPlayer();
                        return false;
                    }
                }
                else
                {
                    try
                    {
                        sendIFinshed();
                    }
                    catch
                    {
                        Lobby.state = 0;
                        Lobby.lostConnection = true;
                        Lobby.connected = false;
                        Lobby.resetLobbyPlayer();
                        return false;
                    }
                }
            }
            return true;
        }