Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Smiley extends SimObject {
- img;
- imgArray = ['../img/smily1.png', '../images/smily2.png', '../images/smily3.png'];
- actImgIndex = 0;
- constructor(theSimulation, objName) {
- super(theSimulation, objName);
- var rnd = Math.random()*5+1;
- this.img = new Image();
- this.img.src = 'imgArray[rnd]';
- }
- calcNextStep() {
- var theCanvasBox = theSimulation.getCanvasRect();
- /** *<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<** */
- if ((this.xPos >= theCanvasBox.width) || (this.xPos <= 0)) {
- //this.xPos = theCanvasBox.width;
- this.xVel = this.xVel * (-1);
- }
- if ((this.yPos >= theCanvasBox.height) || (this.yPos <= 0)) {
- //this.yPos = theCanvasBox.height;
- this.yVel = this.yVel * (-1);
- }
- this.xVel = this.xVel + this.xAccel;
- this.yVel = this.yVel + this.yAccel;
- this.rotationVel = this.rotationVel + this.rotationAccel;
- this.xScaleVel = this.xScaleVel + this.xScaleAccel;
- this.yScaleVel = this.yScaleVel + this.yScaleAccel;
- this.xPos = this.xPos + this.xVel;
- this.yPos = this.yPos + this.yVel;
- this.rotation = this.rotation + this.rotationVel;
- this.xScale = this.xScale + this.xScaleVel;
- this.yScale = this.yScale + this.yScaleVel;
- /** *>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>** */
- this.syncColBody();
- }
- //die Funktion draw muss hier überschrieben werden.
- draw() {
- this.simInstance.ctx.save();
- // Transformation
- this.simInstance.ctx.translate(this.xPos, this.yPos);
- this.simInstance.ctx.rotate(this.rotation * Math.PI / 180);
- this.simInstance.ctx.scale(this.xScale, this.yScale);
- /** *<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<** */
- this.simInstance.ctx.drawImage(this.img, -35, -35);
- /** *>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>** */
- this.simInstance.ctx.restore();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement