index.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="user-scalable=no, width=device-width, minimum-scale=1, maximum-scale=1" />
  6. <title>Text - Hilo Example</title>
  7. <link rel="stylesheet" type="text/css" href="./static/css/sytle.css">
  8. <script type="text/javascript" src="./static/js/hilo-standalone.min.js"></script>
  9. <img src="./static/images/fish.png" alt="" id="fish" style="display:none">
  10. </head>
  11. <body>
  12. <div id="game-container"></div>
  13. <div style="padding: 20px; text-align: center;">
  14. <button onclick="reset()">重播</button>
  15. </div>
  16. <script type="text/javascript" src="./static/js/demo.js"></script>
  17. <script type="text/javascript">
  18. var stage = new Hilo.Stage({
  19. renderType: renderType,
  20. container: gameContainer,
  21. width: stageWidth,
  22. height: stageHeight
  23. });
  24. //start stage ticker
  25. var ticker = new Hilo.Ticker(60);
  26. ticker.addTick(stage);
  27. ticker.start();
  28. //添加背景
  29. var bmp = new Hilo.Bitmap({
  30. image: './static/images/map.jpg',
  31. rect: [0, 0, stageWidth, stageHeight],
  32. x: 0,
  33. y: 0
  34. }).addTo(stage);
  35. var zidanImg = [];
  36. var zidan = [];
  37. var zidanStep = 0;
  38. for (i = 0; i < 3; i++) {
  39. zidanImg[i] = new Hilo.TextureAtlas({
  40. image: './static/images/zidan.png',
  41. width: 64,
  42. height: 64,
  43. frames: {
  44. frameWidth: 64,
  45. frameHeight: 64,
  46. numFrames: 1
  47. },
  48. sprites: {
  49. zidanImg: { from: 0, to: 0 }
  50. }
  51. });
  52. zidan = new Hilo.Sprite({
  53. frames: zidanImg[i].getSprite('zidanImg'),
  54. x: 10 * (i + 1),
  55. y: 100 + 10 * (i + 1),
  56. interval: 10,
  57. timeBased: true,
  58. loop: true,
  59. onUpdate: function () {
  60. if (this.x < 200) {
  61. // console.log("#debug#🚀 ~ file: index.html:84 ~ init ~ this:", this.style)
  62. if (this.x > stage.width - this.pivotX) {
  63. this.x = 0;
  64. } else {
  65. var paoWuXianRes = paoWuXian(this.x + 3);
  66. // console.log("#debug#🚀 ~ file: index.html:88 ~ init ~ paoWuXianRes:", paoWuXianRes)
  67. this.x = paoWuXianRes.x;
  68. // this.y = paoWuXianRes.y;
  69. //this.x += 3;
  70. }
  71. } else {
  72. manStart = true;
  73. }
  74. }
  75. }).addTo(stage);
  76. //text wrapped in dom element
  77. }
  78. // 子弹
  79. //init texture atlas
  80. var atlas = new Hilo.TextureAtlas({
  81. image: './static/images/man.png',
  82. width: 100,
  83. height: 88,
  84. frames: {
  85. frameWidth: 100,
  86. frameHeight: 88,
  87. numFrames: 1
  88. },
  89. sprites: {
  90. fish: { from: 0, to: 0 }
  91. }
  92. });
  93. var manStart = false;
  94. var fish = new Hilo.Sprite({
  95. frames: atlas.getSprite('fish'),
  96. x: 0,
  97. y: 300,
  98. interval: 6,
  99. timeBased: false,
  100. loop: true,
  101. onUpdate: function () {
  102. if (manStart) {
  103. if (this.x < 200) {
  104. this.x += 3;
  105. this.y -= 3;
  106. }
  107. }
  108. }
  109. }).addTo(stage);
  110. function manStart() {
  111. manStart = true;
  112. }
  113. function reset() {
  114. manStart = false;
  115. for (i = 0; i < zidanImg.length; i++) {
  116. zidan[i].x = 10 * (i + 1);
  117. zidan[i].y = 100 + 10 * (i + 1);
  118. }
  119. fish.x = 0;
  120. fish.y = 300;
  121. }
  122. function paoWuXian(x) {
  123. // var y = 1 * x * x + 1 * x + 2;
  124. return {
  125. x, y: 100
  126. }
  127. }
  128. </script>
  129. </body>
  130. </html>