hg_tg

Members
  • Content Count

    2
  • Joined

  • Last visited

  1. hg_tg

    Recursive Collision

    Hi all, I have been stuck for some time on procedurally generating levels for my game. As it stands, I have created rooms in a confined space but most of them overlap. Although this is expected, I can't find a way to separate them. My attempts have been centered around physics collisions, but I have failed hard. Here is my current code: Level.prototype.separate = function() { //For Convenince sake var arcade = this.game.physics.arcade, rooms = this.rooms; for ( var i = 0; i < rooms.length - 1; i++ ) { while ( arcade.intersects( rooms[ i ], rooms[ i + 1 ] ) ) { arcade.collide( rooms[ i ], rooms[ i + 1 ] ); } } //For testing purposes this.displayLevel(); }, Level.prototype.create = function() { this.game.physics.arcade.enable( this.rooms ); this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; //Gets coordinates and dimensions for Rooms and creates them. this.createLevel(); console.log( "Level State Completed" ); //this.game.state.start( 'InGameState' ); }, Level.prototype.update = function() { this.separate(); } This doesn't work. It results in an infinite loop. I have tried used Arcade's overlap as well. The issues I have had boil down to these two questions: 1. How can I test for individual room collisions when they sit in an array together? 2. When two rooms collide with one another, one or both of the rooms may still be colliding with other rooms. However, Arcade's collide method isn't recursive, and throwing the separate function into update might not guarantee the rooms be separated and hurts performance. Does anyone have any ideas or potential solutions to this?
  2. hg_tg

    Including a local app.js

    I am confused in regard to including external Javascript files to the HTML. Essentially, I don't want to have the all of the game's data sitting in the client. Here is what I don't want, even it works. Here is what I wish to work, but it doesn't. I have also included the app.js, if needed or relevant. Let me know if you guys have a clue as to what is going wrong.