From 0c7202dd2374b95ee1ba25df322afd9e4208bb45 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Thu, 27 Feb 2020 16:12:17 +0900 Subject: [PATCH] Create objects.js --- objects.js | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 objects.js diff --git a/objects.js b/objects.js new file mode 100644 index 0000000..61b59fb --- /dev/null +++ b/objects.js @@ -0,0 +1,134 @@ +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() { + + } + drawEvent() { + if (!this.visible) { + return; + } else { + resetTransform(); + transformRotate(this.image_angle); + drawSetColor("white"); + if (typeof this.sprite!=="undefined" && this.sprite!=null) { + drawSpriteExt(this.x,this.y,this.sprite,this.image_xscale,this.image_yscale); + } + resetTransform(); + } + } + mouseMoveEvent(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+""; + } +} + +class IronPlate extends Object{ + constructor(x,y,sprite) { + super(sprite,true,x,y); + this.image_xscale=0.5; + this.image_yscale=0.5; + } + stepEvent() { + super.stepEvent(); + + } + drawEvent() { + super.drawEvent(); + } +}