AddedTeleportingDoors

This commit is contained in:
Timofey06 2023-08-18 15:38:04 +03:00
commit c4de6406c3
12 changed files with 325 additions and 26 deletions

View file

@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="left-up" width="30" height="20" tilewidth="16" tileheight="16" infinite="1" nextlayerid="7" nextobjectid="5">
<tileset firstgid="1" source="map.tsx"/>
<layer id="2" name="Platform" class="StopTile" width="30" height="20">
<data encoding="csv">
<chunk x="-32" y="0" width="16" height="16">
410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
410,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</chunk>
<chunk x="-16" y="0" width="16" height="16">
410,410,410,410,410,410,410,410,410,410,410,410,410,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,410,0,0
</chunk>
<chunk x="-32" y="16" width="16" height="16">
410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,410,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</chunk>
<chunk x="-16" y="16" width="16" height="16">
410,410,410,410,410,410,410,410,410,410,410,410,410,410,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</chunk>
</data>
</layer>
<layer id="3" name="BackGround" class="Tile" width="30" height="20">
<data encoding="csv">
<chunk x="-32" y="0" width="16" height="16">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,376,375,369,370,388,389,726,390,369,370,376,389,376,388,726,
0,376,389,369,370,390,726,388,388,369,370,390,726,388,389,389,
0,388,726,369,370,390,377,375,377,369,370,431,389,389,431,431,
0,389,431,369,370,377,377,389,388,369,370,431,389,375,375,431,
0,377,377,369,370,390,376,389,431,369,370,375,375,726,388,390,
0,388,431,369,370,388,390,376,726,369,370,375,377,376,388,377,
0,388,375,369,370,376,375,377,388,369,370,376,375,389,388,431,
0,390,726,369,370,377,431,431,388,369,370,389,390,390,376,377,
0,377,376,369,370,389,377,431,376,369,370,389,431,726,431,388,
0,377,431,369,370,375,390,390,377,369,370,375,377,389,388,376,
0,390,390,369,370,431,376,389,390,369,370,390,431,376,389,390,
0,431,377,369,370,376,390,388,388,369,370,377,375,390,389,377,
0,390,726,369,370,375,377,726,390,369,370,389,376,388,388,375,
0,390,389,382,383,388,377,388,390,382,383,431,726,390,388,431,
0,389,377,395,396,389,431,377,431,395,396,375,388,726,376,389
</chunk>
<chunk x="-16" y="0" width="16" height="16">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
389,388,375,369,370,388,377,389,389,369,370,390,375,0,0,0,
390,388,726,369,370,375,726,376,726,369,370,388,375,0,0,0,
388,389,431,369,370,726,377,726,431,369,370,377,375,0,0,0,
388,376,431,369,370,377,375,726,726,369,370,431,376,0,0,0,
376,389,388,369,370,377,390,431,389,369,370,376,431,0,0,0,
389,388,389,369,370,376,726,390,377,369,370,389,377,0,0,0,
431,377,389,369,370,431,726,726,389,369,370,431,390,0,0,0,
390,389,377,369,370,390,390,376,431,369,370,390,376,0,0,0,
388,388,377,369,370,388,431,390,388,369,370,389,377,0,0,0,
388,389,390,369,370,726,377,377,388,369,370,390,390,0,0,0,
388,376,390,369,370,377,377,389,726,369,370,375,726,0,0,0,
431,726,390,369,370,375,431,377,726,369,370,389,389,0,0,0,
390,388,726,369,370,389,375,390,388,369,370,377,726,0,0,0,
375,375,375,382,383,376,390,726,388,382,383,431,726,0,0,0,
389,389,390,395,396,390,390,726,390,395,396,431,390,0,0,0
</chunk>
</data>
</layer>
<objectgroup id="5" name="SilasMaster" class="LivingEntities.Monsters.SilasMaster">
<object id="1" x="-279.333" y="121.333">
<point/>
</object>
</objectgroup>
<objectgroup id="6" name="player" class="LivingEntities.Player">
<object id="3" x="-329.333" y="111.333">
<point/>
</object>
</objectgroup>
</map>

View file

@ -0,0 +1 @@
{"id":"DeathFromSilasHand","textureName":"deathAnimation","startSpriteRectangle":{"X":1,"Y":295,"Width":48,"Height":48},"frameSecond":[{"Item1":0,"Item2":10}],"textureFrameInterval":1,"framesCount":5,"isCycle":false,"offset":"0, 0"}

