Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static GameObject IsCollision<T>(Vector position, bool damage = true)
- {
- // OBS - could be wrong enemy it hits
- //GameObject checker = FindNearestObject<T>(position);
- foreach (GameObject checker in gameObjects) {
- if (checker != null && checker is T) {
- if (typeof(Enemy) == typeof(T)) {
- Vector localHitCoord = Vector.DifferenceWrap(new Vector(position.x, checker.pos.y), new Vector(checker.pos.x, position.y));
- if (localHitCoord.x >= 0 && localHitCoord.y >= 0) {
- if (localHitCoord.x < checker.size.x && localHitCoord.y < checker.size.y) {
- int collisionPosition = localHitCoord.y * checker.size.x + localHitCoord.x;
- if (checker.collider[collisionPosition]) {
- if (damage)
- checker.Hit(collisionPosition);
- return checker;
- }
- }
- }
- } else if (typeof(Player) == typeof(T)) {
- Vector localHitCoord = Vector.Subtract(new Vector(position.x, checker.pos.y), new Vector(checker.pos.x, position.y));
- if (localHitCoord.x >= 0 && localHitCoord.y >= 0) {
- if (localHitCoord.x < checker.size.x && localHitCoord.y < checker.size.y) {
- int collisionPosition = localHitCoord.y * checker.size.x + localHitCoord.x;
- if (checker.collider[collisionPosition]) {
- if (damage)
- checker.Hit(collisionPosition);
- return checker;
- }
- }
- }
- }
- }
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement