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 Professional Discussion / Simple movement code that don't wanna work.

Author
Message
Eric T
23
Years of Service
User Offline
Joined: 7th Apr 2003
Location: My location is where I am at this time.
Posted: 19th Jul 2003 11:23 Edited at: 19th Jul 2003 11:29
Well

I got some movement code that i will be using.




Well when i use this code in project i am programming, whenever i decide to go in a diagnal movement (i have it programmed) my whole program starts to glitch. I'm not sure if this is PC error or DBP error but i would like to know.

Any help apprecieted.


--Eric

Opinions are like a$$holes, Everybody has one.
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 19th Jul 2003 15:39
Just a guess, but with the way you've organised your if(whateverkey) statements, it looks like multiple statements could be true at the same time, which means all your statements would go mental, with some being processed twice etc. My advice to you would be to use a number power section and a case statement, so:

keynumber = 0
if leftkey() = 0 then keynumber=keynumber+1
if upkey() = 0 then keynumber=keynumber+2
if rightkey() = 0 then keynumber=keynumber+4
if downkey() = 0 then keynumber=keynumber+8

Doing this will give you an array of codes that is unique for each key combination.

0 = No keys
1 = Left key
2 = Upkey
3 = Upkey + leftkey
4 = Right key
5 = Right key + left key
6 = Rightkey + upkey
7 = Rightkey + upkey + leftkey
8 = Downkey
9 = Downkey + Leftkey
10 = Downkey + Upkey
11 = Downkey + Upkey + Leftkey
12 = downkey + Right key
13 = Downkey + Rightkey + Leftkey
14 = Downkey + Rightkey + Upkey
15 = Downkey + Rightkey + Upkday + Leftkey

Do a nice case statement with keynumber, with entries for which ever of those combinations you want to do something with. That'll prevent all the multiple runnings. Alternatively, just a complex array of if then else statements would do the job.

Machine: P4 2200, 1GB RAM, GeForce4 64MB, Audigy Platinum
http://www.breakbeat-terrorism.co.uk
(It's not all about the coding)
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Jul 2003 15:47
When I put your code in place to control a small box in 2D, it all works well.

Here's what I was using - just a few small changes to make the step size easier to change.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Jul 2003 15:59
Personally, I prefer a more data-driven way of doing this rather than relying on me to get all the right combinations of 'if' statements right.

I'd do something like this.
Eric T
23
Years of Service
User Offline
Joined: 7th Apr 2003
Location: My location is where I am at this time.
Posted: 20th Jul 2003 01:17
i fixed the problem, it wasn't the , movement code but yet the arena i was using it in(learned that when i was looking at ian m's code for a second) so thanks for the help.

Opinions are like a$$holes, Everybody has one.

Login to post a reply

Server time is: 2026-07-21 20:53:27
Your offset time is: 2026-07-21 20:53:27