-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollision.cs
41 lines (37 loc) · 1.01 KB
/
Collision.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Collision.cs
// Created on: 2020-10-23
// Author: Leo Treloar
using System;
using System.Collections.Generic;
using SFML.Audio;
using SFML.Graphics;
using SFML.System;
using SFML.Window;
namespace UniverseIntruders
{
enum CollisionTag {
None,
Player,
PlayerBullet,
Enemy,
EnemyBullet
}
static class Collision
{
public static bool IsPointInRect(Vector2f point, FloatRect rect)
{
return (point.X >= rect.Left &&
point.X <= rect.Left + rect.Width &&
point.Y >= rect.Top &&
point.Y <= rect.Top + rect.Height);
}
// https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection
public static bool IsRectInRect(FloatRect r1, FloatRect r2)
{
return (r1.Left <= r2.Left + r2.Width &&
r1.Left + r1.Width >= r2.Left &&
r1.Top <= r2.Top + r2.Height &&
r1.Top + r1.Height >= r2.Top);
}
}
}