public void UpdatePosition(GameTime gameTime, Level level) { if (currentState != CharacterState.DEAD) { switch (currentState) { case CharacterState.JUMP: this.position.Y -= this.velocity.Y * jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; this.velocity += SideScrollGame.GRAVITY * jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; if (this.lastState == CharacterState.MOVERIGHT) { if (this.position.X + this.sourceRect.Width < level.width) this.position.X += this.velocity.X * jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; } else { if (this.position.X > 0) this.position.X -= this.velocity.X * jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; } if (this.lastPosition.Y < this.position.Y) { this.position.Y = this.lastPosition.Y; currentState = CharacterState.IDLE; } break; case CharacterState.BOOST: if (this.lastState == CharacterState.MOVERIGHT) { if (this.position.X + this.sourceRect.Width < level.width) { this.position.X += (speed * 2.0f) * (float)gameTime.ElapsedGameTime.TotalSeconds; } } else { if (this.position.X > 0) { this.position.X -= (speed * 2.0f) * (float)gameTime.ElapsedGameTime.TotalSeconds; } } break; case CharacterState.MOVELEFT: if (this.position.X > 0) { this.position.X -= speed * (float)gameTime.ElapsedGameTime.TotalSeconds; } break; case CharacterState.MOVERIGHT: if (this.position.X + this.sourceRect.Width < level.width) { this.position.X += speed * (float)gameTime.ElapsedGameTime.TotalSeconds; } break; case CharacterState.MOVEUP: foreach (Background background in level.tilesBackground) { if (background.walkable) { if (this.position.Y > background.position.Y - background.texture.Height) { this.position.Y -= speed * (float)gameTime.ElapsedGameTime.TotalSeconds; } break; } } break; case CharacterState.MOVEDOWN: if (this.position.Y + this.sourceRect.Height < GameplayScreen.main.ScreenManager.GraphicsDevice.Viewport.Height) { this.position.Y += speed * (float)gameTime.ElapsedGameTime.TotalSeconds; } break; } //checking if bullets is hit an enemy if (weapon != null && weapon.bullets != null) { for (int i = 0; i < weapon.bullets.Count; i++) { foreach (Enemy enemy in level.enemiesLevel) { if (weapon.bullets[i].BoundingBox.Intersects(enemy.BoundingBox)) { enemy.getHit(this.attackDamage); weapon.bullets.RemoveAt(i); break; } } } } } }
public void CharacterUpdate(GameTime gameTime, Level level) { UpdatePosition(gameTime, level); base.Update(gameTime, level); }
public override void Update(GameTime gameTime, Level level) { UpdatePosition(gameTime, level); if (SideScrollGame.main.IsNetwork) { NetOutgoingMessage outmessage = SideScrollGame.main.client.CreateMessage(); { outmessage.Write((byte)PacketTypes.MYPOSITION); outmessage.Write((byte)this.currentState); outmessage.Write((byte)this.lastState); outmessage.Write((int)this.health); outmessage.Write((float)this.position.X); outmessage.Write((float)this.position.Y); SideScrollGame.main.client.SendMessage(outmessage, NetDeliveryMethod.Unreliable); } } base.Update(gameTime, level); }
public override void Update(GameTime gameTime, Level level) { base.Update(gameTime, level); }
public virtual void Update(GameTime gameTime, Level level) { if (this.currentState != CharacterState.DEAD && this.targetPlayer != null) { FindPlayerYPosition(gameTime); float distanceX = targetPlayer.position.X - this.position.X; switch (currentState) { case CharacterState.ATTACK: AttackPlayer(gameTime); GetEnemyMovingToPlayer(distanceX); break; case CharacterState.IDLE: GetEnemyMovingToPlayer(distanceX); break; case CharacterState.MOVELEFT: this.lastState = currentState; this.position.X -= speed * (float)gameTime.ElapsedGameTime.TotalSeconds; if (distanceX + targetPlayer.SourceRect.Width - distancePlayerEnemyAttack >= 0 && distanceX < targetPlayer.SourceRect.Width) { currentState = CharacterState.IDLE; } break; case CharacterState.MOVERIGHT: this.lastState = currentState; this.position.X += speed * (float)gameTime.ElapsedGameTime.TotalSeconds; if (distanceX >= 0 && distanceX < targetPlayer.SourceRect.Width) { currentState = CharacterState.IDLE; } break; } } base.Update(gameTime, level); }
public void GetEnemyUpdate(GameTime gameTime, Level level) { base.Update(gameTime, level); }
public virtual void Update(GameTime gameTime, Level level) { if (this.health <= 0 && this.currentState != CharacterState.DEAD) { lastPosition = position; this.frame = 0; this.velocity = new Vector2(deadDistance, deadHeight); this.currentState = CharacterState.DEAD; if (SideScrollGame.main.IsNetwork && SideScrollGame.main.player.currentState == CharacterState.DEAD) { NetOutgoingMessage outMsg = SideScrollGame.main.client.CreateMessage(); outMsg.Write((byte)PacketTypes.SENDPLAYERDEAD); SideScrollGame.main.client.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered); } } if (this.currentState == CharacterState.DEAD) { this.position.Y -= this.velocity.Y * deadSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; this.velocity += SideScrollGame.GRAVITY * deadSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; if (this.lastState == CharacterState.MOVELEFT) { if (this.position.X + this.sourceRect.Width < level.width) this.position.X += this.velocity.X * deadSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; } else { if (this.position.X > 0) this.position.X -= this.velocity.X * deadSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; } if (this.lastPosition.Y < this.position.Y) { this.position.Y = this.lastPosition.Y; this.velocity.X = 0; this.Destroy(); } } if (childObjects != null) { foreach (GameObject child in childObjects) { child.Update(gameTime); } } base.Update(gameTime); }