示例#1
0
        public void updatePos(float direction, GameTime gameTime, ref List <GameObject> gameObjects)
        {
            Vector2 newPos = new Vector2(position.X + direction * speed * (float)gameTime.ElapsedGameTime.TotalSeconds, position.Y);

            GameObject[] collidedObjects = Collision(gameObjects.ToArray(), newPos);

            foreach (GameObject element in collidedObjects)
            {
                if (element.isTrigger)
                {
                    if (this.collect(element))
                    {
                        gameObjects.Remove(element);
                    }
                }
                else
                {
                    return;
                }
            }

            this.position = newPos;

            if (this.newState == Playerstates.IDLE_JUMP || this.newState == Playerstates.WALK_JUMP)
            {
                this.newState = Playerstates.WALK_JUMP;
            }
            else
            {
                this.newState = Playerstates.WALK;
            }
        }
示例#2
0
 public Player(string name, bool isStationary, bool isTrigger, int mass, int height, int width, Vector2 position, SpriteBatch spriteBatch, Texture2D _spriteSheet) : base(name, isStationary, isTrigger, mass, height, width, position)
 {
     spriteSheet = _spriteSheet;
     speed       = 250;
     frame       = 0;
     state       = Playerstates.IDLE;
     animLength  = new int[] { 3, 2, 2, 3, 4, 3 };
     jumpValue   = 0;
     jumpHeight  = 1;
 }
示例#3
0
        public void render(SpriteBatch spriteBatch, GameTime gameTime)
        {
            frame += (float)gameTime.ElapsedGameTime.TotalSeconds * 2; //gibt die geschwindigkeit der Animation an

            if ((int)frame > animLength[(int)state])
            {
                frame = 0;
                state = newState;
            }

            if (state == Playerstates.IDLE)
            {
                spriteBatch.Draw(spriteSheet, position, new Rectangle(30 * (int)frame, 0, 20, 30), Color.White);
            }
            else if (state == Playerstates.WALK)
            {
                spriteBatch.Draw(spriteSheet, position, new Rectangle(30 * (int)frame, 20, 20, 30), Color.White);
            }
        }
示例#4
0
        public void jump(GameTime gameTime, GameObject[] gameObjects)
        {
            if (jumpHeight < 150)
            {
                jumpValue  += 0.125f;
                jumpHeight += 300 * (float)gameTime.ElapsedGameTime.TotalSeconds / jumpValue;
                float        newPosY         = -1 * 300 * (float)gameTime.ElapsedGameTime.TotalSeconds / jumpValue + this.position.Y;
                GameObject[] collidedObjects = Collision(gameObjects, new Vector2(this.position.X, newPosY));
                foreach (GameObject element in collidedObjects)
                {
                    if (!element.isTrigger)
                    {
                        return;
                    }
                }
                this.position.Y = newPosY;
            }
            else
            {
                Vector2      newPosition     = new Vector2(this.position.X, this.position.Y + this.mass * this.gravitation * this.gravValue * (float)gameTime.ElapsedGameTime.TotalSeconds);
                GameObject[] collidedObjects = Collision(gameObjects, newPosition); //all Objects, that you would Collide with if you'd fall

                foreach (GameObject element in collidedObjects)
                {
                    if (!element.isTrigger)
                    {
                        this.gravValue = 1;
                        this.jumpValue = 0;
                        this.state     = Playerstates.IDLE;
                        this.newState  = Playerstates.IDLE;
                        jumpHeight     = 0;
                        jumpValue      = 0;
                        return;
                    }
                }
                this.position = newPosition;;
                this.gravValue++;
            }
        }
示例#5
0
文件: Player.cs 项目: 2Light/Insomnia
        public Player(Mathe mathe, Contents contents, World world, DebugFlag flag)
        {
            this.Mathe = mathe;
            debugFlag = flag;
            this.stringBuilder = new StringBuilder();
            this.Contents = contents;

            PositionCurrent = new Vector2(0, 715);
            Texturen[0] = contents.Player1;
            Texturen[1] = contents.Player2;
            Texturen[2] = contents.Player3;
            Texturen[3] = contents.Player4;
            Texturen[4] = contents.Player5;
            Texturen[5] = contents.Player6;
            Animation = new Animation(Texturen[0], true, 1, new Rectangle(0, 0, 200, 200), 1, 6);
            Blickrichtung = Richtung.Rechts;
            Playerstate = Playerstates.Idle;
            MaxSpeed = new Vector2(6, 12);
            Beschleunigung = new Vector2(0.25f, 0.60f);
            Initialgeschwindigkeit = new Vector2(2.0f, 5.5f);
            Reibung = 0.35f;
            Gravitation = 0.40f;
            jumpCounter = 0;
            jumpCounterMax = 11;
            jumpCooldown = 0;
            jumpCooldownBase = 20;
            Ground = 715;
            Groundcollision = true;

            body = BodyFactory.CreateRectangle(world, 50, 50, 1.0f, PositionCurrent);
        }
示例#6
0
文件: Player.cs 项目: 2Light/Insomnia
 public void Statuswechsel(Playerstates playerstate)
 {
     if (Playerstate != playerstate)
     {
         Playerstate = playerstate;
         switch (Playerstate)
         {
             case Playerstates.Idle: Animation.Texture = Texturen[0]; Animation.Spalte = 1; Animation.Geschwindigkeit = ((float)1 / 7); Animation.Wiederholen = true; break;
             case Playerstates.Walk: Animation.Texture = Texturen[1]; Animation.Spalte = 9; Animation.Geschwindigkeit = ((float)1 / 7); Animation.Wiederholen = true; break;
             case Playerstates.Jump: Animation.Texture = Texturen[2]; Animation.Spalte = 6; Animation.Geschwindigkeit = ((float)1 / 7); Animation.Wiederholen = false; break;
             case Playerstates.Climb1: Animation.Texture = Texturen[3]; Animation.Spalte = 5; Animation.Geschwindigkeit = ((float)1 / 7); Animation.Wiederholen = true; break;
             case Playerstates.Climb2: Animation.Texture = Texturen[4]; Animation.Spalte = 14; Animation.Geschwindigkeit = ((float)1 / 7); Animation.Wiederholen = false; break;
             case Playerstates.Lever: Animation.Texture = Texturen[5]; Animation.Spalte = 5; Animation.Geschwindigkeit = ((float)1 / 7); Animation.Wiederholen = false; break;
             case Playerstates.Run: Animation.Texture = Texturen[1]; Animation.Spalte = 9; Animation.Geschwindigkeit = ((float)1 / 7); Animation.Wiederholen = true; break;
             case Playerstates.Dead: Animation.Texture = Texturen[0]; Animation.Spalte = 1; Animation.Geschwindigkeit = ((float)1 / 7); Animation.Wiederholen = true; break;
             case Playerstates.Spawn: Animation.Texture = Texturen[0]; Animation.Spalte = 1; Animation.Geschwindigkeit = ((float)1 / 7); Animation.Wiederholen = true; break;
         }
         Animation.Abgeschlossen = false;
         Animation.AktuelleSpalte = 0;
     }
 }