Advertisement
XArnonX

game

Feb 16th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2.  
  3.   'use strict';
  4.  
  5.  
  6.   // constants
  7.   var GAME_WIDTH = 1100, // 240
  8.       GAME_HEIGHT = 1100, // 160
  9.       DEBUG = true;
  10.   /*var GAME_WIDTH = MapConstants.NUM_COLUMNS * MapConstants.TILE_SIZE, // 240
  11.       GAME_HEIGHT = MapConstants.NUM_ROWS * MapConstants.TILE_SIZE, // 160
  12.       DEBUG = true;*/
  13.  
  14.   // vars
  15.   var _game = null,
  16.       _map = null,
  17.       _player = null,
  18.       _ausgang = null,
  19.  
  20.       // controls
  21.       _dpad = {
  22.         up: null,
  23.         right: null,
  24.         down: null,
  25.         left: null
  26.       },
  27.       _isUpPressed = false,
  28.       _isRightPressed = false,
  29.       _isDownPressed = false,
  30.       _isLeftPressed = false,
  31.       _keyboardInput = null;
  32.  
  33.  
  34.   // auto initialization
  35.   init();
  36.  
  37.  
  38.   // init
  39.   function init() {
  40.     initPhaser();
  41.  
  42.     // uncomment the following lines
  43.     // to use the HTML buttons
  44.      //getDOMButtons();
  45.      //addDOMListeners();
  46.   }
  47.  
  48.   // phaser methods
  49.   function initPhaser() {
  50.     // add game
  51.     _game = new Phaser.Game(
  52.       GAME_WIDTH, GAME_HEIGHT,
  53.       Phaser.CANVAS, 'phaser-js-test',
  54.       {
  55.         preload: preload,
  56.         create: create,
  57.         update: update,
  58.         render: render
  59.       }
  60.     );
  61.  
  62.     // create map
  63.     _map = new Map(_game);
  64.  
  65.     // create player
  66.     _player = new Player(_game, _map);
  67.  
  68.     //Erschaffe Ausgang
  69.     //_sammelobjekte = new Sammelobjekte(_game, _map);
  70.  
  71.     _ausgang = new Ausgang(_game, _map);
  72.  
  73.   }
  74.  
  75.   function preload() {
  76.     _map.preload();
  77.     _player.preload();
  78.     _ausgang.preload();
  79.     //_ojects.preload();
  80.   }
  81.  
  82.   function create() {
  83.  
  84.     _game.physics.startSystem(Phaser.Physics.ARCADE);
  85.     // set references
  86.     _keyboardInput = _game.input.keyboard;
  87.  
  88.     //_game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
  89.    
  90.     //have the game centered horizontally
  91.     //_game.scale.pageAlignHorizontally = true;
  92.     //_game.scale.pageAlignVertically = true;
  93.  
  94.     // init game objects
  95.     _map.init();
  96.  
  97.     _player.init();
  98.  
  99.     _ausgang.init()
  100.     //_objects.init([{x,y},{x,y},{x,y},{x,y},{x,y},{x,y},{x,y},{}]);
  101.  
  102.     //Kopie player_init
  103.     //_player.init({x: 1, y: 1})
  104.   }
  105.  
  106.   function update() {
  107.     _player.update(
  108.       _keyboardInput.isDown(Phaser.Keyboard.UP) || _isUpPressed,
  109.       _keyboardInput.isDown(Phaser.Keyboard.RIGHT) || _isRightPressed,
  110.       _keyboardInput.isDown(Phaser.Keyboard.DOWN) || _isDownPressed,
  111.       _keyboardInput.isDown(Phaser.Keyboard.LEFT) || _isLeftPressed
  112.     );
  113.   //_game.physics.arcade.overlap(Player, Ausgang, aufsammeln, null);
  114.   }
  115.     //aufsammeln: function(Player, Ausgang) {
  116.      //console.log('Test');
  117.    // findObjectsByType('SammelID', this.map, 'Spielobjekte');
  118.     //forEach(function(element){
  119.    //if(this.Sammelstatus== SammelID) {
  120.     //aufsammelbares.destroy();
  121.    // this.Sammelstatus++;
  122.   // }
  123.  
  124.  
  125.     //remove sprite
  126.     //Ausgang.destroy();
  127.   //},
  128.     //Muss vorhanden sein, Inhalt deaktiviert, damit die Kollisionskacheln beim Spieler nicht angezeigt werden
  129.   function render() {
  130.     if(DEBUG) {
  131.       _map.drawSurroundingCollisions();
  132.     }
  133.   }
  134.  
  135.  
  136.  
  137.   // dom methods
  138.   function getDOMButtons() {
  139.     _dpad.up = document.getElementById('dpad-up');
  140.     _dpad.right = document.getElementById('dpad-right');
  141.     _dpad.down = document.getElementById('dpad-down');
  142.     _dpad.left = document.getElementById('dpad-left');
  143.   }
  144.  
  145.   function addDOMListeners() {
  146.     // pressed (mouse events)
  147.     _dpad.up.addEventListener('mousedown', onUpPressed);
  148.     _dpad.right.addEventListener('mousedown', onRightPressed);
  149.     _dpad.down.addEventListener('mousedown', onDownPressed);
  150.     _dpad.left.addEventListener('mousedown', onLeftPressed);
  151.  
  152.     // pressed (touch events)
  153.     _dpad.up.addEventListener('touchstart', onUpPressed);
  154.     _dpad.right.addEventListener('touchstart', onRightPressed);
  155.     _dpad.down.addEventListener('touchstart', onDownPressed);
  156.     _dpad.left.addEventListener('touchstart', onLeftPressed);
  157.  
  158.     // released (mouse events)
  159.     _dpad.up.addEventListener('mouseup', onUpReleased);
  160.     _dpad.right.addEventListener('mouseup', onRightReleased);
  161.     _dpad.down.addEventListener('mouseup', onDownReleased);
  162.     _dpad.left.addEventListener('mouseup', onLeftReleased);
  163.  
  164.     // released (mouse events)
  165.     _dpad.up.addEventListener('touchend', onUpReleased);
  166.     _dpad.right.addEventListener('touchend', onRightReleased);
  167.     _dpad.down.addEventListener('touchend', onDownReleased);
  168.     _dpad.left.addEventListener('touchend', onLeftReleased);
  169.   }
  170.  
  171.   function onUpPressed() {
  172.     _isUpPressed = true;
  173.   }
  174.  
  175.   function onRightPressed() {
  176.     _isRightPressed = true;
  177.   }
  178.  
  179.   function onDownPressed() {
  180.     _isDownPressed = true;
  181.   }
  182.  
  183.   function onLeftPressed() {
  184.     _isLeftPressed = true;
  185.   }
  186.  
  187.   function onUpReleased() {
  188.     _isUpPressed = false;
  189.   }
  190.  
  191.   function onRightReleased() {
  192.     _isRightPressed = false;
  193.   }
  194.  
  195.   function onDownReleased() {
  196.     _isDownPressed = false;
  197.   }
  198.  
  199.   function onLeftReleased() {
  200.     _isLeftPressed = false;
  201.   }
  202.  
  203. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement