Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- namespace GameTemplate
- {
- public class Entity : GameObject
- {
- protected float Speed = 100;
- protected Vector2 Velocity;
- protected float Health = 100;
- protected bool WallDown = false;
- protected bool WallUp = false;
- protected bool WallLeft = false;
- protected bool WallRight = false;
- public Entity(Vector2 StartPosition, Texture2D SetSprite) : base(StartPosition, SetSprite)
- {
- Velocity = Vector2.Zero;
- }
- public void HitWall(GameObject Other)//assuming evrything is a square
- {
- Vector2 WallDirection = Other.GetPosition() - Position;
- WallDirection.Normalize();
- if (Math.Abs(WallDirection.X) > Math.Abs(WallDirection.Y))//hit wall left or right
- {
- if(WallDirection.X < 0)//left
- {
- WallLeft = true;
- Position.X = Other.GetPosition().X + LevelManager.TileSize.X;//push back out of wall
- }
- else//right
- {
- WallRight = true;
- Position.X = Other.GetPosition().X - LevelManager.TileSize.X;//push back out of wall
- }
- }
- else//hit wall up or down
- {
- if (WallDirection.Y < 0)//Up
- {
- WallUp = true;
- Position.Y = Other.GetPosition().Y + LevelManager.TileSize.Y;//push back out of wall
- }
- else//Down
- {
- WallDown = true;
- Position.Y = Other.GetPosition().Y - LevelManager.TileSize.Y;//push back out of wall
- }
- }
- }
- public override void Update(float DT)
- {
- Position += Velocity * DT;
- base.Update(DT);
- //reset wall touch
- WallDown = false;
- WallUp = false;
- WallLeft = false;
- WallRight = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement