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.

2D All the way! / 2D Control Method Woes...

Author
Message
The Boy Chris
22
Years of Service
User Offline
Joined: 13th May 2004
Location: Liverpool - UK
Posted: 13th May 2004 15:01
Hello everyone,

I've had a bash at creating a 2D GTA-1 style control method - UpKey() moves player forward, LeftKey() rotates avatar left, etc...

At the moment I'm just working on the algorythm to get the numbers correct, then I'm going to enter the sprite code. However, I can't seem to get my numbers to rotate correctly. Can anyone see what I'm doing wrong?

Thanks

Chris



http://www.bizarrecreations.com
The Boy Chris
22
Years of Service
User Offline
Joined: 13th May 2004
Location: Liverpool - UK
Posted: 13th May 2004 15:20
Oh, and I have DB-Pro by the way.

Thanks

http://www.bizarrecreations.com
Lampton Worm
23
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United Kingdom
Posted: 13th May 2004 15:24
Hi,

Wouldn't it be easier to use a sprite from the start, and the commands rotate sprite and move sprite?

e.g. (untested)...

`Codestart
sync on:sync rate 40
load image "player.bmp",1
sprite 1,screen width()/2,screen height()/2,1
do
if upkey()=1 then move sprite 1,1
if downkey()=1 then move sprite 1,0-1
if leftkey()=1 then rotate sprite 1,wrapvalue(sprite angle(1)+3)
if rightkey()=1 then rotate sprite 1,wrapvalue(sprite angle(1)-3)
sync
loop
`Codeend

etc.

Not sure if that is what you're trying to achieve?

Hope it helps,
Cheers.
The Boy Chris
22
Years of Service
User Offline
Joined: 13th May 2004
Location: Liverpool - UK
Posted: 13th May 2004 15:32
I'm doing it this way because it'll make it easier when I need to work out collision, acceleration and other stuff later on. The way you desribed is accurate, but there is no Update/Render loop to it, therefore I can't work out everything before I draw the screen (which I will need to do...)

Chris

http://www.bizarrecreations.com
Lampton Worm
23
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United Kingdom
Posted: 13th May 2004 15:35
Hi,

You could use the (limited) built in sprite collision detection, if you only need box collision.

Also you can track the sprite size and coords easily enough...just use PlayerX=sprite x(1) etc.

For acceleration you'd just calculate the velocity and apply it to the move sprite command.

I'm sure you way will work a treat when its fixed, just thinking that DBP provides these commands to make life easier

Cheers.
The Boy Chris
22
Years of Service
User Offline
Joined: 13th May 2004
Location: Liverpool - UK
Posted: 13th May 2004 15:52 Edited at: 13th May 2004 15:52
Nevermind, thanks for the info I'm going to try what you said and look into the stuff DBP does automatically.

In the meantime I gave up and resigned myself to 8 directional movement. Ahhh well...]

Chris



http://www.bizarrecreations.com
Lampton Worm
23
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United Kingdom
Posted: 13th May 2004 16:30
No worries. p.s. not sure if its something you've considered already, but you may want to use typed arrays -

e.g.

DIM g_PlayerX(iMaxNumPlayers)
DIM g_PlayerY(iMaxNumPlayers)
DIM g_PlayerSpeed(iMaxNumPlayers)
DIM g_PlayerAcceleration(iMaxNumPlayers)
DIM g_PlayerDirection(iMaxNumPlayers)
DIM g_PlayerVehicle(iMaxNumPlayers)

Could be...

type playertype
x as integer
y as integer
speed# as float
etc.
endtype

dim player(iMaxNumPlayers) as playertype

...then you can refer to the array as - player(1).x, player(1).speed# etc. and it only uses up 1 array, cool.

Just a thought,
Cheers.
The Boy Chris
22
Years of Service
User Offline
Joined: 13th May 2004
Location: Liverpool - UK
Posted: 13th May 2004 17:09
That is the absolute best thing I've heard yet Thanks man! (Off to implement that now heh...)

http://www.bizarrecreations.com

Login to post a reply

Server time is: 2026-06-09 13:56:08
Your offset time is: 2026-06-09 13:56:08