Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Problem getting the collision detection to work correctly...
#4
Well, there is nothing specific to point out. You need change the architecture and need more coding discipline to succeed.

Here are a few hints:

- use global variables only in the global context, don't import them to functions (=>"side effects", which create unnecessary complexity and cause slow and painful death to your project when it grows)
- don't use subroutines (Gosub), as they run in global context, use functions only
- a function should do one thing and should depend entirely on the parameters (ideally, the map/world may be an exception)
- use meaningful constants or better variables, no literals (99 = #ROBOT ?)
- use types for all variables, e.g. set "syntax 2" or "syntax 6" on top of the code, this will enforce you to declare types

For the architecture:

- drawing of static "objects" should be taken out of the game loop (this is why you use BBlit, otherwise, if you do full-frame refresh, you could use QBlit or just Blit as this is faster)
- the map should contain (semi-)static objects, the object list should contain moving objects
- don't use shapeshit for collision when you have animated objects. one frame might not collide and allow you to move, the next might collide because the sprite has changed, and you can get easily stuck. use rectangle hit strategy, this is sufficient for most cases. probably you don't even need to compare shapes as all your walls are 32x32, you can just check the map independently from its visualization.

question: do you want your player to move freely or in 32x32 grid?

try to make everything more object oriented, and make use of pointers, something like
[ab3]NEWTYPE.player_T
x.w
y.w
direction.w
...
End NEWTYPE

*player.player_T = player_New{initx.l,inity.l}
player_Draw{*player.player_T, bitmapID.l}
player_CanMove{*player.player_T, *map.map_T}
player_Move{*player.player_T, dx.l, dy.l}
player_Delete{*player.player_T}

*map.map_T = map_New{*data.l}
map_Draw{*map.map_T, bitmapID.l}[/ab3]
hope this helps.
Zitieren


Nachrichten in diesem Thema

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste