Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. export class Dino{
  2. constructor(gameWidth,gameHeight){
  3. this.gameWidth = gameWidth;
  4. this.gameHeight = gameHeight;
  5. this.image = document.getElementById("img_dino");
  6. this.offset = 20;
  7. this.r = 60;
  8. this.width = this.r*2;
  9. this.height = this.r*2;
  10. this.position = {
  11. x:60,
  12. y:this.gameHeight-this.offset-this.height
  13. };
  14. this.speed = 0;
  15. this.gravity = 0.5;
  16. this.lift = -12;
  17. this.jumpFlag = true;
  18. this.audio = new Audio("./bubble-burst1.mp3");
  19. }
  20. up(){
  21. if(this.jumpFlag){
  22.  
  23. this.speed = this.lift;
  24. this.jumpFlag = false;
  25.  
  26. this.audio.play(); //ジャンプをしたときに「bubble-burst1.mp3」音声をplay
  27. }
  28.  
  29. }
  30. update(detlaTime){
  31.  
  32.  
  33. this.position.y += this.speed;
  34. this.speed += this.gravity;
  35.  
  36. /*もし恐竜の位置が初期位置(this.gameHeight-this.offset-this.height)より大きい場合、
  37. 位置を初期位置にする*/
  38. if(this.position.y >= this.gameHeight-this.offset-this.height){
  39. this.position.y = this.gameHeight-this.offset-this.height;
  40. this.speed = 0;
  41. this.jumpFlag = true;
  42. }
  43. }
  44. draw(ctx){
  45. /*ctx.beginPath();
  46. ctx.arc(this.position.x+this.r,this.position.y+this.r,this.r,0,2*Math.PI);
  47. ctx.stroke();*/
  48. ctx.drawImage(this.image,this.position.x,this.position.y,this.width,this.height);
  49.  
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement