none
How to create (good) collision box without lagging? (For a platformer game) RRS feed

  • Question

  • Disclaimer: I know I said earlier in the past that I just wanted an engine and give up on creating the platformer myself, but I've decided to take another stab at it, and try again; this time, I'm asking about something that has actually stumped me for quite some time. Besides, I'm honestly not sure if I can even figure out the code in the earlier Dirt Bike game example litdev mentioned a while back, not that I'm unwilling or anything. lol.

    Also, I plan on doing this without LD or LDPhysics, or other addons, since I feel like it'll be much easier than working with an engine or an add-on (I still might be able to use an engine or add-on much more easily, but I've decided that (trying) from-scratch would be the easier way to go for me personally imo). If you feel like and/or insist I'll be much better off with LD or LDPhysics, however, please let me know and show me, including examples, perhaps besides the Dirt Bike project. Thanks.

    Foreword Bonus: Being such an inexperienced programmer that I am, I'll probably be asking a lot of questions throughout my time learning programming. So you might find yourself answering a lot of my questions on my quest to become professional coder. I know that wasn't really necessary, but I just wanted to show that off and let people know about that so they do. lol.

    Main Point:

    I've been trying to work on a collision box for a character in my game so that collisions can be more flexible and there can be proper, realistic collision, for example. But not only does my current code lag the game to a crawl, it doesn't even work fully properly. If going left on a slope, going up produces some weird movement, and I can't even go down slopes at all going backwards; she just falls right off. I've also noticed other weird behavior even going forward (right), but I won't list it all here because you probably get the gist of it by now.

    Here's the code. I know it's terribly inefficient, but I couldn't think of any other way to deal with the collision box:

      For XColScan = 0 To 31
        If on_ground = 0 Then
          ground_reach = GraphicsWindow.GetPixel(CharX + XColScan, CharY + 40)
          If ground_reach = "#FF0000" Then
            v_spd = 0
            on_ground = 1
          EndIf
        EndIf
      EndFor

    Basically, I really need help here with this part. I've spent hours upon hours on the problem and still haven't solved it, so it would be nice to help me out and find me a much better alternative to this code. It can even be just entirely new code of your own or showing off a feature of SmallBasic or something else entirely new (to me) that I've never known before.

    I'll also provide the slope code if you need it for further clarification.

    Thanks for the help. Please have a nice day.

    Thursday, August 1, 2019 11:50 PM

Answers

All replies