fixed physics
This commit is contained in:
parent
5a5a24dffd
commit
9e3c0f09ad
6 changed files with 41 additions and 24 deletions
|
@ -48,12 +48,12 @@ namespace DangerousD.GameCore
|
|||
GraphicsComponent.Update();
|
||||
}
|
||||
|
||||
//static Texture2D debugTexture;
|
||||
public static Texture2D debugTexture;
|
||||
public virtual void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
GraphicsComponent.DrawAnimation(Rectangle, spriteBatch);
|
||||
//debug
|
||||
//spriteBatch.Draw(debugTexture, Rectangle, Color.White);
|
||||
// spriteBatch.Draw(debugTexture, Rectangle, Color.White);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,14 +48,14 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
|||
{
|
||||
if (isGoRight)
|
||||
{
|
||||
GraphicsComponent.StopAnimation();
|
||||
GraphicsComponent.StartAnimation("ZombieRightAttack");
|
||||
if (GraphicsComponent.GetCurrentAnimation != "ZombieRightAttack")
|
||||
GraphicsComponent.StartAnimation("ZombieRightAttack");
|
||||
AppManager.Instance.GameManager.players[0].Death(name);
|
||||
}
|
||||
else if (!isGoRight)
|
||||
{
|
||||
GraphicsComponent.StopAnimation();
|
||||
GraphicsComponent.StartAnimation("ZombieLeftAttack");
|
||||
if (GraphicsComponent.GetCurrentAnimation != "ZombieLeftAttack")
|
||||
GraphicsComponent.StartAnimation("ZombieLeftAttack");
|
||||
AppManager.Instance.GameManager.players[0].Death(name);
|
||||
}
|
||||
}
|
||||
|
@ -72,14 +72,14 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
|
|||
{
|
||||
if (GraphicsComponent.GetCurrentAnimation != "ZombieMoveRight")
|
||||
GraphicsComponent.StartAnimation("ZombieMoveRight");
|
||||
velocity = new Vector2(monster_speed, 0);
|
||||
velocity.X = monster_speed;
|
||||
}
|
||||
|
||||
else if (!isGoRight)
|
||||
{
|
||||
if(GraphicsComponent.GetCurrentAnimation != "ZombieMoveLeft")
|
||||
GraphicsComponent.StartAnimation("ZombieMoveLeft");
|
||||
velocity = new Vector2(-monster_speed, 0);
|
||||
velocity.X = -monster_speed;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ public abstract class LivingEntity : Entity
|
|||
public Vector2 acceleration;
|
||||
public LivingEntity(Vector2 position) : base(position)
|
||||
{
|
||||
acceleration = new Vector2(0, 10);
|
||||
acceleration = new Vector2(0, 30);
|
||||
}
|
||||
public void SetPosition(Vector2 position) { targetPosition = position; _pos = position; } //TODO befrend targetpos and physics engine
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ namespace DangerousD.GameCore.Levels
|
|||
{
|
||||
new Player(new Vector2(0,0));
|
||||
|
||||
var Zombie = new Zombie(new Vector2(256, 128));
|
||||
var Frank = new Frank(new Vector2(384, 128));
|
||||
var Zombie = new Zombie(new Vector2(300, 64));
|
||||
var Frank = new Frank(new Vector2(100, 64));
|
||||
|
||||
new GrassBlock(new Vector2(0, 224));
|
||||
for (int i = 0; i < 50; i++)
|
||||
|
|
|
@ -53,7 +53,8 @@ namespace DangerousD.GameCore
|
|||
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||
MenuGUI.LoadContent();
|
||||
LoginGUI.LoadContent();
|
||||
//GameObject.te
|
||||
GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1);
|
||||
GameObject.debugTexture.SetData<Color>(new Color[] { new Color(1, 0,0,0.25f) });
|
||||
}
|
||||
|
||||
protected override void Update(GameTime gameTime)
|
||||
|
|
|
@ -40,26 +40,35 @@ namespace DangerousD.GameCore.Managers
|
|||
{
|
||||
var currentEntity = livingEntities[i];
|
||||
Rectangle oldRect = currentEntity.Rectangle;
|
||||
|
||||
bool isXNormalise = true;
|
||||
bool isYNormalise = true;
|
||||
|
||||
oldRect.Offset((int)currentEntity.velocity.X / 2, 0);
|
||||
for (int j = 0; j < mapObjects.Count; j++)
|
||||
{
|
||||
if (oldRect.Intersects(mapObjects[j].Rectangle))
|
||||
{
|
||||
isXNormalise = false;
|
||||
oldRect.Offset(-(int)currentEntity.velocity.X / 2, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
oldRect.Offset((int)currentEntity.velocity.X / 2, 0);
|
||||
for (int j = 0; j < mapObjects.Count; j++)
|
||||
if (isXNormalise)
|
||||
{
|
||||
if (oldRect.Intersects(mapObjects[j].Rectangle))
|
||||
oldRect.Offset((int)currentEntity.velocity.X / 2, 0);
|
||||
for (int j = 0; j < mapObjects.Count; j++)
|
||||
{
|
||||
oldRect.Offset(-(int)currentEntity.velocity.X / 2, 0);
|
||||
break;
|
||||
if (oldRect.Intersects(mapObjects[j].Rectangle))
|
||||
{
|
||||
isXNormalise = false;
|
||||
oldRect.Offset(-(int)currentEntity.velocity.X / 2, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isXNormalise)
|
||||
currentEntity.velocity.X = 0;
|
||||
|
||||
|
||||
oldRect.Offset(0, (int)currentEntity.velocity.Y/2);
|
||||
|
@ -67,19 +76,26 @@ namespace DangerousD.GameCore.Managers
|
|||
{
|
||||
if (oldRect.Intersects(mapObjects[j].Rectangle))
|
||||
{
|
||||
isYNormalise = false;
|
||||
oldRect.Offset(0, -(int)currentEntity.velocity.Y / 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
oldRect.Offset(0, (int)currentEntity.velocity.Y / 2);
|
||||
for (int j = 0; j < mapObjects.Count; j++)
|
||||
if (isYNormalise)
|
||||
{
|
||||
if (oldRect.Intersects(mapObjects[j].Rectangle))
|
||||
oldRect.Offset(0, (int)currentEntity.velocity.Y / 2);
|
||||
for (int j = 0; j < mapObjects.Count; j++)
|
||||
{
|
||||
oldRect.Offset(0, -(int)currentEntity.velocity.Y / 2);
|
||||
break;
|
||||
if (oldRect.Intersects(mapObjects[j].Rectangle))
|
||||
{
|
||||
isYNormalise = false;
|
||||
oldRect.Offset(0, -(int)currentEntity.velocity.Y / 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isYNormalise)
|
||||
currentEntity.velocity.Y = 0;
|
||||
currentEntity.SetPosition(new Vector2(oldRect.X, oldRect.Y));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue