Colliders are really important if you want to make a game with moving parts and check if they collide. Thrunium have some colliders available for exactly that.
Checks collision between two rectangles. The objects have to either have (x, y, width, height) or (pos, width, height) where pos is a Vector.
var game = new THRUNIUM.Game(400, 400);
var rect1 = {
x: 100,
y: 100,
width: 50,
height: 50
};
var rect2 = {
x: 140,
y: 140,
width: 50,
height: 50
};
if (THRUNIUM.Collider.rect(rect1, rect2)) {
console.log("Collision!");
}
var game = new THRUNIUM.Game(400, 400);
var rect1 = {
pos: new THRUNIUM.Vector(100, 100),
width: 50,
height: 50
};
var rect2 = {
pos: new THRUNIUM.Vector(140, 140),
width: 50,
height: 50
};
if (THRUNIUM.Collider.rect(rect1, rect2)) {
console.log("Collision!");
}
Checks collision between two rectangles. The objects have to either have (x, y, radius) or (pos, radius) where pos is a Vector.
var game = new THRUNIUM.Game(400, 400);
var circle1 = {
x: 100,
y: 100,
radius: 50
};
var circle2 = {
x: 140,
y: 140,
radius: 50
};
if (THRUNIUM.Collider.circle(circle1, cirlce2)) {
console.log("Collision!");
}
var game = new THRUNIUM.Game(400, 400);
var circle1 = {
pos: new THRUNIUM.Vector(100, 100),
radius: 50
};
var circle2 = {
pos: new THRUNIUM.Vector(140, 140),
radius: 50
};
if (THRUNIUM.Collider.circle(circle1, cirlce2)) {
console.log("Collision!");
}
Checks collision between two rectangles. The objects have to either have (x, y, radius) or (pos, radius) where pos is a Vector.
var game = new THRUNIUM.Game(400, 400);
var circle = {
x: 100,
y: 100,
radius: 50
};
var rect = {
x: 140,
y: 140,
width: 50,
height: 50
};
if (THRUNIUM.Collider.circleRect(circle, rect)) {
console.log("Collision!");
}
var game = new THRUNIUM.Game(400, 400);
var circle = {
pos: new THRUNIUM.Vector(100, 100),
radius: 50
};
var rect = {
pos: new THRUNIUM.Vector(140, 140),
width: 50,
height: 50
};
if (THRUNIUM.Collider.circleRect(circle, cirlce)) {
console.log("Collision!");
}