gameinfo.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. const screenWidth = window.innerWidth
  2. const screenHeight = window.innerHeight
  3. import Element from './element'
  4. let atlas = new Image()
  5. atlas.src = 'images/bg.jpg'
  6. const scalx = canvas.width/375
  7. const scaly=canvas.height/ 667
  8. export default class GameInfo {
  9. renderGameScore(ctx, score) {
  10. this.info = new Element(ctx);
  11. ctx.font = "15px Arial bold"
  12. ctx.strokeStyle = '#fff';
  13. ctx.strokeText('第:'+1+'关',10*scalx,15*scaly)
  14. ctx.fillStyle = "#ffcf00"
  15. ctx.fillText(
  16. '第:'+1+'关',
  17. 10*scalx,
  18. 15*scaly
  19. )
  20. }
  21. renderImage(ctx,score) {
  22. this.info.render(ctx,0,0,148*scalx,5*scaly);
  23. ctx.font = "16px Arial bold"
  24. ctx.strokeStyle = '#eee';
  25. ctx.strokeText(score,183*scalx,50*scaly)
  26. ctx.fillStyle = "#ffcf00"
  27. ctx.fillText(score,183*scalx,50*scaly)
  28. }
  29. renderGameOver(ctx, score) {
  30. ctx.drawImage(atlas, 0, 0, 119, 108, screenWidth / 2 - 150, screenHeight / 2 - 100, 300, 300)
  31. ctx.fillStyle = "#ffffff"
  32. ctx.font = "20px Arial"
  33. ctx.fillText(
  34. '游戏结束',
  35. screenWidth / 2 - 40,
  36. screenHeight / 2 - 100 + 50
  37. )
  38. ctx.fillText(
  39. '得分: ' + score,
  40. screenWidth / 2 - 40,
  41. screenHeight / 2 - 100 + 130
  42. )
  43. ctx.drawImage(
  44. atlas,
  45. 120, 6, 39, 24,
  46. screenWidth / 2 - 60,
  47. screenHeight / 2 - 100 + 180,
  48. 120, 40
  49. )
  50. ctx.fillText(
  51. '重新开始',
  52. screenWidth / 2 - 40,
  53. screenHeight / 2 - 100 + 205
  54. )
  55. /**
  56. * 重新开始按钮区域
  57. * 方便简易判断按钮点击
  58. */
  59. this.btnArea = {
  60. startX: screenWidth / 2 - 40,
  61. startY: screenHeight / 2 - 100 + 180,
  62. endX : screenWidth / 2 + 50,
  63. endY : screenHeight / 2 - 100 + 255
  64. }
  65. }
  66. }