Skip to content

Commit

Permalink
Merge pull request #23 from waynemwashuma/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
waynemwashuma authored Dec 9, 2023
2 parents 744b38f + 31a3851 commit f98f650
Show file tree
Hide file tree
Showing 346 changed files with 25,185 additions and 18,414 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ res.json
*.mp3
tests
*.res.js
*.txt
animations
*.txt
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Chaos-engine

[![DeepScan grade](https://deepscan.io/api/teams/22133/projects/25462/branches/809490/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=22133&pid=25462&bid=809490)
![npm](https://img.shields.io/npm/dt/chaos-studio)
![npm](https://img.shields.io/npm/v/chaos-studio)
![NPM](https://img.shields.io/npm/l/chaos-studio)
![GitHub Repo stars](https://img.shields.io/github/stars/waynemwashuma/chaos-engine)

This is a 2d game engine with physics,a basic canvas renderer,AI,audio management through web audio,an event system and many more features.

Expand Down Expand Up @@ -55,7 +60,7 @@ import * as CHAOS from "chaos-studio"
```
#### OR:

Get the [umd file](https://github.com/waynemwashuma/chaos-engine/dist)
Get the [umd file](https://github.com/waynemwashuma/chaos-engine/dist/chaos.umd.js)
from the dist folder of the [repository](https://github.com/waynemwashuma/chaos-engine),
put it in your root directory and add it to
your html page like so:
Expand Down Expand Up @@ -106,7 +111,7 @@ world.gravity = 900
So far there is nothing on the screen... Lets fix that.
```javascript
//Creates an entity on which we can add(attach) component to.
let box = CHAOS.Entity.Default(innerWidth / 2, 100)
let box = CHAOS.createEntity(innerWidth/2,innerHeight/2)

//Creates a physics component.
let boxBody = new CHAOS.Box(40, 40)
Expand All @@ -129,7 +134,7 @@ Now you should see a box falling into nothingness.
Lets add ground it can land on.
```javascript
//Creates an entity that we call ground on which we can add(attach) component to.
let ground = CHAOS.Entity.Default(innerWidth / 2, innerHeight - 100)
let ground = CHAOS.createEntity(innerWidth / 2, innerHeight - 100)

//Creates a physics component to iteract physically with other entities
let groundBody = new CHAOS.Box(400, 20)
Expand Down Expand Up @@ -158,17 +163,17 @@ game.add(ground)

## **** FUTURE WORK ****

[] Add a webgl renderer(~~dont have a direct plan for this yet~~ Now i do :) )
[] Stabilize the collision response to work well with large forces such as (gravity = 10000)
[] Stabilize rotational stacking in the physics engine
[] ~~Add game state class for managing the game~~
[] Add an animation system.
[] Add tutorials to this game engine
[] Add appropriate demos to the project and get a website running for them
[] Add some error handling mechanisms
[x] Add Serialization/Deserialization of objects(on the way)
[] Kinematic bodies.
[] Collision masking using bits(bit masking)
[] More AI behaviors.
[] Add indexedDB to Storage API.
[] An audio tag fallback to Web audio (if necessary )
- [ ] Add a webgl renderer(~~dont have a direct plan for this yet~~ Now i do :) )
- [ ] Stabilize the collision response to work well with large forces such as (gravity = 10000)
- [ ] Stabilize rotational stacking in the physics engine
- [ ] ~~Add game state class for managing the game~~
- [ ] Add an animation system.
- [ ] Add tutorials to this game engine
- [ ] Add appropriate demos to the project and get a website running for them
- [ ] Add some error handling mechanisms
- [x] Add Serialization/Deserialization of objects(on the way)
- [ ] Kinematic bodies.
- [ ] Collision masking using bits(bit masking)
- [ ] More AI behaviors.
- [ ] Add indexedDB to Storage API.
- [ ] An audio tag fallback to Web audio (if necessary )
2 changes: 1 addition & 1 deletion configs/jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"destination":"./docs",
"recurse":true,
"encoding":"utf-8",
"template":"templates/jsdoc-template",
"template":"doc-template",
"readme":"readme.md"
}
}
2 changes: 0 additions & 2 deletions configs/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import path from "path"
import {defineConfig} from "vite"
import pkg from "./package.json";


export default defineConfig({
build:{
Expand Down
54 changes: 54 additions & 0 deletions demos/animation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
Vector2,
Sprite,
BufferGeometry,
BasicMaterial,
Tween,
createEntity,
Vector2Update,
Easing
} from "/src/index.js"
let path = [
new Vector2(-25,-25),
new Vector2(-25,25),
new Vector2(25,25),
new Vector2(25,-25)
]
let geometry = new BufferGeometry(path)
let material = new BasicMaterial()

material.fill = "blue"

export function animation(manager) {
let tweener = manager.getSystem("tween")

let box = createEntity(200, 100)
let tween = new Tween(
box.get("transform").position
)
let tween2 = new Tween(
box.get("transform").position
)
tween
.from(new Vector2(200, 200))
.to(new Vector2(200, 1200))
.duration(4)
.onUpdate(Vector2Update)
.easing(Easing.linear).play()

tween2
.from(new Vector2(200, 1200))
.to(new Vector2(200, 200))
.duration(4)
.onUpdate(Vector2Update)
.easing(Easing.linear)
tween.chain(tween2)
tween2.chain(tween)
box.attach("sprite", new Sprite(
geometry, material
))
manager.add(box)
tweener.add(tween2)
tweener.add(tween)
console.log(tweener);
}
4 changes: 2 additions & 2 deletions demos/box.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
Entity,
createEntity,
Box,
BodySprite
} from "/src/index.js"
export function box(manager) {
let world = manager.getSystem("world")

let box = Entity.Default(200,100)
let box = createEntity(200,100)
let body = new Box(50,50)

box.attach("body",body)
Expand Down
10 changes: 5 additions & 5 deletions demos/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
Vector2,
Box,
DistanceConstraint,
Entity,
createEntity,
BodySprite
} from "/src/index.js"

Expand All @@ -11,10 +11,10 @@ export function bridge(manager) {

world.gravity = 1000

let pin1 = Entity.Default(100, 200)
let pin1 = createEntity(100, 200)
.attach("body",new Box(20, 20))
.attach("sprite",new BodySprite())
let pin2 = Entity.Default(350, 200)
let pin2 = createEntity(350, 200)
.attach("body",new Box(20, 20))
.attach("sprite",new BodySprite())
let chain = createChain(50, 200, 50, 10, 5, 50, pin1, pin2)
Expand All @@ -31,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, y)
createEntity(x, y)
.attach("body", prev)
.attach("sprite", new BodySprite())
],
Expand All @@ -46,7 +46,7 @@ function createChain(x, y, w, h, number, spacing, pin1, pin2) {
let constraint = new DistanceConstraint(prev, chain, prev.getAnchor(an1),chain.getAnchor(an2))

bodies.push(
Entity.Default(x * i, y)
createEntity(x * i, y)
.attach("body", chain)
.attach("sprite", new BodySprite())
)
Expand Down
4 changes: 2 additions & 2 deletions demos/car.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
Vector2,
DistanceConstraint,
Entity,
createEntity,
Box,
Ball,
Composite,
Expand All @@ -22,7 +22,7 @@ export function car(manager) {
}

function createCar(x, y, tireSize = 20, maskgroup = 1, manager) {
let car = Entity.Default(x, y)
let car = createEntity(x, y)

let tirebody1 = new Ball(tireSize)
let tirebody2 = new Ball(tireSize)
Expand Down
4 changes: 2 additions & 2 deletions demos/circle.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
Entity,
createEntity,
Ball,
BodySprite
} from "/src/index.js"

export function circle(manager) {
let world = manager.getSystem("world")

let box = Entity.Default(200,100)
let box = createEntity(200,100)
let body = new Ball(20)

box.attach("body",body)
Expand Down
4 changes: 2 additions & 2 deletions demos/circlestack.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
BodySprite,
Ball,
Entity
createEntity
} from "/src/index.js"


Expand All @@ -12,7 +12,7 @@ export function circlestacking(manager) {

function stack(x, y,r, no, spacing, manager) {
for (var i = 0; i < no; i++) {
let entity = Entity.Default(x, y + (r + spacing) * i)
let entity = createEntity(x, y + (r + spacing) * i)
.attach("body",new Ball(r))
.attach("sprite",new BodySprite())
manager.add(entity)
Expand Down
6 changes: 3 additions & 3 deletions demos/constraints.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
Vector2,
Entity,
createEntity,
Box,
BodySprite,
DistanceConstraint,
Expand All @@ -9,8 +9,8 @@ import {
export function constraint(manager) {
let world = manager.getSystem("world")

let box1 = Entity.Default(200, 300)
let box2 = Entity.Default(200, 360)
let box1 = createEntity(200, 300)
let box2 = createEntity(200, 360)

let body1 = new Box(50, 50)
let body2 = new Box(50, 50)
Expand Down
10 changes: 5 additions & 5 deletions demos/friction.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
Entity,
createEntity,
Box,
Ball,
BodySprite,
Expand All @@ -8,13 +8,13 @@ import {
export function friction(manager) {
let world = manager.getSystem("world")

let floor1 = Entity.Default(200,300,20)
let floor1 = createEntity(200,300,20)
let body1 = new Box(300,20)
let entity1 = Entity.Default(100,237)
let entity1 = createEntity(100,237)
let body2 = new Ball(15)
let floor2 = Entity.Default(200,200,20)
let floor2 = createEntity(200,200,20)
let body3 = new Box(300,20)
let entity2 = Entity.Default(100,100,20)
let entity2 = createEntity(100,100,20)
let body4 = new Box(50,30)

body1.type = Body.STATIC
Expand Down
Loading

0 comments on commit f98f650

Please sign in to comment.