Named after my IRL initials, a game engine I am working on to create Javascript games.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
JS/objects.js

140 lines
2.9 KiB

class Object {
constructor(sprite,visible,x,y) {
this.sprite=sprite;
this.visible=visible;
this.x=x;
this.y=y;
this.speed=0;
this.image_xscale=1;
this.image_yscale=1;
this.image_angle=0;
}
stepEvent() {
this.image_angle+=0.5;
}
drawEvent() {
if (!this.visible) {
return;
} else {
resetTransform();
drawSetColor("white");
if (typeof this.sprite!=="undefined" && this.sprite!=null) {
drawSpriteExt(this.x,this.y,this.sprite,this.image_xscale,this.image_yscale,this.image_angle);
//drawSpritePart(this.x,this.y,this.sprite,3,3,20,20,this.image_xscale,this.image_yscale,this.image_angle)
}
resetTransform();
}
}
mouseMoveEvent(e) {
}
touchMoveEvent(e) {
}
keyPressEvent(e) {
}
keyReleaseEvent(e) {
}
mousePressEvent(e) {
}
mouseReleaseEvent(e) {
}
mouseEvent(e) {
}
}
class DebugObj extends Object{
constructor(x,y,sprite) {
super(sprite,true,x,y);
var d = new Date();
this.timer=d.getTime();
this.frameCount=0;
this.lastFrameAmt=0;
this.storedMouseX=0;
this.storedMouseY=0;
this.lastMessage="";
this.eventCount=0;
}
stepEvent() {
//super.stepEvent();
var d = new Date();
var currentTime = d.getTime();
if (currentTime-this.timer>=1000) {
this.lastFrameAmt=this.frameCount;
this.frameCount=0;
this.timer=currentTime;
}
this.frameCount++;
}
drawEvent() {
super.drawEvent();
drawSetColor("white");
drawText(20,20,"Object Count:"+gameObjs.length+" // "+frame++);
drawSetHAlign("right");
drawSetVAlign("bottom");
drawText(
canvas.width,canvas.height-20,"Events: "+this.eventCount);
drawText(
canvas.width,canvas.height,"MOUSE: ("+this.storedMouseX+
","+this.storedMouseY+") "+this.lastFrameAmt+" FPS");
drawSetHAlign("left");
drawSetVAlign("top");
drawText(64,64,this.lastMessage);
drawText(64,84,keysDown.toString());
drawText(64,104,mouseDown.toString());
this.counter=0;
/*for (i=this.messages.length-1;i>=0;i--) {
drawText(20,48+20*i,this.messages[i]);
}*/
}
mouseMoveEvent(e) {
this.eventCount++;
super.mouseMoveEvent(e);
this.storedMouseX=e.offsetX;
this.storedMouseY=e.offsetY;
//this.messages.push(this.lastMessage);
}
mousePressEvent(e) {
this.eventCount++;
super.mousePressEvent(e);
this.lastMessage="Mouse Press Event";
}
mouseReleaseEvent(e) {
this.eventCount++;
super.mouseReleaseEvent(e);
this.lastMessage="Mouse Release Event";
}
keyPressEvent(e) {
this.eventCount++;
super.keyPressEvent(e);
this.lastMessage="Key Press Event: "+e.key+"";
}
keyReleaseEvent(e) {
this.eventCount++;
super.keyReleaseEvent(e);
this.lastMessage="Key Release Event: "+e.key+"";
}
touchMoveEvent(e) {
this.eventCount++;
super.touchMoveEvent(e);
this.lastMessage="Key Release Event: "+e.key+"";
}
}
class IronPlate extends Object{
constructor(x,y,sprite) {
super(sprite,true,x,y);
}
stepEvent() {
super.stepEvent();
}
drawEvent() {
super.drawEvent();
}
}