1 decade ago
by Gamma
Hello everyone, recently I have been thinking about making interactive doors to be incorporated into my game, to give the player a feel for what might be inside someones house...or something, yet I don't know how I'd do that. My goal is to make the user click on the UP arrow when next to a door, and he or she will enter that door to a new area, kind of like in Cave Story. Does anyone know how to do this? I've seen a couple of games in impact have this accomplished.
1 decade ago
by Jerczu
Easy... You know you can create pseudo entities in Impact like triggers, killzones etc. Just create one of these position them where your door graphic appear then on collision with player check if up arrow was pressed.
1 decade ago
by fulvio
I haven't really tested this code, but give something like this a go. I hope it helps.
Door Entity:
ig.module(
'game.entities.door')
.requires(
'impact.entity')
.defines(function() {
EntityDoor = ig.Entity.extend({
size: {
x: 16,
y: 16
},
zIndex: -1,
// Load image resource.
animSheet: new ig.AnimationSheet('media/sprites/door.png', 16, 16),
init: function(x, y, settings) {
this.parent(x, y, settings);
// Specify which icon to use.
this.addAnim('idle', 0.1, [0], true);
// Set current icon.
this.currentAnim = this.anims.idle;
},
ready: function() {
// Make door entity invisible in-game.
// delete this.currentAnim;
},
update: function() {
// Call parent.
this.parent();
}
});
})
Implementation:
// Interact with the faced tile (don't forget to assign the UP_ARROW to call action()).
action: function() {
// Get all doors.
var doors = ig.game.getEntitiesByType(EntityDoor);
// Check that at least one door exists.
if (doors) {
for (var i = 0; i < doors.length; i++) {
// Check if the tile is located at the faced tile.
var distanceToDoor = this.distanceTo(doors[i]);
if (distanceToDoor <= this.size.x * 2) {
// enter the door
}
}
}
}
1 decade ago
by Jerczu
I think you'll gain more if you do it in DoorEntity's check function and give them check against player type and on collision find out whether up key was pressed rather than on each tick iterate through the whole array of doors and check if player is anywhere near.
Seems like a simple if statement would suffice. You have a player entity and a door entity... forgive my lack of actual code here.
range=range you want
if keypressed==up&&Math.abs(player.pos.x-door.pos.x)<range and pos.y (within range you want) run your function.
use absolute value if you want them to be able to do it from left or right... use actual value for Y if you only want the door accessible from one direction IOW the player must be below the door (or "south" of it) to go in.
Page 1 of 1
« first
« previous
next ›
last »