Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. public static GameObject IsCollision<T>(Vector position, bool damage = true)
  2. {
  3. // OBS - could be wrong enemy it hits
  4. //GameObject checker = FindNearestObject<T>(position);
  5.  
  6. foreach (GameObject checker in gameObjects) {
  7. if (checker != null && checker is T) {
  8. if (typeof(Enemy) == typeof(T)) {
  9.  
  10. Vector localHitCoord = Vector.DifferenceWrap(new Vector(position.x, checker.pos.y), new Vector(checker.pos.x, position.y));
  11. if (localHitCoord.x >= 0 && localHitCoord.y >= 0) {
  12. if (localHitCoord.x < checker.size.x && localHitCoord.y < checker.size.y) {
  13. int collisionPosition = localHitCoord.y * checker.size.x + localHitCoord.x;
  14. if (checker.collider[collisionPosition]) {
  15. if (damage)
  16. checker.Hit(collisionPosition);
  17. return checker;
  18. }
  19. }
  20. }
  21. } else if (typeof(Player) == typeof(T)) {
  22. Vector localHitCoord = Vector.Subtract(new Vector(position.x, checker.pos.y), new Vector(checker.pos.x, position.y));
  23. if (localHitCoord.x >= 0 && localHitCoord.y >= 0) {
  24. if (localHitCoord.x < checker.size.x && localHitCoord.y < checker.size.y) {
  25. int collisionPosition = localHitCoord.y * checker.size.x + localHitCoord.x;
  26. if (checker.collider[collisionPosition]) {
  27. if (damage)
  28. checker.Hit(collisionPosition);
  29. return checker;
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }
  36. return null;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement