gameinfo.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const screenWidth = window.innerWidth
  2. const screenHeight = window.innerHeight
  3. const atlas = new Image()
  4. atlas.src = 'images/Common.png'
  5. export default class GameInfo {
  6. renderGameScore(ctx, score) {
  7. ctx.fillStyle = '#ffffff'
  8. ctx.font = '20px Arial'
  9. ctx.fillText(
  10. score,
  11. 10,
  12. 30
  13. )
  14. }
  15. renderGameOver(ctx, score) {
  16. ctx.drawImage(atlas, 0, 0, 119, 108, screenWidth / 2 - 150, screenHeight / 2 - 100, 300, 300)
  17. ctx.fillStyle = '#ffffff'
  18. ctx.font = '20px Arial'
  19. ctx.fillText(
  20. '游戏结束',
  21. screenWidth / 2 - 40,
  22. screenHeight / 2 - 100 + 50
  23. )
  24. ctx.fillText(
  25. `得分: ${score}`,
  26. screenWidth / 2 - 40,
  27. screenHeight / 2 - 100 + 130
  28. )
  29. ctx.drawImage(
  30. atlas,
  31. 120, 6, 39, 24,
  32. screenWidth / 2 - 60,
  33. screenHeight / 2 - 100 + 180,
  34. 120, 40
  35. )
  36. ctx.fillText(
  37. '重新开始',
  38. screenWidth / 2 - 40,
  39. screenHeight / 2 - 100 + 205
  40. )
  41. /**
  42. * 重新开始按钮区域
  43. * 方便简易判断按钮点击
  44. */
  45. this.btnArea = {
  46. startX: screenWidth / 2 - 40,
  47. startY: screenHeight / 2 - 100 + 180,
  48. endX: screenWidth / 2 + 50,
  49. endY: screenHeight / 2 - 100 + 255
  50. }
  51. }
  52. }