View file

@ -37,6 +37,8 @@ namespace DangerousD.GameCore.GameObjects.Entities
public override void OnCollision(GameObject gameObject) public override void OnCollision(GameObject gameObject)
{ {
base.OnCollision(gameObject); base.OnCollision(gameObject);
if (this is not TeleportingDoor)
{
if (gameObject is Player) if (gameObject is Player)
{ {
Player player = (Player)gameObject; Player player = (Player)gameObject;
@ -47,5 +49,7 @@ namespace DangerousD.GameCore.GameObjects.Entities
} }
} }
} }
}
} }
} }

View file

@ -1,4 +1,5 @@
using DangerousD.GameCore.Graphics; using DangerousD.GameCore.GameObjects.LivingEntities;
using DangerousD.GameCore.Graphics;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using System; using System;
@ -14,11 +15,14 @@ namespace DangerousD.GameCore.GameObjects.Entities
{ {
private Vector2 v; private Vector2 v;
public string name;
public SilasBall(Vector2 position) : base(position) public SilasBall(Vector2 position) : base(position)
{ {
Height = 24; Height = 24;
Width = 24; Width = 24;
acceleration = Vector2.Zero; acceleration = Vector2.Zero;
name = "SilasHand";
} }
public SilasBall(Vector2 position, Vector2 velosity) : base(position) public SilasBall(Vector2 position, Vector2 velosity) : base(position)
@ -28,6 +32,7 @@ namespace DangerousD.GameCore.GameObjects.Entities
acceleration = Vector2.Zero; acceleration = Vector2.Zero;
velocity = velosity; velocity = velosity;
v = velosity; v = velosity;
name = "SilasHand";
} }
@ -48,5 +53,21 @@ namespace DangerousD.GameCore.GameObjects.Entities
} }
public void Attack()
{
AppManager.Instance.GameManager.GetPlayer1.Death(name);
}
public override void OnCollision(GameObject gameObject)
{
base.OnCollision(gameObject);
if (gameObject is Player)
{
if (AppManager.Instance.GameManager.players[0].IsAlive)
{
Attack();
}
}
}
} }
} }

View file

@ -0,0 +1,54 @@
using DangerousD.GameCore.GameObjects.LivingEntities;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DangerousD.GameCore.GameObjects.Entities
{
internal class TeleportingDoor : Door
{
public Vector2 Target;
public bool IsVisible = true;
public Action action;
public TeleportingDoor(Vector2 position, Vector2 size, Rectangle sourceRectangle, Vector2 target, Action action) : base(position, size, sourceRectangle)
{
Target = target;
this.action = action;
}
public override void OnCollision(GameObject gameObject)
{
if (IsVisible)
{
if (gameObject is Player)
{
Player player = (Player)gameObject;
if (player.isUping)
{
IsVisible = false;
}
}
}
else
{
if (gameObject is Player)
{
Player player = (Player)gameObject;
if (player.isUping)
{
player.SetPosition(Target);
if (action!=null)
{
action();
}
}
}
}
}
}
}

View file

@ -63,9 +63,7 @@ namespace DangerousD.GameCore
if (AppManager.Instance.InputManager.CollisionsCheat) if (AppManager.Instance.InputManager.CollisionsCheat)
{ {
spriteBatch.Draw(debugTexture, spriteBatch.Draw(debugTexture,
new Rectangle(Rectangle.X - GraphicsComponent.CameraPosition.X, new Rectangle((Rectangle.X - GraphicsComponent.CameraPosition.X) * GraphicsComponent.scaling, (Rectangle.Y - GraphicsComponent.CameraPosition.Y) * GraphicsComponent.scaling, Rectangle.Width * GraphicsComponent.scaling, Rectangle.Height * GraphicsComponent.scaling),Color.White);
Rectangle.Y - GraphicsComponent.CameraPosition.Y, Rectangle.Width, Rectangle.Height),
Color.White);
} }
} }

View file

