Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Movement code help

Author
Message
Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 20th Aug 2007 18:44 Edited at: 21st Aug 2007 18:50
Hi everybody,
I recently started a pacman clone and I am already running into trouble, I just finished coding my movement code and it only semi works. You see, I'm trying to make the player only move in four directions, and face that direction every time you press a certain key, but when i tested it out, the player would not always go in the right direction. I have looked through my code to find the problem but I am having no luck. I have checked over all the numbers, variables and all the other checks and I have found nothing wrong(except for maybe its extreme inefficiency). Can you please help me and check it over it see if there is something I'm missing?

*note this is not the full code


-Thanks in advanced
-fxgamer

Your about to get pwned.
Pixelator
17
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 20th Aug 2007 19:08
Too much code My brain hurts!!!!!!!!




(three days later)



(Y=M*X+B)=(X=(Y-B)/M)=(B=Y-M*X)=(M=Y-B/X)
and if you can figure out what it means i will give you a cookie.
Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 20th Aug 2007 19:20 Edited at: 21st Aug 2007 18:50
Dang I was hoping for some help!Well, I gues in the meantime I could code some other stuff.

Your about to get pwned.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 20th Aug 2007 19:45
Indent your code properly and problems will be much easier to find and we will be much more likely to make an effort to find them!



TDK_Man

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 20th Aug 2007 19:58 Edited at: 20th Aug 2007 20:19
This will only accept unique key presses and will keep Pac-man moving constantly, I've remmed out the IF statement that will mean he only moves when a key is pressed.
Sorry to do all of it for you but I was interested in this



I've just made this up in the post so there's no guarantee it will work

[EDIT]
Got the Z direction the wrong way around but apart from that it works fine

Here's a fully functional version:


I'm pleased with this, my code has improved so much since joining the forums

If you have any questions about my code please ask.
I will explain a clever trick I have used that I picked up from someone.

this line of code is doing the same as

If you are using lots of ANDs and/or ORs () then try to think of ways to do the same statement mathematically

Your signature has been erased by a mod because it was rubbish.
Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 21st Aug 2007 02:46 Edited at: 21st Aug 2007 18:50
Thanks OBese87, that's helped me some, I'm going to see if I can write my own movement code based on the same principle. Also when it comes to indentation, I'm clueless.

Your about to get pwned.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st Aug 2007 14:26 Edited at: 21st Aug 2007 15:07
Quote: "Also when it comes to indentation, I'm clueless"

check out my tutorial on program structure
http://forum.thegamecreators.com/?m=forum_view&t=111855&b=10
I'd actually completely forgotten about it , must finish it.

You can see how much of a difference good structure and economy makes; your movement code was 92 lines long and mine was 5! I'm not boasting, just pointing out the example

Your signature has been erased by a mod because it was rubbish.
Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 21st Aug 2007 15:30 Edited at: 21st Aug 2007 18:50
Yeah but you stacked! Even still yours is much, much shorter, lol.

Your about to get pwned.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st Aug 2007 15:53
What do you mean by stacked?
The main reason why your code is so long is that you have written statements like MOVE OBJECT for each instance, you should try to make it so you only have one call for things like that each loop.
The forums will help with all that though, it's amazing how fast you learn on here

Your signature has been erased by a mod because it was rubbish.
Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 21st Aug 2007 16:16 Edited at: 21st Aug 2007 18:49
Thanks for all your help, I looked through your code and wrote my own based off it, it works pretty well too.


[edit] By stacked I mean using stackers : to put more commands on one line[/edit]

Your about to get pwned.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st Aug 2007 17:17
Nice work, you even got the unique key press thing in there, in a slightly different way.


Quote: "
If Up > 0 then Pacman_angY=0
"

I would have written that ^ like this
Quote: "
If Up = 1 then Pacman_angY=0
"

There's no problem with it, it's just it looks clearer to me
and the fact that Up could only be 0 or 1.

Your signature has been erased by a mod because it was rubbish.
Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 21st Aug 2007 18:48
I guess your right, but it works either way really. Ive started writing a camera now and its working great.

Your about to get pwned.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st Aug 2007 19:12
Quote: "I guess your right, but it works either way really."

Yeah I know, sorry I was just being extra picky
Your code looks much better, you catch on fast!

Your signature has been erased by a mod because it was rubbish.

Login to post a reply

Server time is: 2025-05-30 14:06:51
Your offset time is: 2025-05-30 14:06:51