Giter Club home page Giter Club logo

mini2dplatformer's Introduction

mini2dplatformer's People

Contributors

vicksonzero avatar xem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mini2dplatformer's Issues

hero_x calculation cannot work against ceiling if hero_y is pre-moved

when jumping against a ceiling, and the player is also moving along the x-axis,

the player will be snapped to a wrong x value.

By logging the tile x,y values, i found that the hero_y is checking the ceiling tiles instead of the empty tiles along the x-axis.

2 solutions exist:

  • resolve hero_y first, so that hero_y cannot be inside tiles
    • move this to before line 101

      mini2DPlatformer/index.html

      Lines 143 to 154 in c7036a3

      if(hero_vy < 0){
      // Get the value of the tiles at the top corners of the hero
      tile1 = map[Math.floor(hero_y)][Math.floor(hero_x)];
      tile2 = map[Math.floor(hero_y)][Math.floor(hero_x + hero_w - .1)];
      // If this tile is solid, put the hero on the bottom side of it and make him fall
      if(tile1 == 1 || tile2 == 1){
      hero_y = Math.ceil(hero_y);
      hero_vy = 0;
      }
      }
      , or
  • add hero_vy onto hero_y after the hero_x resolution code,

Gravity calculation is not natural

Hi thank you for letting me use your project as a minimal platformer starter.

just a comment on the custom physics:

hero_ay += g;
hero_vy += hero_ay;

here, adding g to the acceleration makes the player drop at increasing acceleration, aka going cubic instead of parabola

I believe the correct way is to add g to hero_vy every frame instead. Like this:

-  hero_ay += g;
+  hero_vy += g;
   hero_vy += hero_ay;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.