SlimeJumper

This commit is contained in:
Kaktus200020 2023-08-18 13:11:49 +03:00
parent 8e71a3c732
commit ab0947ed69
3 changed files with 58 additions and 21 deletions

View file

@ -12,8 +12,12 @@ 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 = true; private bool isDown = true;
int leftBorder; int leftBorder;
int rightBorder; int rightBorder;
bool isAttaking = false; bool isAttaking = false;
@ -30,6 +34,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
rightBorder = 400; rightBorder = 400;
//acceleration = Vector2.Zero; //acceleration = Vector2.Zero;
delay = 30; delay = 30;
} }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "SlimeMoveLeftTop", "SlimeMoveLeftBottom", "SlimeMoveRightTop", protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> { "SlimeMoveLeftTop", "SlimeMoveLeftBottom", "SlimeMoveRightTop",
@ -40,7 +45,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{ {
} }
public void Jump() public void Jump(GameTime gameTime)
{ {
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;
@ -56,17 +61,19 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
if (delay <= 0) if (delay <= 0)
{ {
velocity = new Vector2(5, -3); velocity = new Vector2(5, -4);
acceleration.Y = 0; acceleration.Y = 0;
if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpLeftBottom") if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpLeftBottom")
{ {
GraphicsComponent.StartAnimation("SlimeJumpLeftBottom"); GraphicsComponent.StartAnimation("SlimeJumpLeftBottom");
} }
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 )
{ {
isJumping = false; isJumping = false;
isDown = false; isDown = false;
isAttaking = false;
} }
} }
@ -81,7 +88,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
if (delay <= 0) if (delay <= 0)
{ {
velocity = new Vector2(-5, -3); velocity = new Vector2(-5, -4);
acceleration.Y = 0; acceleration.Y = 0;
if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpRightBottom") if (GraphicsComponent.GetCurrentAnimation != "SlimeJumpRightBottom")
{ {
@ -92,6 +99,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{ {
isJumping = false; isJumping = false;
isDown = false; isDown = false;
isAttaking = false;
} }
} }
} }
@ -106,19 +114,22 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
if (delay <= 0) if (delay <= 0)
{ {
velocity = new Vector2(5, 3); velocity = new Vector2(5, 4);
acceleration.Y = 0; 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+1, (int)Pos.Y + Height, 46, 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;
isAttaking = false;
acceleration.Y = 10; acceleration.Y = 10;
Move(gameTime);
} }
} }
@ -132,24 +143,28 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
delay--; delay--;
if (delay <= 0) if (delay <= 0)
{ {
velocity = new Vector2(-5, 3); velocity = new Vector2(-5, 4);
acceleration.Y = 0; 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+1, (int)Pos.Y + Height, 46, 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;
isAttaking = false;
acceleration.Y = 10; acceleration.Y = 10;
Move(gameTime);
} }
} }
} }
} }
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
@ -246,25 +261,27 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
acceleration.Y = -acceleration.Y; acceleration.Y = -acceleration.Y;
} }
} }
Attack(); AppManager.Instance.DebugHUD.Set(name, isAttaking.ToString());
if(!isJumping)
if (!isJumping)
{ {
if (isDown) if (isDown)
{ {
Jump(); Jump(gameTime);
} }
else if(IsInAim()) else if(IsInAim())
{ {
Jump(); Jump(gameTime);
isAttaking = true;
} }
else else if(!isAttaking)
{ {
Move(gameTime); Move(gameTime);
} }
else { Jump(gameTime); }
} }
base.Update(gameTime); base.Update(gameTime);
} }
@ -283,6 +300,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X + Width, (int)Pos.Y + Height, 200, 500), false); getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X + Width, (int)Pos.Y + Height, 200, 500), false);
if (getCols.Count > 0) if (getCols.Count > 0)
{ {
return true; return true;
} }
} }
@ -291,10 +309,29 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 200, (int)Pos.Y + Height, 200, 500), false); getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 200, (int)Pos.Y + Height, 200, 500), false);
if (getCols.Count > 0) if (getCols.Count > 0)
{ {
return true; return true;
} }
} }
/*/else if (isGoRight && isDown)
{
getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X +Width, (int)Pos.Y -500, 200, 500), false);
if (getCols.Count > 0)
{
isAttaking = true;
return true;
}
}
else if (!isGoRight && isDown)
{
getCols = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - 200, (int)Pos.Y - 500, 200, 500), false);
if (getCols.Count > 0)
{
isAttaking = true;
return true;
}
}/*/
return false; return false;
} }

View file

@ -30,11 +30,11 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
isDownUp = true; isDownUp = true;
isDown = true; isDown = true;
physicsManager = AppManager.Instance.GameManager.physicsManager; physicsManager = AppManager.Instance.GameManager.physicsManager;
web = new SpiderWeb(Pos);
name = "Spider"; name = "Spider";
Width = 112; Width = 112;
Height = 24; Height = 24;
delay = 0; delay = 0;
web = new SpiderWeb(new Vector2(Pos.X-Width/2,Pos.Y));
webLength = 0; webLength = 0;
monster_speed = 3; monster_speed = 3;
acceleration = new Vector2(0, -50); acceleration = new Vector2(0, -50);

View file

@ -205,12 +205,12 @@ namespace DangerousD.GameCore
case GameState.Lobby: case GameState.Lobby:
break; break;
case GameState.Game: case GameState.Game:
<<<<<<< HEAD
GameManager.mapManager.LoadLevel("map"); GameManager.mapManager.LoadLevel("map");
=======
GameManager.mapManager.LoadLevel("lvl");
GameManager.FindBorders(); GameManager.FindBorders();
>>>>>>> main
break; break;
case GameState.Death: case GameState.Death:
break; break;