tiltedSlime

This commit is contained in:
Kaktus200020 2023-08-18 03:03:11 +03:00
parent a1adb49918
commit 731e69d92e
3 changed files with 107 additions and 21 deletions

View file

@ -13,7 +13,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public class Slime : CoreEnemy public class Slime : CoreEnemy
{ {
private bool isGoRight = true; private bool isGoRight = true;
private bool isDown = false; private bool isDown = true;
int leftBorder; int leftBorder;
int rightBorder; int rightBorder;
bool isAttaking = false; bool isAttaking = false;
@ -38,13 +38,14 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Attack() public override void Attack()
{ {
} }
public void Jump() public void Jump()
{ {
var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle(0, 0, 100, 100)); var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle(0, 0, 100, 100));
velocity.X = 0; velocity.X = 0;
Height = 32; Height = 32;
if (isGoRight && isDown) if (isGoRight && isDown)
{ {
if (GraphicsComponent.GetCurrentAnimation != "SlimeReadyJumpLeftBottom") if (GraphicsComponent.GetCurrentAnimation != "SlimeReadyJumpLeftBottom")
@ -54,8 +55,9 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
delay--; delay--;
if (delay <= 0) if (delay <= 0)
{ {
isJumping = true;
velocity = new Vector2(5, -3); velocity = new Vector2(5, -3);
acceleration.Y = 0;
if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpLeftBottom") if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpLeftBottom")
{ {
GraphicsComponent.StartAnimation("SlimeJumpLeftBottom"); GraphicsComponent.StartAnimation("SlimeJumpLeftBottom");
@ -71,17 +73,19 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
else if (!isGoRight && isDown) else if (!isGoRight && isDown)
{ {
if (GraphicsComponent.GetCurrentAnimation != "SlimeReadyJumpRightTop") if (GraphicsComponent.GetCurrentAnimation != "SlimeReadyJumpRightBottom")
{ {
GraphicsComponent.StartAnimation("SlimeReadyJumpRightTop"); GraphicsComponent.StartAnimation("SlimeReadyJumpRightBottom");
} }
delay--; delay--;
if (delay <= 0) if (delay <= 0)
{ {
velocity = new Vector2(-5, -3); velocity = new Vector2(-5, -3);
if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpRightTop") acceleration.Y = 0;
if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpRightBottom")
{ {
GraphicsComponent.StartAnimation("SlimeJumpRightTop"); GraphicsComponent.StartAnimation("SlimeJumpRightBottom");
} }
getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y - 5, 48, 5)); getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y - 5, 48, 5));
if (getCols.Count > 0) if (getCols.Count > 0)
@ -101,17 +105,20 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
delay--; delay--;
if (delay <= 0) if (delay <= 0)
{ {
isJumping = true;
velocity = new Vector2(5, 3); velocity = new Vector2(5, 3);
acceleration.Y = 0;
if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpLeftTop") if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpLeftTop")
{ {
GraphicsComponent.StartAnimation("SlimeJumpLeftTop"); GraphicsComponent.StartAnimation("SlimeJumpLeftTop");
} }
getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height, 48, 5)); getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X+1, (int)Pos.Y + Height, 46, 5));
if (getCols.Count > 0) if (getCols.Count > 0)
{ {
isJumping = false; isJumping = false;
isDown = true; isDown = true;
acceleration.Y = 10;
} }
} }
@ -126,15 +133,18 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
if (delay <= 0) if (delay <= 0)
{ {
velocity = new Vector2(-5, 3); velocity = new Vector2(-5, 3);
acceleration.Y = 0;
if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpRightTop") if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpRightTop")
{ {
GraphicsComponent.StartAnimation("SlimeJumpRightTop"); GraphicsComponent.StartAnimation("SlimeJumpRightTop");
} }
getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height, 48, 5)); getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X+1, (int)Pos.Y + Height, 46, 5));
if (getCols.Count > 0) if (getCols.Count > 0)
{ {
isJumping = false; isJumping = false;
isDown = true; isDown = true;
acceleration.Y = 10;
} }
} }
@ -144,8 +154,8 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
spriteBatch.Draw(debugTexture, new Rectangle((int)Pos.X, (int)Pos.Y - 5, 48, 5), Color.White);
spriteBatch.Draw(debugTexture, new Rectangle((int)Pos.X, (int)Pos.Y + Height, 48, 5), Color.White);
base.Draw(spriteBatch); base.Draw(spriteBatch);
} }
public override void Death() public override void Death()
@ -197,15 +207,24 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
velocity.X = -monster_speed; velocity.X = -monster_speed;
} }
var getCols= AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 50, 2)); ;
if (Pos.X >= rightBorder) if (isGoRight)
{ {
isGoRight = false; getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height / 2 - 2, 51, 2));
} }
else
else if (Pos.X <= leftBorder)
{ {
isGoRight = true; getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X-3, (int)Pos.Y + Height / 2 - 2, 51, 2));
}
foreach(var item in getCols)
{
if(item is MapObject)
{
isGoRight = !isGoRight;
break;
}
} }
} }
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
@ -227,8 +246,25 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
acceleration.Y = -acceleration.Y; acceleration.Y = -acceleration.Y;
} }
} }
//if (!isAttaking){ Move(gameTime); } Attack();
if (!isJumping)
{
if (isDown)
{
Jump();
}
else if(IsInAim())
{
Jump();
}
else
{
Move(gameTime);
}
}
base.Update(gameTime); base.Update(gameTime);
} }
@ -237,10 +273,45 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{ {
} }
public bool IsInAim()
{
var getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)Pos.Y + Height, 48, 5));
if (isGoRight && !isDown)
{
getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X + Width, (int)Pos.Y + Height, 200, 500), false);
if (getCols.Count > 0)
{
return true;
}
}
else if (!isGoRight && !isDown)
{
getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 200, (int)Pos.Y + Height, 200, 500), false);
if (getCols.Count > 0)
{
return true;
}
}
return false;
}
public override void Attack(GameTime gameTime) public override void Attack(GameTime gameTime)
{ {
} }
public override void OnCollision(GameObject gameObject)
{
if (gameObject is Player)
{
if (AppManager.Instance.GameManager.players[0].IsAlive)
{
AppManager.Instance.GameManager.players[0].Death(name);
}
}
base.OnCollision(gameObject);
}
} }
} }

View file

@ -202,7 +202,7 @@ namespace DangerousD.GameCore
case GameState.Lobby: case GameState.Lobby:
break; break;
case GameState.Game: case GameState.Game:
GameManager.mapManager.LoadLevel("lvl"); GameManager.mapManager.LoadLevel("map");
break; break;
case GameState.Death: case GameState.Death:
break; break;

View file

@ -234,6 +234,21 @@ namespace DangerousD.GameCore.Managers
} }
return intersected; return intersected;
} }
public List<GameObject> CheckRectangle(Rectangle rectangle, bool player)
{
var gameObjects = AppManager.Instance.GameManager.GetPlayer1;
List<GameObject> intersected = new List<GameObject>();
if (gameObjects.Rectangle.Intersects(rectangle))
{
intersected.Add(gameObjects);
}
return intersected;
}
public List<GameObject> CheckRectangle(Rectangle rectangle) public List<GameObject> CheckRectangle(Rectangle rectangle)
{ {
var gameObjects = AppManager.Instance.GameManager.mapObjects; var gameObjects = AppManager.Instance.GameManager.mapObjects;