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.

Newcomers DBPro Corner / I need to position my character

Author
Message
ZeroShade
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location:
Posted: 18th Jun 2006 22:35
I'm new to Darkbasic, and on my third day of learning it, I've created this a "DEMO". But I don't know how to position my character in the middle of my matrix. Can somebody help? Also, how would I go about making an invisible border so that the character cannot go outside the matrix?

rem **************************
rem ** DEMO **
rem ** Created By: **
rem ** Martin vanPutten **
rem **************************

rem Start Up Screen.
cls
print "DEMO"
print "Created By: Martin vanPutten"
sleep 1000
print "Loading..."
sleep 5000

rem Setup Environment.
hide mouse
autocam off
sync on

rem Prepare Ground For The Matrix.
Load bitmap "Ground.bmp", 1
Get Image 1, 0, 0, 128, 128
Delete Bitmap 1

rem Create Ground.
Make Matrix 1, 10000, 10000, 15, 15
Prepare Matrix Texture 1, 1, 1, 1

rem Load Charecter.
load object "idle.x", 1 : append object "walk.x", 1, 100
yrotate object 1, 180 : fix object pivot 1
position object 1, 10000, 0, 10000
loop object 1, 0, 20 : set object speed 1, 5

rem Game Loop.
do

rem Variables.
aY# = Object angle Y(1)

rem Player Movement.
stage=0
if Leftkey() = 1 then a# = a# - 9.0 : a# = wrapvalue(aY# - 4.5)
if Rightkey() = 1 then a# = a# + 9.0 : a#=wrapvalue(aY# + 4.5)
if Upkey() = 1 then x# = NewxValue(x#, a#, +12) : z# = NewzValue(z#, a#, +12) : stage = 1
if Downkey() = 1 then x# = NewxValue(x#, a#, -12) : z# = NewzValue(z#, a#, -12) : stage = 1
position object 1, x#, 0.0, z#
yrotate object 1, a#

rem Controling Player Animation.
if stage <> oldstage
if stage = 0
set object frame 1, 0.0
loop object 1, 0, 20
set object speed 1, 10
endif
if stage = 1
set object frame 1, 105.0
loop object 1, 105, 125
set object speed 1, 40
endif
oldstage = stage
endif

rem Camera Control.
cZ# = Newzvalue(Z#, aY# - 180, 300)
cX# = Newxvalue(X#, aY# - 180, 300)
Position Camera cX#, 200, cZ#
Point camera X#, 150, Z#

rem Refresh Screen.
sync

rem End Game Loop.
loop

~Live And Let Learn~
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 19th Jun 2006 04:22 Edited at: 19th Jun 2006 04:24
I'll help you!

Okay...
When you have a matrix, the positioning works differently. When you position a matrix, the bottom left CORNER goes on the point that you specify, but with objects, the CENTER of the object goes there. Got it? Good, now to answer yor question...

Now that that's out of the way, I can tell you how to position the object/character.

Alright, so what you need to do is put your object halfway into the matrix on the X and Z axis'. Don't you agree that halfway into the matrix on those two dimensions (X and Z) will give you the center?

You can find the halfway point on the X axis by dividing the matrix's X size (in your case 10000) by 2. Dividing by 2 gives half, correct? Same thing with the Z axis. Divide 10000 by 2.

So, if you keep your matrix where it is right now in your program, you should have ended up with "position object 1,5000,0,5000" You can change the 0, I'm sure you know what it is. It's the Y axis position. You'll see how this turns out. Anyway, to cut to the chase, your final position should be:

position object 1,5000,0,5000

That's it! Hope I helped.

I doubt you can draw me/60 by hand, so you REALLY can't draw ME/1, can you?
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 19th Jun 2006 18:32
I was just as surprised as you are.

I doubt you can draw me/60 by hand, so you REALLY can't draw ME/1, can you?
Heckno
20
Years of Service
User Offline
Joined: 8th Sep 2004
Location: Palm Coast, FL
Posted: 20th Jun 2006 22:41
Quote: "invisible border so that the character cannot go outside the matrix?"


you just place invisible objects ( cube, box, sphere,any really) at the edge... Of course that would require a collision system..
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 21st Jun 2006 00:20
Just test the characters new position before you POSITION OBJECT.

If x or z are outside the bounds of the matrix, e.g. if <0 or >10000 then you reset the position back to what it was before you updated, and hey presto, your object stops moving.

Hope this helps!
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 21st Jun 2006 09:59 Edited at: 21st Jun 2006 16:41
Expanding the above suggestion

x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
if x#>10000.0 then x#=10000.0
if z#>10000.0 then z#=10000.0
if x#<0.0 then x#=0.0
if z#<0.0 then z#=0.0
position object x#,y#,z#

M.I.A is pending
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 21st Jun 2006 15:39
Baggers:
Read my post - the code you have supplied is exactly what I suggested he do????? I never mentioned a collision system!
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 21st Jun 2006 16:40
well look at that...sorry, god knows what I was smoking this morning then.
Sorry about that..editing in progress.

M.I.A is pending
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 21st Jun 2006 17:08
Cheers (and can you pass me one of whatever you were smoking?)

Login to post a reply

Server time is: 2024-11-26 17:29:05
Your offset time is: 2024-11-26 17:29:05