@ -19,7 +19,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
Width = 16; Width = 16;
Height = 16; Height = 16;
monster_health = 2; monster_health = 2;
monster_speed = 2; monster_speed = 1;
acceleration = Vector2.Zero; acceleration = Vector2.Zero;
} }
@ -28,7 +28,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Attack() public override void Attack()
{ {
AppManager.Instance.GameManager.GetPlayer1.Death(name);
} }
public override void Attack(GameTime gameTime) public override void Attack(GameTime gameTime)
@ -38,7 +38,13 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Death() public override void Death()
{ {
throw new NotImplementedException(); for (int i = 0; i < 3; i++)
{
Particle particle = new Particle(Pos);
}
AppManager.Instance.GameManager.Remove(this);
} }
public override void Move(GameTime gameTime) public override void Move(GameTime gameTime)
@ -71,12 +77,30 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
{ {
base.Update(gameTime); base.Update(gameTime);
Move(gameTime); Move(gameTime);
if ((Pos.X + 20 <= AppManager.Instance.GameManager.GetPlayer1.Pos.X || Pos.X - 20 >= AppManager.Instance.GameManager.GetPlayer1.Pos.X)&&(Pos.Y + 20 <= AppManager.Instance.GameManager.GetPlayer1.Pos.Y || Pos.Y - 20 >= AppManager.Instance.GameManager.GetPlayer1.Pos.Y))
{
AppManager.Instance.GameManager.GetPlayer1.Death(name);
}
GraphicsComponent.Update(); GraphicsComponent.Update();
} }
public void TakeDamage()
{
monster_health--;
GraphicsComponent.StartAnimation("SilasHandMove");
Particle particle = new Particle(Pos);
if (monster_health <= 0)
{
Death();
}
}
public override void OnCollision(GameObject gameObject)
{
if (gameObject is Player)
{
if (AppManager.Instance.GameManager.players[0].IsAlive)
{
Attack();
}
}
base.OnCollision(gameObject);
}
} }
} }

View file

@ -16,6 +16,7 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
private int attackTime = 60; private int attackTime = 60;
private int moveTime = 360; private int moveTime = 360;
private int currentTime = 0; private int currentTime = 0;
private int interval = 0;
int leftBorder; int leftBorder;
int rightBorder; int rightBorder;
List<SilasHands> hands = new List<SilasHands>(); List<SilasHands> hands = new List<SilasHands>();
@ -119,9 +120,18 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities.Monsters
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
{ {
base.Update(gameTime); base.Update(gameTime);
for (int i = 0; i < hands.Count; i++)
{
if (!AppManager.Instance.GameManager.GetAllGameObjects.Contains(hands[i]))
{
hands.RemoveAt(i);
}
}
if (hands.Count<2) if (hands.Count<2)
{ {
hands.Add(new SilasHands(new Vector2(Pos.X + 60, Pos.Y + 120))); hands.Add(new SilasHands(new Vector2(Pos.X + 30, Pos.Y + 30)));
} }
if (GraphicsComponent.CurrentAnimation.Id == "SilasMove") if (GraphicsComponent.CurrentAnimation.Id == "SilasMove")
{ {

View file

@ -18,7 +18,7 @@ namespace DangerousD.GameCore.GameObjects.PlayerDeath
PlayDeath(DeathType); PlayDeath(DeathType);
} }
protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> {"DeathFromZombie"}, protected override GraphicsComponent GraphicsComponent { get; } = new(new List<string> {"DeathFromZombie", "DeathFromSilasHand" },
"DeathFromZombie"); "DeathFromZombie");
public GraphicsComponent Gr => GraphicsComponent; public GraphicsComponent Gr => GraphicsComponent;
@ -29,6 +29,10 @@ namespace DangerousD.GameCore.GameObjects.PlayerDeath
{ {
GraphicsComponent.StartAnimation("DeathFromZombie"); GraphicsComponent.StartAnimation("DeathFromZombie");
} }
if (GraphicsComponent.GetCurrentAnimation != "DeathFromSilasHand")
{
GraphicsComponent.StartAnimation("DeathFromSilasHand");
}
} }
} }

View file

