~nasser/lospec-2

85f58fd4c12d46824e4cb65a6236ef15faccdb89 — Ramsey Nasser 7 months ago 379a568
Add zones
1 files changed, 25 insertions(+), 2 deletions(-)

M main.js
M main.js => main.js +25 -2
@@ 112,6 112,12 @@ function drawPeg(position, color = 'white', size = 2) {
    GIZMOS.line(v, v.clone().add(new THREE.Vector3(0, size, 0)), new THREE.Color(color))
}

const zones = []
zones.push({
    box: new THREE.Box2(new THREE.Vector2(-40, -100), new THREE.Vector2(40, -50)),
    velocity: new THREE.Vector2(0, -1).normalize()
})

const terrain = []
function makeTerrainPath(path) {
    for (let i = 0; i < path.length - 1; i++)


@@ 135,10 141,19 @@ makeTerrainPath([


SCHED.add(function* () {
    const blue = new THREE.Color('blue')
    const blue = new THREE.Color(0x2929ff)
    const green = new THREE.Color(0x0aff0a)
    const center = new THREE.Vector2()
    while (true) {
        for (const segment of terrain) {
        for (const segment of terrain)
            GIZMOS.line(toVector3(segment.from), toVector3(segment.to), blue)
        for (const zone of zones) {
            GIZMOS.line(toVector3(zone.box.min), toVector3(new THREE.Vector2(zone.box.min.x, zone.box.max.y)), green)
            GIZMOS.line(toVector3(new THREE.Vector2(zone.box.min.x, zone.box.max.y)), toVector3(zone.box.max), green)
            GIZMOS.line(toVector3(zone.box.max), toVector3(new THREE.Vector2(zone.box.max.x, zone.box.min.y)), green)
            GIZMOS.line(toVector3(new THREE.Vector2(zone.box.max.x, zone.box.min.y)), toVector3(zone.box.min), green)
            zone.box.getCenter(center)
            GIZMOS.line(toVector3(center), toVector3(center.clone().addScaledVector(zone.velocity, 20)), green)
        }
        yield
    }


@@ 204,6 219,14 @@ SCHED.add(function* sheep() {
                color = 'yellow'
            }

            // zone
            for (const zone of zones) {
                if (zone.box.containsPoint(sheep.position)) {
                    sheep.velocity.addScaledVector(zone.velocity, 2)
                    color = 0x007062
                }
            }

            // avoid terrain
            const line = new THREE.Line3()
            const closest = new THREE.Vector3()