• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

best way to collide with different tiles?

Dubbsta

Active member
Joined
Jul 13, 2017
Messages
208
im trying different methods to collide with different tiles. so far i tried lists and it worked. i made 6 different size rects and was able to collide with all 6 with one call, but it doesnt seem right to use lilst on an entire level, thats a ton of addlast calls.

This time im trying map[][] =[[0,0,0], arrays where i would try to coll. with 1 and 2 with this call...............................[1,2,0]]


in the main class to get p1 to collide with specific tile images. but it seems like x,y have no real position i think.
i tried different variations of this code and nothing. can someone point me in the right direction. i looked a few places. also what different methods are there. thanks!

Code:
For Local i:= Eachin lvl.map
        For Local j:= eachin lvl.map

               If lvl.map[i][j] = 1 or lvl.map[i][j] = 2

                        If p1.x + p1.width >= lvl.x+j and p1.x <= lvl.x+j + lvl.tileSize and

                                  p1.y + p1.height >= lvl.y+i and p1.y <= lvl.y+i + lvl.tileSize

                                  p1.fallspd = 0

                         End
                End
          Next
next
 
but it seems like x,y have no real position i think.
You're thinking in the right direction already ;-)

The problem is, that this
Code:
For Local i:= Eachin lvl.map
will iterate through the whole -whatever lvl.map is-. In this case I guess it will iterate through an array of arrays of ints (an array whose elements are arrays whose elements are ints) and therefore i will be of type array<int> - not like you might expect indices going from 0 to the dimension of map -1. The same applies to j btw, since the eachin statement is the same in both cases.

If you really wanted through the complete map data, the head of your nested loops should look something like this:
Code:
For Local i:= 0 Until lvl.width
        For Local j:= 0 Until lvl.height
With lvl.height and lvl.width being the dimensions (in tiles) of your map.

BUT:

If the purpose of your code is just to - lemmeguess - stop p1 from falling when hitting solid ground, then you don't have to check against collision with the whole level. Just check the tiles around p1.x and p1.y
 
  • For Local i:= 0 Until lvl.width
  • For Local j:= 0 Until lvl.height
thanks Holzchopf! that was actually what i did first haha but must've done it wrong obvi.


If the purpose of your code is just to - lemmeguess - stop p1 from falling when hitting solid ground, then you don't have to check against collision with the whole level. Just check the tiles around p1.x and p1.y

this seems like a much better and easier solution !...ummm could you lend me some pseudo on that, not sure how to implement that.
i do want to collide with different tiles and tileheights and occasional walls. a small platformer. ill keep trying!!!
 
Back
Top Bottom