Hello there!!! I'm back with an initial implementation. It's can be buggy, but for a frist test, it works.
In Player.js class
collideSlope (block) {
let m = 1 / parseInt (block.value.substring(0, 2))
let c = parseInt (block.value[2]) * block.height * m;
let ratio = this.height / this.width;
if (m < 0) {
this.pos.y = block.pos.y - (this.height / ratio) + c - (this.pos.x + this.width - block.pos.x) * Math.abs(m);
} else {
this.pos.y = block.pos.y - (this.height / ratio) + c - (block.height - (this.pos.x - block.pos.x) * Math.abs(m));
}
this.vel.y = 0;
return;
}
I defined '#', '10', '20', '21' as block value. Where:
# : all sides collisions;
10: 1 block slope. diagonal from 0 to full height;
2 blocks to get full slope
20: diagonal 0 to half height;
21: half height to full height;
My code is available in https://github.com/rafaelrpq/platformer
Want to participate?
Create a free Chris Courses account to begin