9 years ago by EnMod
Anyone try to apply tile-based movement similar to the code in the below thread to a TwoPointFive level?
http://impactjs.com/forums/code/tile-based-movement
That's currently something I'm really looking to implement but I am having trouble translating into TPF logic. Basically I want to make something similar to those old first-person dungeons, much like http://www.playkeepout.com
EDIT: I've got...something working with a kind-of convoluted solution I cooked up, using Super Blob Blaster as my base with custom tiles. I've created a variable for direction and have switch blocks to determine where to go depending on where the player is facing. I changed turn speed to 90 degrees and have each turn update the direction variable accordingly. Test it out here: https://teach.mccc.edu/impacttest/
The important bits of the code are below, unchanged code is in "...":
http://impactjs.com/forums/code/tile-based-movement
That's currently something I'm really looking to implement but I am having trouble translating into TPF logic. Basically I want to make something similar to those old first-person dungeons, much like http://www.playkeepout.com
EDIT: I've got...something working with a kind-of convoluted solution I cooked up, using Super Blob Blaster as my base with custom tiles. I've created a variable for direction and have switch blocks to determine where to go depending on where the player is facing. I changed turn speed to 90 degrees and have each turn update the direction variable accordingly. Test it out here: https://teach.mccc.edu/impacttest/
The important bits of the code are below, unchanged code is in "...":
... .defines(function(){ EntityPlayer = tpf.Entity.extend({ type: ig.Entity.TYPE.A, collides: ig.Entity.COLLIDES.PASSIVE, size: {x: 64, y: 64}, angle: 0, internalAngle: 0, turnSpeed: (90).toRad(), moveSpeed: 192, direction: 1, health: 100, tileSize: 64, ... update: function() { if (this.direction < 1){ this.direction = 4; } else if (this.direction > 4){ this.direction = 1; } // Move var dx = 0, dy = 0; if( ig.input.pressed('forward') ) { switch(this.direction){ // if north case 1: this.pos.y -= this.tileSize; break; // if east case 2: this.pos.x += this.tileSize; break; // if south case 3: this.pos.y += this.tileSize; break; // if west case 4: this.pos.x -= this.tileSize; break; } dy = -1; } else if( ig.input.pressed('back') ) { switch(this.direction){ // if north case 1: this.pos.y += this.tileSize; break; // if east case 2: this.pos.x -= this.tileSize; break; // if south case 3: this.pos.y -= this.tileSize; break; // if east case 4: this.pos.x += this.tileSize; break; } dy = 1; } // Turn viewpoint with mouse? // if( ig.system.isFullscreen || ig.system.hasMouseLock ) { // this.internalAngle -= ig.input.mouseDelta.x / 400; // } // Turn with keys if( ig.input.pressed('left') ) { this.internalAngle += this.turnSpeed; this.direction -= 1; } else if( ig.input.pressed('right') ) { this.internalAngle -= this.turnSpeed; this.direction += 1; } // Sidestep if( ig.input.pressed('stepleft') ) { switch(this.direction){ // if north case 1: this.pos.x -= this.tileSize; break; // if east case 2: this.pos.y -= this.tileSize; break; // if south case 3: this.pos.x += this.tileSize; break; // if west case 4: this.pos.y += this.tileSize; break; } dx = -1; } else if( ig.input.pressed('stepright') ) { switch(this.direction){ // if north case 1: this.pos.x += this.tileSize; break; // if east case 2: this.pos.y += this.tileSize; break; // if south case 3: this.pos.x -= this.tileSize; break; // if west case 4: this.pos.y -= this.tileSize; break; } dx = 1; } ... // Set the desired velocity based on our angle and which keys are // pressed this.vel.x = -Math.sin(this.angle) * dy -Math.sin(this.angle+Math.PI/2) * dx; this.vel.y = -Math.cos(this.angle) * dy -Math.cos(this.angle+Math.PI/2) * dx; ... this.parent(); ... }); });