Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.43 KB | None | 0 0
  1. var Game = function () { };
  2.  
  3. var ratcheck;
  4. var map;
  5. var player;
  6. var p2;
  7. var layer, layer1, layer2, specialLayer;
  8. var p;
  9. var shootTimer = 0;
  10. var enemy;
  11. var countScoreAndTime = true;
  12. var canMinus = true;
  13. var cursors;
  14. var weapon;
  15. var coordX, coordY;
  16. var isJumping = false;
  17. var jumpTimer = 0;
  18. var text;
  19. var buttonLeft, buttonRight, buttonJump, buttonFire;
  20. var right = false;
  21. var left = false;
  22. var jump = false;
  23. var fire = false;
  24. var time = 0;
  25. var score = 0, tempScore, minusScore;
  26. var canHit;
  27. var speed, platform;
  28. var lifes = 3;
  29. var bulletsCounter = 4;
  30. var playerAnimation;
  31. var questionObjectsArray = [];
  32. var onPlatform = false;
  33. var music;
  34. var fx;
  35. var canShoot = true;
  36. var ScoreInfo = {
  37. time: '0',
  38. score: '0',
  39. lifes:'0'
  40. };
  41. Game.prototype = {
  42. preload:function() {
  43. screen.orientation.lock('landscape');
  44.  
  45. game.load.tilemap('mario', 'images/mario_map.json', null, Phaser.Tilemap.TILED_JSON);
  46. game.load.image('super_mario', 'images/super_mario.png');
  47. game.load.image('bullet', 'images/bullet.png');
  48. game.load.image('bullet2', 'images/bullet2.png');
  49. game.load.image('enemy', 'images/enemy.png');
  50. game.load.image('btLeft', 'images/dpad/left.png');
  51. game.load.image('btRight', 'images/dpad/right.png');
  52. game.load.image('btJump', 'images/dpad/jump.png');
  53. game.load.image('btFire', 'images/dpad/fire.png');
  54. game.load.image('ratcheck', 'images/ratcheck.png');
  55.  
  56. game.load.spritesheet('move', 'images/hero_spritesheet.png', 340 / 8, 214 / 5, 48);
  57. game.load.audio('song', ['images/music/song.mp3', 'images/music/song.ogg']);
  58. game.load.audiosprite('sfx', 'images/music/fx_mixdown.ogg');
  59. game.load.script('textButton','scripts/textButton.js');
  60.  
  61. },
  62.  
  63.  
  64.  
  65. create: function () {
  66. alert("Welcome in our DirtyReverseMario game"+"\n" +"Remember you have 4 bullets and can renew it by picking up bullet's from boxes" + "\n" + "You have 3 lifes if you die current stage is reloaded and your current points vanishe's "+"\n" + "Kill princesses by using shoot or avoid it and have fun");
  67. countScoreAndTime = true;
  68. bulletsCounter = 4;
  69. game.physics.startSystem(Phaser.Physics.ARCADE);
  70. game.stage.backgroundColor = '#787878';
  71. music = game.add.audio('song');
  72. music.volume = 0.2;
  73. // music.play();
  74. fx = game.add.audio('sfx');
  75. fx.allowMultiple = true;
  76.  
  77. fx.addMarker('alien death', 1, 1.0);
  78. fx.addMarker('boss hit', 3, 0.5);
  79. fx.addMarker('escape', 4, 3.2);
  80. fx.addMarker('meow', 8, 0.5);
  81. fx.addMarker('numkey', 9, 0.1);
  82. fx.addMarker('ping', 10, 1.0);
  83. fx.addMarker('death', 12, 4.2);
  84. fx.addMarker('shot', 17, 1.0);
  85. fx.addMarker('squit', 19, 0.3);
  86.  
  87. map = game.add.tilemap('mario');
  88. map.addTilesetImage('super_mario', 'super_mario');
  89. map.addTilesetImage('bullet2', 'bullet2');
  90. map.addTilesetImage('enemy', 'enemy');
  91. map.addTilesetImage('ratcheck', 'ratcheck');
  92. map.setCollisionBetween(0, 142, true, 'ground');
  93. map.setCollisionBetween(1, 1225, true, 'walls');
  94. map.setCollisionBetween(1, 1225, true, 'special');
  95.  
  96. // 9,10 ,13//40 podloga //39 mapa//20+ rura//16 schodki//14 zapytajnik//13 flaga
  97. //15 brick//tileCall
  98. map.setTileIndexCallback(11, hitCoin, this, 'walls');
  99. map.setTileIndexCallback(15, hitBricks, this, 'ground');
  100. map.setTileIndexCallback(1, hitHiden, this, 'walls');
  101. map.setTileIndexCallback(14, hitQBox, this, 'ground');
  102. map.setTileIndexCallback(45, grabBullet, this, 'ground');
  103. // map.setTileIndexCallback(9, reachCastle, this, 'ground');
  104. // map.setTileIndexCallback(17, reachCastle, this, 'ground');
  105. map.setTileIndexCallback(13, Castle, this, 'ground');
  106. // map.setTileIndexCallback(10, reachCastle, this, 'ground');
  107.  
  108.  
  109. layer1 = map.createLayer('background');
  110. layer2 = map.createLayer('walls');
  111. layer = map.createLayer('ground');
  112.  
  113. layer.resizeWorld();
  114. layer1.resizeWorld();
  115. layer2.resizeWorld();
  116.  
  117. player = game.add.sprite(0, 100, 'move');
  118. player.anchor.set(0.5);
  119. // playerAnimation = player.animations.add('walk');
  120. player.animations.add("goLeft", [8, 13], 10, true);
  121. player.animations.add("goRight", [25, 26], 10, true);
  122.  
  123. //objects
  124.  
  125. enemy = game.add.group();
  126. enemy.enableBody = true;
  127. enemy.physicsBodyType = Phaser.Physics.ARCADE;
  128.  
  129. ratcheck = game.add.group();
  130. ratcheck.enableBody = true;
  131. ratcheck.physicsBodyType = Phaser.Physics.ARCADE;
  132.  
  133. map.createFromObjects('enemies', 46, 'enemy', 0, true, false, enemy);
  134. map.createFromObjects('enemies', 357, 'ratcheck', 0, true, false, ratcheck);
  135. game.physics.arcade.enable(enemy);
  136. game.physics.arcade.enable(ratcheck);
  137. game.physics.arcade.enable('enemies');
  138. // game.physics.arcade.enable('ratcheck');
  139. // game.physics.arcade.enable('enemies');
  140. // enemy.callAll('anchor.setTo', 'anchor', 0.5, 1.0);
  141.  
  142. enemy.setAll('body.velocity.x', 10);
  143. enemy.setAll('body.gravity.y', 250);
  144.  
  145. // ratcheck.setAll('body.velocity.x', 40);
  146. ratcheck.setAll('body.gravity.y', 250);
  147.  
  148. game.physics.arcade.enable(player);
  149. game.physics.arcade.enable(layer);
  150. game.physics.arcade.enable(layer2);
  151.  
  152. player.body.gravity.y = 250;
  153. player.body.setSize(14, 14, 14, 14);
  154. player.body.collideWorldBounds = true;
  155.  
  156. //pad
  157. buttonLeft = game.add.button(window.innerWidth * .10, window.innerHeight - 100, 'btLeft', null, this, 0);
  158. buttonLeft.scale.setTo(1, 1);
  159.  
  160. buttonRight = game.add.button(window.innerWidth * .30, window.innerHeight - 100, 'btRight', null, this, 0);
  161. buttonRight.scale.setTo(1, 1);
  162.  
  163. buttonJump = game.add.button(window.innerWidth * .60, window.innerHeight - 100, 'btJump', null, this, 0);
  164. buttonJump.scale.setTo(1, 1);
  165.  
  166. buttonFire = game.add.button(window.innerWidth * .80, window.innerHeight - 100, 'btFire', null, this, 0);
  167. buttonFire.scale.setTo(1, 1);
  168.  
  169. buttonLeft.fixedToCamera = true;
  170. buttonRight.fixedToCamera = true;
  171. buttonJump.fixedToCamera = true;
  172. buttonFire.fixedToCamera = true;
  173.  
  174.  
  175. buttonLeft.onInputDown.add(function () {
  176. left = true
  177. }, this);
  178. buttonLeft.onInputOver.add(function () {
  179. left = true
  180. }, this);
  181. buttonLeft.onInputUp.add(function () {
  182. left = false
  183. }, this);
  184. buttonLeft.onInputOut.add(function () {
  185. left = false
  186. }, this);
  187.  
  188. buttonRight.onInputDown.add(function () {
  189. right = true
  190. }, this);
  191. buttonRight.onInputOver.add(function () {
  192. right = true
  193. }, this);
  194. buttonRight.onInputUp.add(function () {
  195. right = false
  196. }, this);
  197. buttonRight.onInputOut.add(function () {
  198. right = false
  199. }, this);
  200.  
  201. buttonJump.onInputDown.add(function () {
  202. jump = true
  203. }, this);
  204. buttonJump.onInputOver.add(function () {
  205. jump = true
  206. }, this);
  207. buttonJump.onInputUp.add(function () {
  208. jump = false
  209. }, this);
  210. buttonJump.onInputOut.add(function () {
  211. jump = false
  212. }, this);
  213.  
  214. buttonFire.onInputDown.add(function () {
  215. fire = true
  216. }, this);
  217. buttonFire.onInputOver.add(function () {
  218. fire = true
  219. }, this);
  220. buttonFire.onInputUp.add(function () {
  221. fire = false
  222. }, this);
  223. buttonFire.onInputOut.add(function () {
  224. fire = false
  225. }, this);
  226.  
  227. weapon = game.add.weapon(4, 'bullet');
  228. weapon.bulletKillType = Phaser.Weapon.KILL_CAMERA_BOUNDS;
  229. weapon.bulletAngleOffset = 90;
  230. weapon.bulletSpeed = 600;
  231. weapon.fireLimit = 4;
  232.  
  233. weapon.trackSprite(player, 0, 0, true);
  234.  
  235. //text
  236. var style = { font: "20px Courier", fill: "#fff", tabs: 132 };
  237. var style2 = { font: "40px Courier", fill: "#fff", tabs: 132 };
  238.  
  239. text = game.add.text(10, 10, "Lifes:" + lifes, style);
  240. this.text2 = game.add.text(window.innerWidth / 2, 10, "Time:" + time, style);
  241. this.text3 = game.add.text(window.innerWidth -150, 10, "Score:" + score, style);
  242. this.text4 = game.add.text(window.innerWidth -150 , 30, "Bullets" + bulletsCounter, style);
  243. this.gameOver = game.add.text( (window.innerWidth / 2) - 100, (window.innerHeight / 2 )-100, "", style2);
  244. //camera
  245. text.fixedToCamera = true;
  246. this.text2.fixedToCamera = true;
  247. this.text3.fixedToCamera = true;
  248. this.text4.fixedToCamera = true;
  249. this.gameOver.fixedToCamera = true;
  250.  
  251. game.camera.follow(player);
  252. game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT;
  253. cursors = game.input.keyboard.createCursorKeys();
  254. },
  255.  
  256.  
  257. update: function() {
  258.  
  259. player.body.velocity.x = 0;
  260. game.physics.arcade.collide(player, layer);
  261. game.physics.arcade.collide(player, layer2);
  262. game.physics.arcade.collide(player, this.bricks);
  263. game.physics.arcade.collide(player, enemy,deadByEnemy,null,this);
  264. game.physics.arcade.collide(weapon.bullets, enemy, hitEnemy, null, this);
  265.  
  266.  
  267. text.setText("Lifes:" + lifes);
  268. if (countScoreAndTime) {
  269. time += 1;
  270. }
  271. bulletsCounter = 4 - weapon.shots;
  272. this.text2.setText("Time:" + time);
  273. this.text3.setText("Score: " + score);
  274. this.text4.setText("Bullets: " + bulletsCounter);
  275.  
  276. if (left) {
  277. turnLeft();
  278. isJumping = false;
  279.  
  280. }
  281. else if (right) {
  282. turnRight();
  283. isJumping = false;
  284. }
  285. else if (jump) {
  286. if (player.body.onFloor() && game.time.now > jumpTimer) {
  287. player.body.y -= 1;
  288. player.body.velocity.y = -200;
  289. player.animations.stop();
  290. isJumping = true;
  291. }
  292.  
  293. } else if (fire) {
  294. isJumping = false;
  295. fireF();
  296. }
  297. if (player.body.onFloor() && player.body.y > 210) {
  298. fx.play('death');
  299. // navigator.vibrate(2000);
  300. countScoreAndTime = false;
  301. this.gameOver.setText("PADLES");
  302. //if(canMinus){
  303. timer = game.time.create(false);
  304. // Set a TimerEvent to occur after 2 seconds
  305. timer.loop(2000, updateCounter, this);
  306. // Start the timer running - this is important!
  307. // It won't start automatically, allowing you to hook it to button events and the like.
  308. timer.start();
  309. }
  310. if (lifes < 0) {
  311. this.gameOver.setText("GAME OVER");
  312. someonediedd();
  313. }
  314. canHit = player.body.onFloor();
  315. isJumping = !canHit;
  316. game.physics.arcade.collide(enemy, layer, moved, null, this);
  317. game.physics.arcade.collide(ratcheck, layer, movi, null, this);
  318. if (countScoreAndTime == false) {
  319. navigator.vibrate(2000);
  320. }
  321. },
  322.  
  323.  
  324.  
  325. render:function() {
  326. // weapon.debug();
  327. // game.debug.text(player.frame, 32, 32);
  328. // game.debug.soundInfo(music, 20, 32);
  329.  
  330. // game.debug.body(player);
  331. // game.debug.spriteCoords(player, 32, 500);
  332. }
  333.  
  334. };
  335. //done
  336. function hitCoin(player, tile) {
  337. if (countScoreAndTime && player.key == 'move') {
  338. fx.play('ping');
  339. score++;
  340. map.removeTile(tile.x, tile.y, 'walls').destroy();
  341. }
  342. return true;
  343. }
  344.  
  345. //done
  346. function hitBricks(player, tile) {
  347. if (countScoreAndTime && player.key == 'move') {
  348. // fx.play('alien death');
  349. tile.setCollision(true, true, true, true);
  350. if (canHit == false && player.body.velocity.y < 0 && player.body.blocked.right == false && player.body.blocked.left == false) {
  351. map.removeTile(tile.x, tile.y, 'ground').destroy();
  352. }
  353. }
  354. return true;
  355. }
  356.  
  357. //done
  358. function grabBullet(sprite, tile) {
  359. if (countScoreAndTime && sprite.key == 'move') {
  360.  
  361. weapon.resetShots();
  362. canShoot = true;
  363. map.removeTile(tile.x, tile.y, 'ground').destroy();
  364. }
  365. return true;
  366. }
  367.  
  368. function hitHiden(sprite, tile) {
  369. if (countScoreAndTime && sprite.key == 'move') {
  370. if (canHit == false && player.body.velocity.y < 0 && player.body.blocked.right == false && player.body.blocked.left == false) {
  371.  
  372. //jezeli nad mamy cos fajnego to pokaz to
  373. var index2 = map.getTile(tile.x, tile.y, 'special', true).index;
  374. if (index2 == '16') {
  375. map.putTile(16, tile.x, tile.y, 'ground');
  376. } else if (index2 == '14') {
  377. fx.play('ping');
  378. map.putTile(14, tile.x, tile.y, 'ground');
  379. } else {
  380. }
  381. }
  382. }
  383. return true;
  384. }
  385.  
  386. function hitQBox(sprite, tile) {
  387. if (countScoreAndTime && sprite.key == 'move') {
  388. if (canHit == false && player.body.velocity.y < 0 && player.body.blocked.right == false && player.body.blocked.left == false) {
  389. var y = tile.y - 1;
  390. //jezeli nad mamy cos fajnego to pokaz to
  391. var index2 = map.getTile(tile.x, y, 'special', true).index;
  392. if (index2 == '45') {
  393. map.putTile(45, tile.x, y, 'ground');
  394. map.putTile(16, tile.x, tile.y, 'ground');
  395.  
  396. } else {
  397. fx.play('ping');
  398. score++;
  399. map.putTile(16, tile.x, tile.y, 'ground');
  400. }
  401. }
  402. }
  403. return true;
  404. }
  405.  
  406. function Castle(sprite, tile) {
  407. // fx.play('death');
  408. ScoreInfo.lifes = lifes;
  409. ScoreInfo.score = score;
  410. ScoreInfo.time = time;
  411. game.state.start('leveltwo', true, false, ScoreInfo);
  412. return true;
  413. }
  414.  
  415. function turnLeft() {
  416. if (countScoreAndTime) {
  417. player.body.x -= 0.05;
  418. player.body.velocity.x = -200;
  419. player.play("goLeft");
  420. }
  421. }
  422.  
  423. function turnRight() {
  424. if (countScoreAndTime) {
  425. player.body.x += 0.05;
  426. player.body.velocity.x = 200;
  427. player.play("goRight");
  428. }
  429. }
  430.  
  431. function fireF() {
  432. if (countScoreAndTime) {
  433. if (bulletsCounter > 0 && canShoot) {
  434.  
  435. shootTimer2 = game.time.create(false);
  436. shootTimer2.loop(5000, shootCheck, this);
  437. shootTimer2.start();
  438. fx.play('shot');
  439. weapon.fire();
  440. canShoot = false;
  441. }
  442. }
  443. }
  444.  
  445. function jump() {
  446. if (countScoreAndTime) {
  447. if (player.body.onFloor() && game.time.now > jumpTimer) {
  448. isJumping = true;
  449. // player.body.y -= 1;
  450. player.body.velocity.y = -200;
  451. player.animations.stop();
  452. }
  453. }
  454. }
  455. function hitEnemy(bullet, enemy) {
  456. if (countScoreAndTime) {
  457. bullet.kill();
  458. enemy.kill();
  459. score += 10;
  460. }
  461. }
  462. function deadByEnemy(player, enemy) {
  463. fx.play('death');
  464.  
  465. this.gameOver.setText("PADLES");
  466.  
  467. countScoreAndTime = false;
  468. timer = game.time.create(false);
  469. timer.loop(5000, updateCounter, this);
  470. timer.start();
  471.  
  472. }
  473. function updateCounter() {
  474. lifes--;
  475. game.state.restart();
  476.  
  477. }
  478. function shootCheck() {
  479. canShoot = true;
  480. }
  481. function actionOnClick() {
  482. }
  483. function someonediedd() {
  484. var database = firebase.database();
  485.  
  486. $("#game").hide();
  487. $("#formularz").show();
  488. $("#subbtn").click(function () {
  489. //alert($("input:text").val());
  490. writeUserData($("input:text").val(), score);
  491.  
  492. });
  493. }
  494. function moved(monster, platform) {
  495. var y = platform.y;
  496. var xplus = platform.x + 1;
  497. var xminus = platform.x - 1;
  498. var index2;
  499. if (y != null && xminus != null && xplus != null) {
  500. if (map.getTile(platform.x, y, 'ground', true).index != null) {
  501. index2 = map.getTile(platform.x, y, 'ground', true).index;
  502. }
  503. if (index2 != null && index2 != "") {
  504. if (!monster.hmovementloop) {
  505. var indeksplus = map.getTile(xplus, y, 'ground', true).index;
  506. var indeksminus = map.getTile(xminus, y, 'ground', true).index;
  507. if (indeksminus != '15' && indeksminus != '14' && indeksminus != '16' && indeksminus != '40') {
  508. enemy.setAll('body.velocity.x', 60);
  509. // monster.hmovementloop = game.add.tween(monster).to({ x: monster.x + 1 }, 10, "Linear", true, 0, -1, true);
  510. } else if (indeksplus != '15' && indeksplus != '14' && indeksplus != '16' && indeksplus != '40') {
  511. enemy.setAll('body.velocity.x', -60);
  512. // monster.hmovementloop = game.add.tween(monster).to({ x: monster.x - 1 }, 100, "Linear", true, 0, -1, true);
  513. }
  514. }
  515.  
  516. }
  517. }
  518. }
  519. function movi(monsterr, platformr) {
  520. // alert("DDA");
  521. // player.body.y -= 1;
  522. // player.body.velocity.y = -200;
  523. ratcheck.setAll('body.velocity.y', -80);
  524. // ratcheck.setAll('body.y', -1);
  525.  
  526. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement