Resolve issues

This commit is contained in:
PetrKu09 2024-08-17 11:36:18 +03:00
parent 72bfd52ae5
commit 1b77e35c32
2 changed files with 17 additions and 15 deletions

View file

@ -1,10 +1,11 @@
using System; using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Linq; using System.Linq;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ZoFo.GameCore.GameObjects;
using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player; using ZoFo.GameCore.GameObjects.Entities.LivingEntities.Player;
namespace ZoFo.GameCore.GameManagers.CollisionManager namespace ZoFo.GameCore.GameManagers.CollisionManager
@ -13,17 +14,19 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
{ {
//==ПОЛЯ== //==ПОЛЯ==
//public GameObject gameObject { get; set; } public GameObject gameObject { get; set; }
//public Rectangle Bounds { get; set; } //public Rectangle Bounds { get; set; }
public Rectangle Rectangle => new Rectangle(); //public Rectangle Rectangle => new Rectangle();
bool doesStop; bool doesStop;
Rectangle stopRectangle; public Rectangle stopRectangle;
// triggers for rectangle // triggers for rectangle
bool isTrigger; bool isTrigger;
Rectangle triggerRectangle; public Rectangle triggerRectanglee;
//delegate //delegate
public delegate void EventHandler(object sender, EventArgs e); public delegate void EventHandler(object sender, EventArgs e);

View file

@ -1,7 +1,6 @@
using Microsoft.VisualBasic; using Microsoft.VisualBasic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -28,7 +27,7 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
{ {
//for (int i = 0; i < ObjectsWithCollisions.Count; i++) //for (int i = 0; i < ObjectsWithCollisions.Count; i++)
//{ //{
var currentRect = entity.Rectangle;//задаём РЕК var currentRect = entity.collisionComponent.stopRectangle;//задаём РЕК
var newRect = currentRect; // задаём значение старого РЕК новому РЕК var newRect = currentRect; // задаём значение старого РЕК новому РЕК
bool flagRemovedObject = false; //флаг удаления bool flagRemovedObject = false; //флаг удаления
@ -40,9 +39,9 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
foreach (var item in ObjectsWithCollisions)//фильтрация foreach (var item in ObjectsWithCollisions)//фильтрация
{ {
if (Math.Abs(item.Pos.X - entity.Pos.X) < 550 if (Math.Abs(item.stopRectangle.X - entity.collisionComponent.stopRectangle.X) < 550
&& Math.Abs(item.Pos.Y - entity.Pos.Y) < 550 && Math.Abs(item.stopRectangle.Y - entity.collisionComponent.stopRectangle.Y) < 550
&& tryingRectX.Intersect(item.Rectangle)) && tryingRectX.Intersects(item.stopRectangle))
{ {
collidedX = true;// меняем значение соприкосновения на true collidedX = true;// меняем значение соприкосновения на true
@ -66,13 +65,13 @@ namespace ZoFo.GameCore.GameManagers.CollisionManager
var collidedY = false; // соприкосновение var collidedY = false; // соприкосновение
var tryingRectY = currentRect;//переменная для попытки перемещения по X var tryingRectY = currentRect;//переменная для попытки перемещения по X
tryingRectY.Offset((int)(0, entity.velocity.Y));//задаём значения для tryingRectX по X и по Y tryingRectY.Offset(new Point(0, (int)entity.velocity.Y));//задаём значения для tryingRectX по X и по Y
foreach (var item in ObjectsWithCollisions)//фильтрация foreach (var item in ObjectsWithCollisions)//фильтрация
{ {
if (Math.Abs(item.Pos.X - entity.Pos.X) < 550 if (Math.Abs(item.stopRectangle.X - entity.collisionComponent.stopRectangle.X) < 550
&& Math.Abs(item.Pos.Y - entity.Pos.Y) < 550 && Math.Abs(item.stopRectangle.Y - entity.collisionComponent.stopRectangle.Y) < 550
&& tryingRectY.Intersect(item.Rectangle)) && tryingRectY.Intersects(item.stopRectangle))
{ {
collidedY = true;// меняем значение соприкосновения на true collidedY = true;// меняем значение соприкосновения на true