Closed SpenceSellers closed 8 years ago
That sounds fine to me. Do we want multiple paired tiles or just one set? I would prefer one, personally, but I'm open to more.
I've added a second layer to the game (visibility set to false) which only has collision on teleport tiles. This allows us to handle the player entering a teleport tile with the standard Phaser collision mechanism. You'll teleport upon entering the tile, as opposed to leaving the tile, like in the original Pac-Man, but it's way less work for us this way.
I currently have the game track its teleport tiles in an array and I was thinking we'd just teleport the player to the next tile in the list. If we wanted to "pair" tiles together, we can change that to an array of tuples, but that involves more checking on map initialization.
After poking around for 30 minutes, I have no idea how to actually implement the teleportation itself. Just changing the x and y values of the player object does not behave as expected. Anybody got any thoughts?
Amend that last statement - apparently changing the x and y work as intended, but I've handled the second layer incorrectly. Fix should be incoming shortly.
Last thing I pulled broke the broad for me..but i got teleport working..change the update method in game.ts to:
update(): void {
//dot collision
this.game.physics.arcade.overlap(this.player, this.smallDot, (creature, dot) => {
this.smallDot.destroy();
//console.log(this.game)
this.score += 42;
this.scoreText.text = 'Score:' + this.score;
});
this.game.physics.arcade.collide(this.player, this.layer);
this.game.physics.arcade.collide(this.player, this.layer, (s, t) => {
console.log("Collide " + s + " " + t)
});
console.log(this.player.x + " " + this.player.y)
if (this.player.x < 16 && this.player.y == 304) {
this.player.reset(624, 304)
this.player.setDesiredDirection(map.Direction.WEST); //Continues movement
}
if (this.player.x > 624 && this.player.y == 304) {
this.player.reset(16, 304)
this.player.setDesiredDirection(map.Direction.EAST); //Continues movement
}
}
What did you pull, and how did it break things? Did bumping into anything reset your position? 'Cause that's the broken dual-layer behavior.
Resetting is a good find, and probably what we're going to want for pacman death, but given that it seems to halt the player's movement, I'm betting it's not what we want for teleportation - we want to preserve as much of the current state of the game as we can and only change the player's position.
Regardless, after spending more time looking for a quick fix than I anticipated, I have arrived at the conclusion that my second-layer approach is basically doomed unless we want to write two tilesets for every map we want to implement, which is completely unfeasible.
The approach I'm looking at now is to set callbacks for the teleport tile id. This seems to be the behavior we're looking for (triggers some function when the player collides with that tile), but I'm somewhat uncertain how to check which tile you collided with in this method. (Callbacks are another feature of Javascript I suck at.)
Push ETA: 15 minutes.
Alan check the update to the code above.. should continue movement now..Also after reading your previous comment I assume what I called "broken board" was a layers visibility being set to false and the broken dual layer behavior you just spoke of
Yeah, that code will work for this map, but it won't scale to additional maps well. We need a solution that will work for any map we want to hand the game, since we promised multiple maps.
Implemented the TileIDCallback stuff. Seems to be working on my end. Gonna turn in for the evening - let me know what's broken (because I'm sure _some_thing is) and I'll try to fix it before work tomorrow.
I propose that this feature is implemented by a pair of 'teleport tiles' that, when entered, teleport a Creature to its paired tile.