hotfixes
camera scaling
This commit is contained in:
parent
57f130e6f1
commit
ec275c7584
9 changed files with 95 additions and 54 deletions
|
@ -93,6 +93,7 @@ namespace ZoFo.GameCore
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
Player myPlayer;
|
||||||
List<MapObject> mapObjects = new List<MapObject>();
|
List<MapObject> mapObjects = new List<MapObject>();
|
||||||
List<GameObject> gameObjects = new List<GameObject>();
|
List<GameObject> gameObjects = new List<GameObject>();
|
||||||
List<Player> players = new List<Player>();
|
List<Player> players = new List<Player>();
|
||||||
|
@ -111,6 +112,8 @@ namespace ZoFo.GameCore
|
||||||
}
|
}
|
||||||
|
|
||||||
networkManager.SendData();//set to ticks
|
networkManager.SendData();//set to ticks
|
||||||
|
if (myPlayer!=null)
|
||||||
|
GraphicsComponent.CameraPosition = (myPlayer.position + myPlayer.graphicsComponent.ObjectDrawRectangle.Size.ToVector2()/2 - AppManager.Instance.CurentScreenResolution.ToVector2()/(2*GraphicsComponent.scaling)).ToPoint();
|
||||||
}
|
}
|
||||||
internal void Draw(SpriteBatch spriteBatch)
|
internal void Draw(SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
|
@ -140,16 +143,17 @@ namespace ZoFo.GameCore
|
||||||
(update as UpdateTileCreated).tileSetName
|
(update as UpdateTileCreated).tileSetName
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
//else if (update is UpdateStopObjectCreated)
|
else if (update is UpdateStopObjectCreated)
|
||||||
//{
|
{
|
||||||
// stopObjects.Add(
|
stopObjects.Add(
|
||||||
// new StopObject(
|
new StopObject(
|
||||||
// (update as UpdateStopObjectCreated).Position,
|
(update as UpdateStopObjectCreated).Position,
|
||||||
// (update as UpdateStopObjectCreated).Size.ToVector2(),
|
(update as UpdateStopObjectCreated).Size.GetPoint().ToVector2(),
|
||||||
// (update as UpdateStopObjectCreated).sourceRectangle,
|
(update as UpdateStopObjectCreated).sourceRectangle.GetRectangle(),
|
||||||
// (update as UpdateStopObjectCreated).tileSetName
|
(update as UpdateStopObjectCreated).tileSetName,
|
||||||
// ));
|
(update as UpdateStopObjectCreated).collisions.Select(x =>x.GetRectangle()).ToArray()
|
||||||
//}
|
));
|
||||||
|
}
|
||||||
else if (update is UpdateGameObjectCreated)
|
else if (update is UpdateGameObjectCreated)
|
||||||
{
|
{
|
||||||
GameObject created_gameObject;
|
GameObject created_gameObject;
|
||||||
|
@ -159,6 +163,7 @@ namespace ZoFo.GameCore
|
||||||
{
|
{
|
||||||
created_gameObject = new Player((update as UpdateGameObjectCreated).position);
|
created_gameObject = new Player((update as UpdateGameObjectCreated).position);
|
||||||
players.Add(created_gameObject as Player);
|
players.Add(created_gameObject as Player);
|
||||||
|
myPlayer = players[0];
|
||||||
gameObjects.Add(created_gameObject);
|
gameObjects.Add(created_gameObject);
|
||||||
}
|
}
|
||||||
if ((update as UpdateGameObjectCreated).GameObjectType == "Ammo")
|
if ((update as UpdateGameObjectCreated).GameObjectType == "Ammo")
|
||||||
|
|
|
@ -211,8 +211,8 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
|
||||||
{
|
{
|
||||||
public static Rectangle SetOrigin(this Rectangle rectangle, Vector2 origin)
|
public static Rectangle SetOrigin(this Rectangle rectangle, Vector2 origin)
|
||||||
{
|
{
|
||||||
rectangle.X = (int)origin.X;
|
rectangle.X += (int)origin.X;
|
||||||
rectangle.Y = (int)origin.Y;
|
rectangle.Y += (int)origin.Y;
|
||||||
return rectangle;
|
return rectangle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,31 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
#endregion // Cheats
|
#endregion // Cheats
|
||||||
|
|
||||||
#region Обработка состояния объекта. Задает значение полю scopeState.
|
#region Обработка состояния объекта. Задает значение полю scopeState.
|
||||||
if (keyBoardState.IsKeyDown(Keys.Up) || keyBoardState.IsKeyDown(Keys.W))
|
if(keyBoardState.IsKeyDown(Keys.Right) && keyBoardState.IsKeyDown(Keys.Up) ||
|
||||||
|
keyBoardState.IsKeyDown(Keys.D) && keyBoardState.IsKeyDown(Keys.W))
|
||||||
|
{
|
||||||
|
currentScopeState = ScopeState.StraightRight;
|
||||||
|
InputMovementDirection = new Vector2(1, -1);
|
||||||
|
}
|
||||||
|
else if(keyBoardState.IsKeyDown(Keys.Left) && keyBoardState.IsKeyDown(Keys.Up) ||
|
||||||
|
keyBoardState.IsKeyDown(Keys.A) && keyBoardState.IsKeyDown(Keys.W))
|
||||||
|
{
|
||||||
|
currentScopeState = ScopeState.StraightLeft;
|
||||||
|
InputMovementDirection = new Vector2(-1, -1);
|
||||||
|
}
|
||||||
|
else if(keyBoardState.IsKeyDown(Keys.Right) && keyBoardState.IsKeyDown(Keys.Down) ||
|
||||||
|
keyBoardState.IsKeyDown(Keys.D) && keyBoardState.IsKeyDown(Keys.S))
|
||||||
|
{
|
||||||
|
currentScopeState = ScopeState.BackRight;
|
||||||
|
InputMovementDirection = new Vector2(1, 1);
|
||||||
|
}
|
||||||
|
else if(keyBoardState.IsKeyDown(Keys.Left) && keyBoardState.IsKeyDown(Keys.Down) ||
|
||||||
|
keyBoardState.IsKeyDown(Keys.A) && keyBoardState.IsKeyDown(Keys.S))
|
||||||
|
{
|
||||||
|
currentScopeState = ScopeState.BackLeft;
|
||||||
|
InputMovementDirection = new Vector2(-1, 1);
|
||||||
|
}
|
||||||
|
else if (keyBoardState.IsKeyDown(Keys.Up) || keyBoardState.IsKeyDown(Keys.W))
|
||||||
{
|
{
|
||||||
currentScopeState = ScopeState.Straight;
|
currentScopeState = ScopeState.Straight;
|
||||||
InputMovementDirection = new Vector2(0, -1);
|
InputMovementDirection = new Vector2(0, -1);
|
||||||
|
@ -189,30 +213,6 @@ namespace ZoFo.GameCore.GameManagers
|
||||||
currentScopeState = ScopeState.Right;
|
currentScopeState = ScopeState.Right;
|
||||||
InputMovementDirection = new Vector2(1, 0);
|
InputMovementDirection = new Vector2(1, 0);
|
||||||
}
|
}
|
||||||
else if(keyBoardState.IsKeyDown(Keys.Right) && keyBoardState.IsKeyDown(Keys.Up) ||
|
|
||||||
keyBoardState.IsKeyDown(Keys.D) && keyBoardState.IsKeyDown(Keys.W))
|
|
||||||
{
|
|
||||||
currentScopeState = ScopeState.StraightRight;
|
|
||||||
InputMovementDirection = new Vector2(1, 1);
|
|
||||||
}
|
|
||||||
else if(keyBoardState.IsKeyDown(Keys.Left) && keyBoardState.IsKeyDown(Keys.Up) ||
|
|
||||||
keyBoardState.IsKeyDown(Keys.A) && keyBoardState.IsKeyDown(Keys.W))
|
|
||||||
{
|
|
||||||
currentScopeState = ScopeState.StraightLeft;
|
|
||||||
InputMovementDirection = new Vector2(-1, 1);
|
|
||||||
}
|
|
||||||
else if(keyBoardState.IsKeyDown(Keys.Right) && keyBoardState.IsKeyDown(Keys.Down) ||
|
|
||||||
keyBoardState.IsKeyDown(Keys.D) && keyBoardState.IsKeyDown(Keys.S))
|
|
||||||
{
|
|
||||||
currentScopeState = ScopeState.BackRight;
|
|
||||||
InputMovementDirection = new Vector2(1, -1);
|
|
||||||
}
|
|
||||||
else if(keyBoardState.IsKeyDown(Keys.Left) && keyBoardState.IsKeyDown(Keys.Down) ||
|
|
||||||
keyBoardState.IsKeyDown(Keys.A) && keyBoardState.IsKeyDown(Keys.S))
|
|
||||||
{
|
|
||||||
currentScopeState = ScopeState.BackLeft;
|
|
||||||
InputMovementDirection = new Vector2(-1, -1);
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Обработка нажатия выстрела. Вызывает событие ShootEvent
|
#region Обработка нажатия выстрела. Вызывает событие ShootEvent
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ZoFo.GameCore.GameManagers.NetworkManager.SerializableDTO;
|
||||||
|
|
||||||
|
namespace ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient
|
||||||
|
{
|
||||||
|
internal class UpdateStopObjectCreated : UpdateData
|
||||||
|
{
|
||||||
|
public UpdateStopObjectCreated() { UpdateType = "UpdateStopObjectCreated"; }
|
||||||
|
public Texture2D TextureTile { get; set; }
|
||||||
|
public Vector2 Position { get; set; }
|
||||||
|
public SerializablePoint Size { get; set; }
|
||||||
|
public SerializableRectangle sourceRectangle { get; set; }
|
||||||
|
public string tileSetName { get; set; }
|
||||||
|
public SerializableRectangle[] collisions { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,13 +11,13 @@ namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies
|
||||||
{
|
{
|
||||||
class Zombie : Enemy
|
class Zombie : Enemy
|
||||||
{
|
{
|
||||||
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "zombie_damaged","zombie_walk","zombie_idle","zombie_attack","zombie_death" }, "zombie_walk");
|
public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List<string> { "zombie_damaged", "zombie_walk", "zombie_idle", "zombie_attack", "zombie_death" }, "zombie_walk");
|
||||||
public Zombie(Vector2 position) : base(position)
|
public Zombie(Vector2 position) : base(position)
|
||||||
{
|
{
|
||||||
health = 5;
|
health = 5;
|
||||||
speed =2;
|
speed = 2;
|
||||||
collisionComponent.stopRectangle = new Rectangle(0, 0, 52, 100);
|
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30);
|
||||||
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 100, 100);
|
collisionComponent.stopRectangle = new Rectangle(0, 10, 30, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
|
@ -25,7 +25,7 @@ namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies
|
||||||
Vector2 duration = Vector2.Normalize(
|
Vector2 duration = Vector2.Normalize(
|
||||||
AppManager.Instance.server.players[0].position - position
|
AppManager.Instance.server.players[0].position - position
|
||||||
);
|
);
|
||||||
velocity+=new Vector2(duration.X * speed, duration.Y*speed);
|
velocity += new Vector2(duration.X * speed, duration.Y * speed);
|
||||||
if (Random.Shared.NextDouble() > 0.9)
|
if (Random.Shared.NextDouble() > 0.9)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,9 @@ public class LivingEntity : Entity
|
||||||
Vector2 prevPosition_forClient;
|
Vector2 prevPosition_forClient;
|
||||||
public override void Draw(SpriteBatch spriteBatch)
|
public override void Draw(SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
if ((position - prevPosition_forClient).X< 0)
|
if ((position - prevPosition_forClient).X < 0)
|
||||||
graphicsComponent.Flip = SpriteEffects.FlipHorizontally;
|
graphicsComponent.Flip = SpriteEffects.FlipHorizontally;
|
||||||
else if((position - prevPosition_forClient).X > 0)
|
else if ((position - prevPosition_forClient).X > 0)
|
||||||
graphicsComponent.Flip = SpriteEffects.None;
|
graphicsComponent.Flip = SpriteEffects.None;
|
||||||
base.Draw(spriteBatch);
|
base.Draw(spriteBatch);
|
||||||
prevPosition_forClient = position;
|
prevPosition_forClient = position;
|
||||||
|
|
|
@ -26,8 +26,8 @@ public class Player : LivingEntity
|
||||||
//public bool isTryingToInteract { get; set; }
|
//public bool isTryingToInteract { get; set; }
|
||||||
public Player(Vector2 position) : base(position)
|
public Player(Vector2 position) : base(position)
|
||||||
{
|
{
|
||||||
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 100, 100);
|
graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30);
|
||||||
collisionComponent.stopRectangle = new Rectangle(0, 0, 100, 100);
|
collisionComponent.stopRectangle = new Rectangle(0, 20, 30, 10);
|
||||||
speed = 10;
|
speed = 10;
|
||||||
//isTryingToInteract = false;
|
//isTryingToInteract = false;
|
||||||
//IsTryingToShoot = false;
|
//IsTryingToShoot = false;
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace ZoFo.GameCore.Graphics;
|
||||||
public abstract class GraphicsComponent
|
public abstract class GraphicsComponent
|
||||||
{
|
{
|
||||||
public Rectangle ObjectDrawRectangle;
|
public Rectangle ObjectDrawRectangle;
|
||||||
public static int scaling = 1;
|
public static int scaling = 3;
|
||||||
public string mainTextureName;//TODO костыль - пофиксить
|
public string mainTextureName;//TODO костыль - пофиксить
|
||||||
|
|
||||||
public SpriteEffects Flip = SpriteEffects.None;
|
public SpriteEffects Flip = SpriteEffects.None;
|
||||||
|
|
|
@ -183,6 +183,22 @@ namespace ZoFo.GameCore
|
||||||
{
|
{
|
||||||
|
|
||||||
gameObjects.Add(gameObject);
|
gameObjects.Add(gameObject);
|
||||||
|
if (gameObject is StopObject)
|
||||||
|
{
|
||||||
|
AddData(new UpdateStopObjectCreated()
|
||||||
|
{
|
||||||
|
Position = (gameObject as StopObject).position,
|
||||||
|
sourceRectangle = new SerializableRectangle((gameObject as StopObject).sourceRectangle),
|
||||||
|
Size = new SerializablePoint((gameObject as StopObject).graphicsComponent.ObjectDrawRectangle.Size),
|
||||||
|
tileSetName = ((gameObject as StopObject).graphicsComponent as StaticGraphicsComponent)._textureName,
|
||||||
|
collisions = (gameObject as StopObject).collisionComponents.Select(x=>new SerializableRectangle(x.stopRectangle)).ToArray()
|
||||||
|
});//TODO
|
||||||
|
foreach (var col in (gameObject as StopObject).collisionComponents)
|
||||||
|
{
|
||||||
|
collisionManager.Register(col);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (gameObject is MapObject)
|
if (gameObject is MapObject)
|
||||||
{
|
{
|
||||||
AddData(new UpdateTileCreated()
|
AddData(new UpdateTileCreated()
|
||||||
|
@ -191,7 +207,7 @@ namespace ZoFo.GameCore
|
||||||
sourceRectangle = new SerializableRectangle((gameObject as MapObject).sourceRectangle),
|
sourceRectangle = new SerializableRectangle((gameObject as MapObject).sourceRectangle),
|
||||||
Size = new SerializablePoint((gameObject as MapObject).graphicsComponent.ObjectDrawRectangle.Size),
|
Size = new SerializablePoint((gameObject as MapObject).graphicsComponent.ObjectDrawRectangle.Size),
|
||||||
tileSetName = ((gameObject as MapObject).graphicsComponent as StaticGraphicsComponent)._textureName
|
tileSetName = ((gameObject as MapObject).graphicsComponent as StaticGraphicsComponent)._textureName
|
||||||
});//TODO
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (gameObject is Entity entity)
|
if (gameObject is Entity entity)
|
||||||
|
@ -207,9 +223,7 @@ namespace ZoFo.GameCore
|
||||||
|
|
||||||
|
|
||||||
if (gameObject is Player)
|
if (gameObject is Player)
|
||||||
{
|
|
||||||
players.Add(gameObject as Player);
|
players.Add(gameObject as Player);
|
||||||
}
|
|
||||||
////var elems = gameObject.GetType().GetProperties(System.Reflection.BindingFlags.Public);
|
////var elems = gameObject.GetType().GetProperties(System.Reflection.BindingFlags.Public);
|
||||||
////if (elems.Count()>0) TODO
|
////if (elems.Count()>0) TODO
|
||||||
////{
|
////{
|
||||||
|
|
Loading…
Add table
Reference in a new issue