Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Problem getting the collision detection to work correctly...
#1
Hey,

Sorry to disturb you but I am having a major problem getting the collision detection to work. For some reason it seems it is executing both true and false at the same time with my collision detection and it is not working for me. Is it possible you could check on the source code and point to me my mistake? Big Grin

I have attached the entire source code...I hope people who are starting their own gaming project will learn from all my mistakes and learn from this source code Smile
Zitieren
#2
So what exactly do you want me to do?
Shall I do a full code cleanup with comments? You code is a bit unstructured and therefore hard to understand. I think the major problem is how you want to do the game logic.

BTW, you should give your sourcecode file a proper extentions, like .bb2, .ab2 or .ab3 (prefered if you use Amiblitz3).
Zitieren
#3
I do not want you to fix it for me at all..in fact...all I want is that you execute it...and find the fault..just tell me with your own word the logic mistake I have made. Because usually it is something very silly but I am unable to see it..and a third eye will see the mistake. Do not fix it for me..just point me in the direction saying you have problem with say array declaration for example..that's it. Then I know where I will start tackling the situation.

Thank you for pointing out my structured code...now that is something I did not realize and you pointed that out to me. I will work on making it more structured.


THANKS FOR EVERYTHING!! Big Grin Remember this is all junior work for me...I am learning things...and I want all my mistakes here so that I learned them ones and never repeat them again in my future project. This way it will become like writing a story when it comes to coding a game...all what would be left for me is my imagination and the story I write...as of right now...I am having problem with grammar, syntax, logic, etc...i.e...this is where I am facing in my code Big Grin

Yes I know programming...but I have never tackled full blown game development in an old hardware before...so this is all new to me.


THANK YOU!!!
Zitieren
#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
#5
Yes! That is all the help I really want. I will not be able to learn if I do not make mistakes and fix them myself. If I rely on people to do all the work for me...then I have done nothing. I would rather crawl, stand up, walk, fall again, crawl, stand up, walk and fall again until I can run. So to answer your question, that is all I wanted. I just want to ask one question...if I get so seriously stuck could I ask you to help me on that part that I get stuck? But of course after putting 300% effort from my part to solve it!

What I will do now...is stop where I am...make a backup of this code...redo everything again and check mark all your helpful suggestion and tips into my code...and see how this works out. This project is more to teach me proper programming technique than the actual game it seems.

Ooh...I forgot to answer your question...I want the character to move in 32 grid and not freely. Also I do not want the character to movie diagonally...I want the character to move only in four directions: UP, DOWN, LEFT and RIGHT. I cannot move on in this game and add magnet, and screen scrolling, high score, etc without scrubbing everything I did so far and following your advice completely. THE PROJECT will end up hideously slow, buggy, frustrating to make, non-usable for further project and failure. IN FACT...I want to make my own tiny little INCLUDE where I have my own custom functions that can be used in future projects with ease. I want the main program to have so few lines of code...

I have much work than needs to be done. I think it is best I develop this or optimize the code in WinUAE because my Amiga 4000D running at just 040 @ 25 Mhz is too slow for AmiBlitz3....tooooooooooooooooooooooooooooooooooooooooooooooooooo slow and this is not something I want on my head as I program.
Zitieren


Gehe zu:


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