Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. class Smiley extends SimObject {
  2. img;
  3. imgArray = ['../img/smily1.png', '../images/smily2.png', '../images/smily3.png'];
  4. actImgIndex = 0;
  5. constructor(theSimulation, objName) {
  6. super(theSimulation, objName);
  7. var rnd = Math.random()*5+1;
  8. this.img = new Image();
  9. this.img.src = 'imgArray[rnd]';
  10. }
  11.  
  12. calcNextStep() {
  13. var theCanvasBox = theSimulation.getCanvasRect();
  14.  
  15. /** *<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<** */
  16.  
  17. if ((this.xPos >= theCanvasBox.width) || (this.xPos <= 0)) {
  18. //this.xPos = theCanvasBox.width;
  19. this.xVel = this.xVel * (-1);
  20. }
  21. if ((this.yPos >= theCanvasBox.height) || (this.yPos <= 0)) {
  22. //this.yPos = theCanvasBox.height;
  23. this.yVel = this.yVel * (-1);
  24. }
  25.  
  26. this.xVel = this.xVel + this.xAccel;
  27. this.yVel = this.yVel + this.yAccel;
  28. this.rotationVel = this.rotationVel + this.rotationAccel;
  29. this.xScaleVel = this.xScaleVel + this.xScaleAccel;
  30. this.yScaleVel = this.yScaleVel + this.yScaleAccel;
  31.  
  32. this.xPos = this.xPos + this.xVel;
  33. this.yPos = this.yPos + this.yVel;
  34.  
  35. this.rotation = this.rotation + this.rotationVel;
  36. this.xScale = this.xScale + this.xScaleVel;
  37. this.yScale = this.yScale + this.yScaleVel;
  38. /** *>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>** */
  39.  
  40. this.syncColBody();
  41. }
  42.  
  43. //die Funktion draw muss hier überschrieben werden.
  44. draw() {
  45. this.simInstance.ctx.save();
  46. // Transformation
  47. this.simInstance.ctx.translate(this.xPos, this.yPos);
  48. this.simInstance.ctx.rotate(this.rotation * Math.PI / 180);
  49. this.simInstance.ctx.scale(this.xScale, this.yScale);
  50.  
  51. /** *<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<** */
  52. this.simInstance.ctx.drawImage(this.img, -35, -35);
  53. /** *>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>** */
  54.  
  55. this.simInstance.ctx.restore();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement