Skip to content

Commit

Permalink
adding helper functions in world class
Browse files Browse the repository at this point in the history
  • Loading branch information
amidos2006 committed Mar 5, 2024
1 parent e51d34a commit 77fb589
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/jsp/JSP.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export default class JSP{

static init(canvasID, width, height, fps, scale, debugID, smoothing){
if(fps==undefined) fps = 60;
if(scale==undefined) scale = 1;
if(scale==undefined) scale = -1;
if(debugID==undefined) debugID = "";
if(smoothing==undefined) smoothing = false;

Expand Down
2 changes: 1 addition & 1 deletion src/jsp/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class Entity{
}

addTween(t, start){
if (start == undefined) start = false;
if (start == undefined) start = true;
this._tweener.addTween(t);
if (start) t.start();
}
Expand Down
6 changes: 6 additions & 0 deletions src/jsp/sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ export class SoundManager{
}
}

stop(){
for(let s of this._playingSounds){
s.stop();
}
}

_addSound(s){
if(this._playingSounds.indexOf(s) < 0){
this._playingSounds.push(s);
Expand Down
45 changes: 44 additions & 1 deletion src/jsp/world.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import JSP from "./JSP.js";
import Entity from "./entity.js";
import { BitmapText, Graphic, Text } from "./graphics.js";
import { Tweener } from "./tweens.js";


Expand All @@ -18,7 +21,7 @@ export default class World{
}

addTween(t, start){
if(start == undefined) start = false;
if(start == undefined) start = true;
this._tweener.addTween(t);
if(start) t.start();
}
Expand All @@ -35,6 +38,45 @@ export default class World{
e.visible = true;
e.collidable = true;
this._addedEntitites.push(e);
return e;
}

addGraphic(g, x, y){
if(x === undefined) x = 0;
if(y === undefined) y = 0;

let e = new Entity(x, y, g);
return this.addEntity(e);
}

addBitmapText(text, x, y){
if(x === undefined) x = 0;
if(y === undefined) y = 0;

let g = new BitmapText(JSP.loader.getFile("bmpfont"), text);
g.cx = g.width / 2;
g.cy = g.height / 2;
return this.addGraphic(g, x, y);
}

addText(text, x, y){
if(x === undefined) x = 0;
if(y === undefined) y = 0;

let g = new Text(JSP.loader.getFile("font"), text);
g.cx = g.width / 2;
g.cy = g.height / 2;
return this.addGraphic(g, x, y);
}

addImage(name, x, y){
if(x === undefined) x = 0;
if(y === undefined) y = 0;

let g = new Graphic(JSP.loader.getFile(name));
g.cx = g.width / 2;
g.cy = g.height / 2;
return this.addGraphic(g, x, y);
}

removeEntity(e){
Expand All @@ -45,6 +87,7 @@ export default class World{
e.visible = false;
e.collidable = false;
this._removedEntities.push(e);
return e;
}

getClass(type){
Expand Down

0 comments on commit 77fb589

Please sign in to comment.