@ -87,12 +87,29 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
{ {
base.OnCollision(gameObject); base.OnCollision(gameObject);
} }
public Rectangle GetShootRectangle(bool isRight)
{
if (isRight)
return new Rectangle((int)Pos.X, (int)(Pos.Y) + 10, shootLength + Width, Height / 2);
else
return new Rectangle((int)Pos.X-shootLength, (int)(Pos.Y) + 10, shootLength, Height / 2);
}
public override void Draw(SpriteBatch spriteBatch) public override void Draw(SpriteBatch spriteBatch)
{ {
if (isVisible) if (isVisible)
{ {
base.Draw(spriteBatch); base.Draw(spriteBatch);
} }
if (AppManager.Instance.InputManager.CollisionsCheat)
{
Rectangle attackRect = GetShootRectangle(isRight);
spriteBatch.Draw(debugTexture,
new Rectangle((attackRect.X - GraphicsComponent.CameraPosition.X) * GraphicsComponent.scaling,
(attackRect.Y - GraphicsComponent.CameraPosition.Y) * GraphicsComponent.scaling,
attackRect.Width * GraphicsComponent.scaling,
attackRect.Height * GraphicsComponent.scaling), Color.White);
}
} }
public void Death(string monsterName) public void Death(string monsterName)
{ {
@ -123,6 +140,28 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
} }
}; };
} }
else if (monsterName == "SilasHand")
{
AnimationRectangle deathRectangle = new AnimationRectangle(Pos, "DeathFrom" + monsterName);
deathRectangle.Gr.actionOfAnimationEnd += (a) =>
{
if (a == "DeathFrom" + monsterName)
{
AppManager.Instance.ChangeGameState(GameState.Death);
}
};
}
else if (monsterName == "SilasBall")
{
AnimationRectangle deathRectangle = new AnimationRectangle(Pos, "DeathFrom" + monsterName);
deathRectangle.Gr.actionOfAnimationEnd += (a) =>
{
if (a == "DeathFrom" + monsterName)
{
AppManager.Instance.ChangeGameState(GameState.Death);
}
};
}
isAlive = false; isAlive = false;
} }
public void Jump() public void Jump()
@ -146,18 +185,25 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
if (isRight) if (isRight)
{ {
StartCicycleAnimation("playerShootRight"); StartCicycleAnimation("playerShootRight");
var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X, (int)(Pos.Y - 10f), shootLength + 24, 10), typeof(Zombie)).OrderBy(x => (x.Pos - Pos).LengthSquared()); var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(GetShootRectangle(isRight), typeof(Zombie)).OrderBy(x => (x.Pos - Pos).LengthSquared());
if (targets.Count() > 0) if (targets.Count() > 0)
{ {
Zombie targetZombie = (Zombie)targets.First(); Zombie targetZombie = (Zombie)targets.First();
targetZombie.TakeDamage(); targetZombie.TakeDamage();
}
targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(GetShootRectangle(isRight), typeof(SilasHands)).OrderBy(x => (x.Pos - Pos).LengthSquared());
if (targets.Count() > 0)
{
SilasHands targetHand = (SilasHands)targets.First();
targetHand.TakeDamage();
} }
SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X + 30, Pos.Y + 7)); SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X + 30, Pos.Y + 7));
} }
else else
{ {
StartCicycleAnimation("playerShootLeft"); StartCicycleAnimation("playerShootLeft");
var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(new Rectangle((int)Pos.X - shootLength, (int)(Pos.Y - 10f), shootLength, 10), typeof(Zombie)); var targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(GetShootRectangle(isRight), typeof(Zombie));
if (targets != null) if (targets != null)
{ {
foreach (var target in targets) foreach (var target in targets)
@ -166,6 +212,12 @@ namespace DangerousD.GameCore.GameObjects.LivingEntities
targetZombie.TakeDamage(); targetZombie.TakeDamage();
} }
} }
targets = AppManager.Instance.GameManager.physicsManager.CheckRectangle(GetShootRectangle(isRight), typeof(SilasHands));
if (targets.Count() > 0)
{
SilasHands targetHand = (SilasHands)targets.First();
targetHand.TakeDamage();
}
SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X - 12, Pos.Y + 7)); SmokeAfterShoot smokeAfterShoot = new SmokeAfterShoot(new Vector2(Pos.X - 12, Pos.Y + 7));
} }
} }

View file

@ -6,6 +6,7 @@ using Microsoft.Xna.Framework.Graphics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
namespace DangerousD.GameCore.Graphics namespace DangerousD.GameCore.Graphics
@ -18,7 +19,7 @@ namespace DangerousD.GameCore.Graphics
private List<Texture2D> textures; private List<Texture2D> textures;
private List<string> texturesNames; private List<string> texturesNames;
private AnimationContainer currentAnimation; private AnimationContainer currentAnimation;
static private int scaling = 4; static public int scaling = 4;
public int parentId; public int parentId;
public AnimationContainer CurrentAnimation public AnimationContainer CurrentAnimation
{ {

View file

@ -204,7 +204,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("LastLvl");
GameManager.FindBorders(); GameManager.FindBorders();
break; break;
case GameState.Death: case GameState.Death: