CHANNELS:

All
rafaelrpq posted 2 months ago
rafaelrpq posted 17 days ago

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

0

Want to participate?

Create a free Chris Courses account to begin

or
Sign In

Providing the lift to launch your development career

© 2025 Chris Courses. All rights reserved.