Home > database >  only walls collidable; python text game
only walls collidable; python text game

Time:12-07

I have made a text game in a python trinket. I made a collision system that activates whenever you press a key (in each key function it tests to see if there is a block under you after you move. if there is, it moves you back 1 cell the way you came from). The thing that confuses me is that walls of the stages work perfectly fine, but when there are any blocks in the middle of the stages, you can pass straight through them. There are no error messages or anything else that could possibly tell me where the collision mishap is coming from. I have tried putting the blocks in a straight line to replicate a wall, but you can still go right through them.

Trinket: https://trinket.io/library/trinkets/fc64f127d3

CodePudding user response:

Your functions left, right, up, down all use the global level variable. The render function uses the updated version of the level, which in level 2 includes a block. However, your directional control functions are still using level 1, which has no block.

For a quick fix, you can add global level to the top of your render function so that the global variable is updated when the level advances from 1 to 2.

  • Related