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 / Velocity vectors driving me nuts

Author
Message
Biggyniner
23
Years of Service
User Offline
Joined: 25th Apr 2003
Location:
Posted: 16th Nov 2003 00:49
I would really appreciate if anyone could help me out with this. Im trying to move a ship around the screen, like the old asteroids game. So when you release the acceleration key you continue to coast in that direction. To do this I set up two vectors. New vector data is entered when you press the up key (specifically angle and speed data) then this vector is added to the previous vector that was obtained the last time through the loop to come up with a single vector for the ships course and speed. However, this isn't exactly working out as I had planned and I cant figure out why. I've attached my code any help would be appreciated. I think the problem is with player.speedx and player.speedy but cant figure out where Im going wrong with them. If you need me to elaborate on any of the code let me know. Also spaceship.bmp can be any bitmap, just make sure the top of the ship or object you draw is facing up when you start.

"A man not willing to die for something is a man not fit to live."
-Martin Luther King Jr.
Biggyniner
23
Years of Service
User Offline
Joined: 25th Apr 2003
Location:
Posted: 16th Nov 2003 02:55
I already understand how vectors work though, but for some reason my code doesn't. At the heart my code should be doing basically the same thing as the asteroid demo in the code base. I know its probably some really minute detail I've missed, but I cant seem to find it.

"A man not willing to die for something is a man not fit to live."
-Martin Luther King Jr.
Dreamora
23
Years of Service
User Offline
Joined: 20th Sep 2002
Location: Switzerland
Posted: 16th Nov 2003 19:23
you are making a large effort with drift()

just using int(displacementx) would be much easier

Dell Inspiron 8200,P4-M 1,7ghz, GF4 440go (45.23 - DX9b), 1GB RAM
Biggyniner
23
Years of Service
User Offline
Joined: 25th Apr 2003
Location:
Posted: 19th Nov 2003 04:37
Thanks for the tips everyone, I finally got it working I just got rid of the code that calculated the vectors and tried it all over again from scratch. Go figure now it works. Anyways I have a little section of code that determines if the ship has gone off the screen or not, and if it has it repositions it on the other side of the screen. Can you let me know if there's any way to make this code cleaner? Thanks, here's the code:



"A man not willing to die for something is a man not fit to live."
-Martin Luther King Jr.
las6
23
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Finland
Posted: 19th Nov 2003 10:47
Dunno if it's any "cleaner", but you could use temp variables to shorten the code. Like this:
tempx = sprite x(1)
tempy = sprite y(1)
and then do the checking with those. Also, instead of positioning like that, you could try to just adjust the variables that control the ships position. ( ship.posx = screen width() )
Or just edit those temp variables above and using only 1 sprite positioning command: Sprite 1,tempx,tempy,1

Keyboard not detected. Press F1 to continue.

Login to post a reply

Server time is: 2026-07-26 18:01:03
Your offset time is: 2026-07-26 18:01:03