Skip to content

Commit

Permalink
Merge pull request #16 from waynemwashuma/dev
Browse files Browse the repository at this point in the history
new release v0.4.11
  • Loading branch information
waynemwashuma authored Oct 22, 2023
2 parents 7804e7c + 967bda8 commit 8e419dd
Show file tree
Hide file tree
Showing 58 changed files with 310 additions and 264 deletions.
5 changes: 1 addition & 4 deletions demos/bridge.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {
Vector,
Manager,
Box,
Ball,
DistanceConstraint,
rand,
Entity,
BodySprite
} from "/src/index.js"
Expand Down Expand Up @@ -34,7 +31,7 @@ export function bridge(manager) {
function createChain(x, y, w, h, number, spacing, pin1, pin2) {
let prev = new Box(w, h),
bodies = [
Entity.Default(x * i, y)
Entity.Default(x, y)
.attach("body", prev)
.attach("sprite", new BodySprite())
],
Expand Down
1 change: 0 additions & 1 deletion demos/constraints.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Box,
BodySprite,
DistanceConstraint,
SpringConstraint
} from "/src/index.js"//"/dist/chaos.module.js"

export function constraint(manager) {
Expand Down
4 changes: 2 additions & 2 deletions demos/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { constraint } from "./constraints.js"
import { pathfollower } from "./pathfollower.js"
import { materials } from "./marterial.js"
import { box } from "./box.js"
import { triangle } from "./triangle.js"
import { particle } from "./particle.js"
import { circle } from "./circle.js"
import { circlestacking } from "./circlestack.js"
import { triangle } from "./triangle.js"
import {
Manager,
Renderer2D,
Expand Down Expand Up @@ -118,4 +118,4 @@ demos.register("bridge",bridge)
demos.register("car",car)
demos.register("pathfollower",pathfollower)
demos.register("materials",materials)
demos.register("particle",particle)
demos.register("particle",particle)
2 changes: 0 additions & 2 deletions demos/marterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
BasicMaterial,
StaticImageMaterial,
SpriteMaterial,
Material,
Vector,
Entity
} from "/src/index.js"
Expand All @@ -15,7 +14,6 @@ const assets = {

export function materials(manager) {
manager.clear()
let renderer = manager.getSystem("renderer")
let geometry = new BufferGeometry([
new Vector(-50, -50),
new Vector(-50, 50),
Expand Down
3 changes: 0 additions & 3 deletions demos/particle.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import {
Sprite,
ParticleSystemSprite,
Vector,
Entity
} from "/src/index.js"

export function particle(manager) {
manager.clear()
let renderer = manager.getSystem("renderer")

let entity = Entity.Default(innerWidth/2,innerHeight/2 -200)
let sprite = new ParticleSystemSprite(10,1000)
Expand Down
6 changes: 0 additions & 6 deletions demos/pathfollower.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@ import {
Ball,
BodySprite,
AgentSprite,
AgentManager,
SeekBehaviour,
EvadeBehaviour,
PathFollowing,
ArriveBehaviour,
WanderBehaviour,
Path,
Vector
} from "/src/index.js"

export function pathfollower(manager) {

manager.getSystem("world").gravity = 0
let renderer = manager.getSystem("renderer")

let a = Entity.Default(100, 100)
let b = Entity.Default(100, 250)
Expand Down
10 changes: 7 additions & 3 deletions demos/pyramid.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Box, BodySprite, Entity, Vector } from "/src/index.js"
import {
Box,
BodySprite,
Entity
} from "/src/index.js"

export function pyramid(manager) {
stackpyramid(200, 100, 50, 50, 3, 5, manager)
Expand All @@ -11,8 +15,8 @@ function stackpyramid(x, y, w, h, no, spacing, manager) {
dx += w / 2
for (var i = 0; i < j; i++) {
let entity = Entity.Default(dx + w * i, y + (h + spacing) * j)
.attach("sprite",new BodySprite())
.attach("body",new Box(w, h))
.attach("sprite", new BodySprite())
.attach("body", new Box(w, h))
manager.add(entity)
}
}
Expand Down
2 changes: 0 additions & 2 deletions demos/random.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
Manager,
Vector,
rand,
BodySprite,
Entity,
Expand Down
30 changes: 15 additions & 15 deletions demos/triangle.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {
Entity,
Trigon,
BodySprite
} from "/src/index.js"
export function triangle(manager) {
let world = manager.getSystem("world")
let box = Entity.Default(200,100)
let body = new Trigon(50,50 * Math.sin(30),60)
box.attach("body",body)
.attach("sprite",new BodySprite())
manager.add(box)
world.gravity = 980
}
Entity,
Trigon,
BodySprite
} from "/src/index.js"
export function triangle(manager) {
let world = manager.getSystem("world")
let angle = Math.PI/3
let box = Entity.Default(200,100,1)
let body = new Trigon(50,50 * Math.sin(angle),angle)

box.attach("body",body)
.attach("sprite",new BodySprite())
manager.add(box)
world.gravity = 300
}
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "chaos-studio",
"version": "0.4.0",
"version": "0.4.11",
"description": "a 2D game engine",
"homepage": "https://github.com/waynemwashuma/chaos-engine",
"bugs": {
"url": "https://github.com/waynemwashuma/chaos-engine/issues"
},
"license": "MIT",
"main": "./dist/chaos.umd.js",
"types":"./dist/chaos.module.d.ts",
"types": "./dist/chaos.module.d.ts",
"exports": {
".": {
"import": "/dist/chaos.module.js",
"require": "/dist/chaos.umd.js"
"import": "./dist/chaos.module.js",
"require": "./dist/chaos.umd.js"
}
},
"author": "Wayne Mwashuma",
Expand All @@ -23,11 +23,11 @@
"scripts": {
"types": "tsc -p configs/tsconfig.json",
"test": "echo test done",
"rollup":"rollup --config configs/rollup.config.js",
"rollup": "rollup --config configs/rollup.config.js",
"docs": "jsdoc -c configs/jsdoc.json",
"dev": "npm run build:alfa",
"typedef":"node scripts/typedef.js",
"build":"npm run build:full",
"typedef": "node scripts/typedef.js",
"build": "npm run build:full",
"build:alfa": "npm run rollup & npm run typedef & npm run types",
"build:full": "npm run test & npm run build:alfa",
"build:prod": "npm run build:full & npm run docs"
Expand All @@ -42,7 +42,9 @@
"vite": "^4.3.9",
"rollup": "^2.79.1",
"jsdoc": "4.0.2",
"typescript":"latest"
"typescript": "latest"
},
"files": ["dist/*"]
}
"files": [
"dist/*"
]
}
13 changes: 0 additions & 13 deletions server.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/AI/behaviours/arrive.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Behaviour } from "./behaviour.js"
import { Vector, map, clamp } from "../../math/index.js"
import { Vector, map } from "../../math/index.js"

let tmp1 = new Vector(),
tmp2 = new Vector()
Expand Down
5 changes: 2 additions & 3 deletions src/AI/behaviours/evade.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Behaviour } from "./behaviour.js"
import { Vector,clamp,map } from "../../math/index.js"
import { Vector,map } from "../../math/index.js"

let tmp1 = new Vector(),
tmp2 = new Vector()
let tmp1 = new Vector()
/**
* Creates a behaviour to evade a certain position.
*
Expand Down
6 changes: 4 additions & 2 deletions src/AI/behaviours/flocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import { Vector } from "../../math/index.js"
*
* @augments Behaviour
*/
class Flock {
class Flock extends Behaviour{
/**
* @type Agent[]
*/
neighbours = []
constructor() {}
constructor() {
super()
}
/**
* @inheritdoc
* @param {Agent} agent
Expand Down
5 changes: 1 addition & 4 deletions src/AI/behaviours/path.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Behaviour } from "./behaviour.js"
import { Vector, clamp, map } from "../../math/index.js"
import { Vector, map } from "../../math/index.js"
import { circle, fill, stroke } from "../../render/index.js"
const tmp1 = new Vector()
const tmp2 = new Vector()
const tmp3 = new Vector()
/**
* Creates a behaviour that follows a certain path.
*
Expand Down Expand Up @@ -33,11 +32,9 @@ export class PathFollowing extends Behaviour {
calc(target, inv_dt) {
tmp1.copy(this.position)
let [p1, p2] = this.path.current()
let dist = tmp2.copy(p2).sub(p1).magnitude()
tmp2.normalize()

let proj = tmp2.dot(tmp1.sub(p1))
let dir = tmp3.copy(tmp2).multiply(proj)
let projPoint = this.path.update(proj)
tmp1.copy(projPoint).sub(this.position)
let length = tmp1.magnitude()
Expand Down
4 changes: 2 additions & 2 deletions src/AI/behaviours/pursuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { Vector } from "../../math/index.js"
*
* @augments Behaviour
*/
class Pursuit {
class Pursuit extends Behaviour {
constructor() {

super()
}
/**
* @inheritdoc
Expand Down
5 changes: 2 additions & 3 deletions src/AI/behaviours/seek.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Behaviour } from "./behaviour.js"
import { Vector, map, clamp } from "../../math/index.js"
import { Vector } from "../../math/index.js"

let tmp1 = new Vector(),
tmp2 = new Vector()
let tmp1 = new Vector()

/**
* Creates a behaviour to seek out a target and move towards it.
Expand Down
3 changes: 1 addition & 2 deletions src/AI/paths/path.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Vector, clamp } from "../../math/index.js"
import { vertices, fill, stroke } from "../../render/index.js"
import { vertices, stroke } from "../../render/index.js"

let tmp = new Vector()
export class Path {
Expand Down Expand Up @@ -95,7 +95,6 @@ export class Path {
update(lerpdist = this._lerpdist) {
if (this._finished) return this._lerpedPoint
let dist = tmp.copy(this._points[this._way[0]]).sub(this._points[this._way[1]]).magnitude()
let current = lerpdist / dist
this._lerp_t = (this.speed + lerpdist) / dist
if (this._lerp_t > 1 && (dist - lerpdist) < this.tolerance) {
if (!this.advance()) this._finished = true
Expand Down
2 changes: 1 addition & 1 deletion src/dataStructures/pools/VectorPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Vector} from "../math/index.js"
/**
* A vector pool.
*/
class VectorPool extends Pool{
export class VectorPool extends Pool{
/**
* @inheritdoc
*
Expand Down
4 changes: 1 addition & 3 deletions src/loader/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEVICE } from "../device/index.js"
//import { DEVICE } from "../device/index.js"
import { Err } from "../utils/index.js"
class Loader {
constructor(manager) {
Expand Down Expand Up @@ -58,7 +58,6 @@ class Loader {
}
}
_getName(url) {
let ext
if (url.includes("/")) {
let tmp = url.split("/")
url = tmp[tmp.length - 1]
Expand Down Expand Up @@ -113,7 +112,6 @@ class Loader {
}
if (files.json) {
for (var i = 0; i < files.json.length; i++) {
let name = files.json[i]
let xhr = new XMLHttpRequest();
xhr.responseType = "text"
xhr.open('GET', files.json[i], true);
Expand Down
Loading

1 comment on commit 8e419dd

@vercel
Copy link

@vercel vercel bot commented on 8e419dd Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.