Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Game = function () { };
- var ratcheck;
- var map;
- var player;
- var p2;
- var layer, layer1, layer2, specialLayer;
- var p;
- var shootTimer = 0;
- var enemy;
- var countScoreAndTime = true;
- var canMinus = true;
- var cursors;
- var weapon;
- var coordX, coordY;
- var isJumping = false;
- var jumpTimer = 0;
- var text;
- var buttonLeft, buttonRight, buttonJump, buttonFire;
- var right = false;
- var left = false;
- var jump = false;
- var fire = false;
- var time = 0;
- var score = 0, tempScore, minusScore;
- var canHit;
- var speed, platform;
- var lifes = 3;
- var bulletsCounter = 4;
- var playerAnimation;
- var questionObjectsArray = [];
- var onPlatform = false;
- var music;
- var fx;
- var canShoot = true;
- var ScoreInfo = {
- time: '0',
- score: '0',
- lifes:'0'
- };
- Game.prototype = {
- preload:function() {
- screen.orientation.lock('landscape');
- game.load.tilemap('mario', 'images/mario_map.json', null, Phaser.Tilemap.TILED_JSON);
- game.load.image('super_mario', 'images/super_mario.png');
- game.load.image('bullet', 'images/bullet.png');
- game.load.image('bullet2', 'images/bullet2.png');
- game.load.image('enemy', 'images/enemy.png');
- game.load.image('btLeft', 'images/dpad/left.png');
- game.load.image('btRight', 'images/dpad/right.png');
- game.load.image('btJump', 'images/dpad/jump.png');
- game.load.image('btFire', 'images/dpad/fire.png');
- game.load.image('ratcheck', 'images/ratcheck.png');
- game.load.spritesheet('move', 'images/hero_spritesheet.png', 340 / 8, 214 / 5, 48);
- game.load.audio('song', ['images/music/song.mp3', 'images/music/song.ogg']);
- game.load.audiosprite('sfx', 'images/music/fx_mixdown.ogg');
- game.load.script('textButton','scripts/textButton.js');
- },
- create: function () {
- 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");
- countScoreAndTime = true;
- bulletsCounter = 4;
- game.physics.startSystem(Phaser.Physics.ARCADE);
- game.stage.backgroundColor = '#787878';
- music = game.add.audio('song');
- music.volume = 0.2;
- // music.play();
- fx = game.add.audio('sfx');
- fx.allowMultiple = true;
- fx.addMarker('alien death', 1, 1.0);
- fx.addMarker('boss hit', 3, 0.5);
- fx.addMarker('escape', 4, 3.2);
- fx.addMarker('meow', 8, 0.5);
- fx.addMarker('numkey', 9, 0.1);
- fx.addMarker('ping', 10, 1.0);
- fx.addMarker('death', 12, 4.2);
- fx.addMarker('shot', 17, 1.0);
- fx.addMarker('squit', 19, 0.3);
- map = game.add.tilemap('mario');
- map.addTilesetImage('super_mario', 'super_mario');
- map.addTilesetImage('bullet2', 'bullet2');
- map.addTilesetImage('enemy', 'enemy');
- map.addTilesetImage('ratcheck', 'ratcheck');
- map.setCollisionBetween(0, 142, true, 'ground');
- map.setCollisionBetween(1, 1225, true, 'walls');
- map.setCollisionBetween(1, 1225, true, 'special');
- // 9,10 ,13//40 podloga //39 mapa//20+ rura//16 schodki//14 zapytajnik//13 flaga
- //15 brick//tileCall
- map.setTileIndexCallback(11, hitCoin, this, 'walls');
- map.setTileIndexCallback(15, hitBricks, this, 'ground');
- map.setTileIndexCallback(1, hitHiden, this, 'walls');
- map.setTileIndexCallback(14, hitQBox, this, 'ground');
- map.setTileIndexCallback(45, grabBullet, this, 'ground');
- // map.setTileIndexCallback(9, reachCastle, this, 'ground');
- // map.setTileIndexCallback(17, reachCastle, this, 'ground');
- map.setTileIndexCallback(13, Castle, this, 'ground');
- // map.setTileIndexCallback(10, reachCastle, this, 'ground');
- layer1 = map.createLayer('background');
- layer2 = map.createLayer('walls');
- layer = map.createLayer('ground');
- layer.resizeWorld();
- layer1.resizeWorld();
- layer2.resizeWorld();
- player = game.add.sprite(0, 100, 'move');
- player.anchor.set(0.5);
- // playerAnimation = player.animations.add('walk');
- player.animations.add("goLeft", [8, 13], 10, true);
- player.animations.add("goRight", [25, 26], 10, true);
- //objects
- enemy = game.add.group();
- enemy.enableBody = true;
- enemy.physicsBodyType = Phaser.Physics.ARCADE;
- ratcheck = game.add.group();
- ratcheck.enableBody = true;
- ratcheck.physicsBodyType = Phaser.Physics.ARCADE;
- map.createFromObjects('enemies', 46, 'enemy', 0, true, false, enemy);
- map.createFromObjects('enemies', 357, 'ratcheck', 0, true, false, ratcheck);
- game.physics.arcade.enable(enemy);
- game.physics.arcade.enable(ratcheck);
- game.physics.arcade.enable('enemies');
- // game.physics.arcade.enable('ratcheck');
- // game.physics.arcade.enable('enemies');
- // enemy.callAll('anchor.setTo', 'anchor', 0.5, 1.0);
- enemy.setAll('body.velocity.x', 10);
- enemy.setAll('body.gravity.y', 250);
- // ratcheck.setAll('body.velocity.x', 40);
- ratcheck.setAll('body.gravity.y', 250);
- game.physics.arcade.enable(player);
- game.physics.arcade.enable(layer);
- game.physics.arcade.enable(layer2);
- player.body.gravity.y = 250;
- player.body.setSize(14, 14, 14, 14);
- player.body.collideWorldBounds = true;
- //pad
- buttonLeft = game.add.button(window.innerWidth * .10, window.innerHeight - 100, 'btLeft', null, this, 0);
- buttonLeft.scale.setTo(1, 1);
- buttonRight = game.add.button(window.innerWidth * .30, window.innerHeight - 100, 'btRight', null, this, 0);
- buttonRight.scale.setTo(1, 1);
- buttonJump = game.add.button(window.innerWidth * .60, window.innerHeight - 100, 'btJump', null, this, 0);
- buttonJump.scale.setTo(1, 1);
- buttonFire = game.add.button(window.innerWidth * .80, window.innerHeight - 100, 'btFire', null, this, 0);
- buttonFire.scale.setTo(1, 1);
- buttonLeft.fixedToCamera = true;
- buttonRight.fixedToCamera = true;
- buttonJump.fixedToCamera = true;
- buttonFire.fixedToCamera = true;
- buttonLeft.onInputDown.add(function () {
- left = true
- }, this);
- buttonLeft.onInputOver.add(function () {
- left = true
- }, this);
- buttonLeft.onInputUp.add(function () {
- left = false
- }, this);
- buttonLeft.onInputOut.add(function () {
- left = false
- }, this);
- buttonRight.onInputDown.add(function () {
- right = true
- }, this);
- buttonRight.onInputOver.add(function () {
- right = true
- }, this);
- buttonRight.onInputUp.add(function () {
- right = false
- }, this);
- buttonRight.onInputOut.add(function () {
- right = false
- }, this);
- buttonJump.onInputDown.add(function () {
- jump = true
- }, this);
- buttonJump.onInputOver.add(function () {
- jump = true
- }, this);
- buttonJump.onInputUp.add(function () {
- jump = false
- }, this);
- buttonJump.onInputOut.add(function () {
- jump = false
- }, this);
- buttonFire.onInputDown.add(function () {
- fire = true
- }, this);
- buttonFire.onInputOver.add(function () {
- fire = true
- }, this);
- buttonFire.onInputUp.add(function () {
- fire = false
- }, this);
- buttonFire.onInputOut.add(function () {
- fire = false
- }, this);
- weapon = game.add.weapon(4, 'bullet');
- weapon.bulletKillType = Phaser.Weapon.KILL_CAMERA_BOUNDS;
- weapon.bulletAngleOffset = 90;
- weapon.bulletSpeed = 600;
- weapon.fireLimit = 4;
- weapon.trackSprite(player, 0, 0, true);
- //text
- var style = { font: "20px Courier", fill: "#fff", tabs: 132 };
- var style2 = { font: "40px Courier", fill: "#fff", tabs: 132 };
- text = game.add.text(10, 10, "Lifes:" + lifes, style);
- this.text2 = game.add.text(window.innerWidth / 2, 10, "Time:" + time, style);
- this.text3 = game.add.text(window.innerWidth -150, 10, "Score:" + score, style);
- this.text4 = game.add.text(window.innerWidth -150 , 30, "Bullets" + bulletsCounter, style);
- this.gameOver = game.add.text( (window.innerWidth / 2) - 100, (window.innerHeight / 2 )-100, "", style2);
- //camera
- text.fixedToCamera = true;
- this.text2.fixedToCamera = true;
- this.text3.fixedToCamera = true;
- this.text4.fixedToCamera = true;
- this.gameOver.fixedToCamera = true;
- game.camera.follow(player);
- game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT;
- cursors = game.input.keyboard.createCursorKeys();
- },
- update: function() {
- player.body.velocity.x = 0;
- game.physics.arcade.collide(player, layer);
- game.physics.arcade.collide(player, layer2);
- game.physics.arcade.collide(player, this.bricks);
- game.physics.arcade.collide(player, enemy,deadByEnemy,null,this);
- game.physics.arcade.collide(weapon.bullets, enemy, hitEnemy, null, this);
- text.setText("Lifes:" + lifes);
- if (countScoreAndTime) {
- time += 1;
- }
- bulletsCounter = 4 - weapon.shots;
- this.text2.setText("Time:" + time);
- this.text3.setText("Score: " + score);
- this.text4.setText("Bullets: " + bulletsCounter);
- if (left) {
- turnLeft();
- isJumping = false;
- }
- else if (right) {
- turnRight();
- isJumping = false;
- }
- else if (jump) {
- if (player.body.onFloor() && game.time.now > jumpTimer) {
- player.body.y -= 1;
- player.body.velocity.y = -200;
- player.animations.stop();
- isJumping = true;
- }
- } else if (fire) {
- isJumping = false;
- fireF();
- }
- if (player.body.onFloor() && player.body.y > 210) {
- fx.play('death');
- // navigator.vibrate(2000);
- countScoreAndTime = false;
- this.gameOver.setText("PADLES");
- //if(canMinus){
- timer = game.time.create(false);
- // Set a TimerEvent to occur after 2 seconds
- timer.loop(2000, updateCounter, this);
- // Start the timer running - this is important!
- // It won't start automatically, allowing you to hook it to button events and the like.
- timer.start();
- }
- if (lifes < 0) {
- this.gameOver.setText("GAME OVER");
- someonediedd();
- }
- canHit = player.body.onFloor();
- isJumping = !canHit;
- game.physics.arcade.collide(enemy, layer, moved, null, this);
- game.physics.arcade.collide(ratcheck, layer, movi, null, this);
- if (countScoreAndTime == false) {
- navigator.vibrate(2000);
- }
- },
- render:function() {
- // weapon.debug();
- // game.debug.text(player.frame, 32, 32);
- // game.debug.soundInfo(music, 20, 32);
- // game.debug.body(player);
- // game.debug.spriteCoords(player, 32, 500);
- }
- };
- //done
- function hitCoin(player, tile) {
- if (countScoreAndTime && player.key == 'move') {
- fx.play('ping');
- score++;
- map.removeTile(tile.x, tile.y, 'walls').destroy();
- }
- return true;
- }
- //done
- function hitBricks(player, tile) {
- if (countScoreAndTime && player.key == 'move') {
- // fx.play('alien death');
- tile.setCollision(true, true, true, true);
- if (canHit == false && player.body.velocity.y < 0 && player.body.blocked.right == false && player.body.blocked.left == false) {
- map.removeTile(tile.x, tile.y, 'ground').destroy();
- }
- }
- return true;
- }
- //done
- function grabBullet(sprite, tile) {
- if (countScoreAndTime && sprite.key == 'move') {
- weapon.resetShots();
- canShoot = true;
- map.removeTile(tile.x, tile.y, 'ground').destroy();
- }
- return true;
- }
- function hitHiden(sprite, tile) {
- if (countScoreAndTime && sprite.key == 'move') {
- if (canHit == false && player.body.velocity.y < 0 && player.body.blocked.right == false && player.body.blocked.left == false) {
- //jezeli nad mamy cos fajnego to pokaz to
- var index2 = map.getTile(tile.x, tile.y, 'special', true).index;
- if (index2 == '16') {
- map.putTile(16, tile.x, tile.y, 'ground');
- } else if (index2 == '14') {
- fx.play('ping');
- map.putTile(14, tile.x, tile.y, 'ground');
- } else {
- }
- }
- }
- return true;
- }
- function hitQBox(sprite, tile) {
- if (countScoreAndTime && sprite.key == 'move') {
- if (canHit == false && player.body.velocity.y < 0 && player.body.blocked.right == false && player.body.blocked.left == false) {
- var y = tile.y - 1;
- //jezeli nad mamy cos fajnego to pokaz to
- var index2 = map.getTile(tile.x, y, 'special', true).index;
- if (index2 == '45') {
- map.putTile(45, tile.x, y, 'ground');
- map.putTile(16, tile.x, tile.y, 'ground');
- } else {
- fx.play('ping');
- score++;
- map.putTile(16, tile.x, tile.y, 'ground');
- }
- }
- }
- return true;
- }
- function Castle(sprite, tile) {
- // fx.play('death');
- ScoreInfo.lifes = lifes;
- ScoreInfo.score = score;
- ScoreInfo.time = time;
- game.state.start('leveltwo', true, false, ScoreInfo);
- return true;
- }
- function turnLeft() {
- if (countScoreAndTime) {
- player.body.x -= 0.05;
- player.body.velocity.x = -200;
- player.play("goLeft");
- }
- }
- function turnRight() {
- if (countScoreAndTime) {
- player.body.x += 0.05;
- player.body.velocity.x = 200;
- player.play("goRight");
- }
- }
- function fireF() {
- if (countScoreAndTime) {
- if (bulletsCounter > 0 && canShoot) {
- shootTimer2 = game.time.create(false);
- shootTimer2.loop(5000, shootCheck, this);
- shootTimer2.start();
- fx.play('shot');
- weapon.fire();
- canShoot = false;
- }
- }
- }
- function jump() {
- if (countScoreAndTime) {
- if (player.body.onFloor() && game.time.now > jumpTimer) {
- isJumping = true;
- // player.body.y -= 1;
- player.body.velocity.y = -200;
- player.animations.stop();
- }
- }
- }
- function hitEnemy(bullet, enemy) {
- if (countScoreAndTime) {
- bullet.kill();
- enemy.kill();
- score += 10;
- }
- }
- function deadByEnemy(player, enemy) {
- fx.play('death');
- this.gameOver.setText("PADLES");
- countScoreAndTime = false;
- timer = game.time.create(false);
- timer.loop(5000, updateCounter, this);
- timer.start();
- }
- function updateCounter() {
- lifes--;
- game.state.restart();
- }
- function shootCheck() {
- canShoot = true;
- }
- function actionOnClick() {
- }
- function someonediedd() {
- var database = firebase.database();
- $("#game").hide();
- $("#formularz").show();
- $("#subbtn").click(function () {
- //alert($("input:text").val());
- writeUserData($("input:text").val(), score);
- });
- }
- function moved(monster, platform) {
- var y = platform.y;
- var xplus = platform.x + 1;
- var xminus = platform.x - 1;
- var index2;
- if (y != null && xminus != null && xplus != null) {
- if (map.getTile(platform.x, y, 'ground', true).index != null) {
- index2 = map.getTile(platform.x, y, 'ground', true).index;
- }
- if (index2 != null && index2 != "") {
- if (!monster.hmovementloop) {
- var indeksplus = map.getTile(xplus, y, 'ground', true).index;
- var indeksminus = map.getTile(xminus, y, 'ground', true).index;
- if (indeksminus != '15' && indeksminus != '14' && indeksminus != '16' && indeksminus != '40') {
- enemy.setAll('body.velocity.x', 60);
- // monster.hmovementloop = game.add.tween(monster).to({ x: monster.x + 1 }, 10, "Linear", true, 0, -1, true);
- } else if (indeksplus != '15' && indeksplus != '14' && indeksplus != '16' && indeksplus != '40') {
- enemy.setAll('body.velocity.x', -60);
- // monster.hmovementloop = game.add.tween(monster).to({ x: monster.x - 1 }, 100, "Linear", true, 0, -1, true);
- }
- }
- }
- }
- }
- function movi(monsterr, platformr) {
- // alert("DDA");
- // player.body.y -= 1;
- // player.body.velocity.y = -200;
- ratcheck.setAll('body.velocity.y', -80);
- // ratcheck.setAll('body.y', -1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement