Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. export class Bomb{
  2. constructor(gameWidth,gameHeight){
  3. this.gameWidth = gameWidth;
  4. this.gameHeight = gameHeight;
  5. this.image = document.getElementById("img_bomb");
  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:this.gameWidth,
  12. y:this.gameHeight-this.offset-this.height
  13. };
  14. this.speed = 8;
  15.  
  16. this.audio = new Audio("./ta_ge_kotaiko02.mp3");
  17. }
  18. //二つの円:中心座標(x1,y1)、半径r1の円と、中心が(x2,y2)で半径r2の円が接触したかどうかの判定
  19. checkHit(x1,y1,r1,x2,y2,r2){
  20. var a = x2-x1;
  21. var b = y2-y1;
  22. var r = r1+r2;
  23. return r*r >= a*a+b*b;
  24.  
  25. }
  26. //爆弾の位置が画面外かどうかの判定
  27. offScreen(){
  28. if(this.position.x <= -this.width){
  29.  
  30. return true;
  31. }else{
  32. return false;
  33. }
  34. }
  35.  
  36. update(deltaTime){
  37. this.position.x -= this.speed;
  38. }
  39.  
  40. draw(ctx){
  41. /*ctx.beginPath();
  42. ctx.arc(this.position.x+this.r,this.position.y+this.r,this.r,0,2*Math.PI);
  43. ctx.stroke();*/
  44.  
  45. ctx.drawImage(this.image,this.position.x,this.position.y,this.width,this.height);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement