Documentation des fonctions

Intégrés dans un fichier séparé nommé `helpers.js`, ces fonctions intègrent dans le starter-kit les fonctionnalités les plus utilisés dans le monde des jeux-vidéos.

Calculs trigonométriques, détections de collisions, raycast, calculs mathématiques raccourcis, tout est ici pour vous simplifier la vie.

point(Number x, Number y)

Raccourcis retournant un objet au format `{x, y}`

            let point = point(21.55, 123.75)
// {
//   x: 21.55,
//   y: 123.75
// }
        
rect(Number x, Number y, Number width, Number height)

Raccourcis retournant un objet au format `{x, y, width, height}`

            let rect = rect(50, 75, 20, 100)
// {
//   x: 50,
//   y: 75,
//   width: 20,
//   height: 100
// }
        
circle(Point center, Number radius)

Raccourcis retournant un objet au format `{center: {x, y}, radius}`

            let circle = circle(point(25, 50), 15)
// {
//   center: {
//     x: 25,
//     y: 50
//   },
//   radius: 15
// }
        
triangle(Point pointA, Point pointB, Point pointC)

Raccourcis retournant un objet au format `{points: [{x, y}, {x, y}, {x, y}]}`

            let triangle = triangle(point(25, 50), point(50, 98), point(40, 62))
// {
//   points: [
//     { x: 25, y: 50 },
//     { x: 50, y: 98 },
//     { x: 40, y: 62 }
//   ]
// }
        
moveTriangle(Triangle triangle, Point vector)

Déplace `triangle` selon le vecteur `vector`

            let triangle = triangle(point(25, 50), point(50, 98), point(40, 62))

moveTriangle(triangle, point(0, 20)) // Déplace le triangle de 20 pixels vers le bas
// {
//   points: [
//     { x: 25, y: 70 },
//     { x: 50, y: 188 },
//     { x: 40, y: 82 }
//   ]
// }
        
clamp(Number min, Number num, Number max)

Circonscrit `num` entre un `min` et un `max`

            clamp(0, 123, 100) // 100
clamp(20, 35, 50) // 35
clamp(20, 10, 50) // 20
        

INFO: Un raccourci `clamp` est intégré directement sur le type `Number`

                            let a = 123
a.clamp(0, 100) // 100
a.clamp(100, 200) // 123
a.clamp(200, 300) // 200
                        
clamp01(Number num)

Circonscrit `num` entre un 0 et 1

            clamp01(1.123) // 1
clamp01(0.756) // 0.756
clamp01(-0.125) // 0
        

INFO: Un raccourci `clamp01` est intégré directement sur le type `Number`

                        let a = 1.123
a.clamp01() // 1
let b = 0.567
b.clamp01() // 0.567
let c = -0.659
c.clamp01() // 0
                    
isNumberBetween(Number a, Number num, Number b)

Retourne un booléen indiquant si un `num` est inclus ou non entre `a` et `b`

            isNumberBetween(0, 123, 100) // false
isNumberBetween(20, 35, 50) // true
isNumberBetween(20, 10, 50) // false
        

INFO: Un raccourci `isBetween` est intégré directement sur le type `Number`

                    let a = 123
a.isBetween(0, 100) // false
a.isBetween(100, 200) // true
                    
                
angleBetweenPoints(Point pointA, Point pointB)

Retour l'angle radian entre deux points

            let a = point(50, 20)
let b = point(11, 56)

angleBetweenPoint(a, b) // -0.7454194762741583
        
randomNumber(Number min, Number max)

Génère un nombre aléatoire compris entre un `min` et un `max`

            randomNumber(0, 100) // Peut être 25, 13, 1 ou 89...
        
aabb(Rect rectA, Rect rectB)

Retourne un booléen indiquant si le `rectA` touche `rectB`

            let a = rect(50, 50, 100, 100) // Un carré de 100x100 positionné à 50;50
let b = rect(125, 125, 100, 100) // Un carré de 100x100 positionné à 125;125
let c = rect(300, 200, 100, 100) // Un carré de 100x100 positionné à 300;200

aabb(a, b) // true
aabb(a, c) // false
aabb(b, c) // true
        
rectContainsPoint(Rect rect, Point point)

Retourne un booléen indiquant si `point` est dans `rect`

            let rect = rect(50, 50, 100, 100) // Un carré de 100x100 positionné à 50;50
let pointA = point(75, 75) // Un point positionné à 75;75
let pointB = point(300, 200) // Un point positionné à 300;200

rectContainsPoint(rect, pointA) // true
rectContainsPoint(rect, pointB) // false
        
circleContainsPoint(Circle circle, Point point)

Retourne un booléen indiquant si `point` est dans `circle`

            let circle = circle(point(50, 50), 100) // Un cercle de diamètre 100 positionné à 50;50
let pointA = point(60, 75) // Un point positionné à 60;75
let pointB = point(300, 200) // Un point positionné à 300;200

circleContainsPoint(rect, pointA) // true
circleContainsPoint(rect, pointB) // false
        
triangleContainsPoint(Triangle triangle, Point point) Premium

Retourne un booléen indiquant si `point` est dans `triangle`

            let triangle = triangle(point(25, 50), point(50, 98), point(40, 62))
let pointA = point(30, 60) // Un point positionné à 30;60
let pointB = point(300, 200) // Un point positionné à 300;200

triangleContainsPoint(triangle, pointA) // true
triangleContainsPoint(triangle, pointB) // false
        
onSegment(Point pointA, Point pointB, Point pointC) Premium

Retourne un booléen indiquant si `pointC` est sur le segment [pointA-PointB]

            let pointA = point(30, 60) // Un point positionné à 30;60
let pointB = point(60, 60) // Un point positionné à 60;60
let pointC = point(45, 60) // Un point positionné à 45;60
let pointD = point(70, 60) // Un point positionné à 70;60

onSegment(pointA, pointB, pointC) // true
onSegment(pointA, pointB, pointD) // false
        
segmentsIntersect(Point pointA, Point pointB, Point pointC, Point pointD) Premium

Retourne un booléen indiquant si le segment le segment [pointA-PointB] croise le segment [pointC-pointD]

            let pointA = point(30, 60) // Un point positionné à 30;60
let pointB = point(60, 60) // Un point positionné à 60;60
let pointC = point(45, 20) // Un point positionné à 45;20
let pointD = point(45, 80) // Un point positionné à 45;80

let pointE = point(70, 60) // Un point positionné à 65;20
let pointF = point(70, 60) // Un point positionné à 65;80

segmentsIntersect(pointA, pointB, pointC, pointD) // true
segmentsIntersect(pointA, pointB, pointE, pointF) // false
        
trianglesCollision(Triangle triangleA, Triangle triangleB) Premium

Retourne un booléen indiquant si `triangleA` est en collision avec `triangleB`

            let triangleA = triangle(point(25, 50), point(50, 98), point(40, 62))
let triangleB = triangle(point(10, 60), point(60, 102), point(30, 52))
let triangleC = triangle(point(100, 100), point(128, 128), point(98, 110))

trianglesCollision(triangleA, triangleB) // true
trianglesCollision(triangleA, triangleC) // false
        
CanvasRenderingContext2D.drawPolygon(Point[] points, Bool filled = true)

Dessine les contours ou le remplissage du polygone définis par les `points`.

            let weirdShape = {
    points: [point(20, 20), point(102, 65), point(98, 152), point(12, 135)]
}

context.fillStyle = 'red'
context.strokeStyle = 'green'
context.drawPolygon(weirdShape) // Rempli la forme
context.drawPolygon(weirdShape, false) // Dessine les contours
        
CanvasRenderingContext2D.drawCircle(Point center, Int radius, Bool filled = true)

Dessine les contours ou le remplissage d'un cercle de centre `center`. et de rayon `radius`.

            let circle = circle(point(50, 50), 25)

context.fillStyle = 'red'
context.strokeStyle = 'green'
context.drawCircle(circle) // Rempli le cercle
context.drawCircle(circle, false) // Dessine les contours
        
CanvasRenderingContext2D.drawLine(Point from, Point to)

Dessine une ligne partant de `from` jusqu'à `to`.

            context.strokeStyle = 'green'
context.drawLine(point(25, 98), point(102, 159))
        
Nous utilisons les cookies pour personnaliser le contenu et analyser notre trafic. Veuillez décider quel type de cookies vous êtes prêt à accepter.