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 / Getting character to stop when needed

Author
Message
ZeroShade
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location:
Posted: 5th Jul 2006 17:47
I have a problem with my character... when he hits the border that is set up... he doesn't go through but he still walks... how can I set it so that he becomes idle unless he moves away from the wall or along it?
rem **************************
rem ** DEMO **
rem ** Created By: **
rem ** Martin vanPutten **
rem **************************

rem ******************************************************************
rem * # Variables
rem ******************************************************************
rem * player = Player.
rem * PushEnterToBegin = Creates A Wait Period Until ENTER Is Pushed.
rem * playerY = Players Y Value.
rem * x = X Value.
rem * z = Z Value.
rem * cameraX = Cameras X Value.
rem * cameraZ = Cameras Z Value.
rem ******************************************************************

rem ******************************************************************
rem * $ Variables
rem ******************************************************************
rem * player = Your Characters Name.
rem ******************************************************************

rem Setup Introduction.
hide mouse

rem Start Introduction.
cls
center text screen width() / 2, screen height() / 2 - 20, "DEMO"
sleep 1000
center text screen width() / 2, screen height() / 2, "Created By: Martin vanPutten"
sleep 1000
center text screen width() / 2, screen height() / 2 + 20, "Loading"
sleep 5000
cls
center text screen width() / 2, screen height() / 2 - 10, "What is your name?"
set cursor screen width() / 2 - 115, screen height() / 2 + 100
print "..."
set cursor screen width() / 2 - 100, screen height() / 2 + 100
input player$
cls
set cursor screen width() / 2 - 150, screen height() / 2 - 100
print "Welcome to DEMO " ;player$; "!"
set cursor screen width() / 2 - 150, screen height() / 2 - 80
print "This is a brief example of what"
set cursor screen width() / 2 - 150, screen height() / 2 - 60
print "DarkBASIC is capable of. Feel"
set cursor screen width() / 2 - 150, screen height() / 2 - 40
print "free to interact with the objects."
set cursor screen width() / 2 - 150, screen height() / 2 - 20
center text screen width() / 2, screen height() / 2 + 50, "~~Push ENTER To Begin~~"
input PushEnterToBegin#

rem Setup Environment.
show mouse
autocam off
sync on

rem Prepare Ground For The Matrix.
Load bitmap "Ground.bmp", 1
Get Image 1, 1, 1, 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, 5000, 10000
loop object 1, 0, 20 : set object speed 1, 5

rem Game Loop.
do

rem Status Bar
ink rgb((0), (0), (0)), 1
box 0, screen height() - 60, screen width() - 1, screen height() - 1
ink rgb((255), (255), (255)), 1
center text screen width() / 2, screen height() - 30, "Press the Escape Key to quit."
ink rgb(rnd(255), rnd(255), rnd(255)), 1
center text screen width() / 2, screen height() - 50, "This is the Status Bar for further Development."

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

rem Player Movement.
stage = 0
if Leftkey() = 1 then player# = player# - 9.0 : player# = wrapvalue(playerY# - 4.5)
if Rightkey() = 1 then player# = player# + 9.0 : player# = wrapvalue(playerY# + 4.5)
if Upkey() = 1 then x# = newxvalue(x#, player#, +12) : z# = newzvalue(z#, player#, +12) : stage = 1
if Downkey() = 1 then x# = newxvalue(x#, player#, -12) : z# = newzvalue(z#, player#, -12) : stage = 1

rem Boundaries.
if x# < -5000 then x# = -5000
if x# > 5000 then x# = 5000
if z# < -5000 then z# = -5000
if z# > 5000 then z# = 5000

rem Player Position.
position object 1, x# + 5000, 0.0, z# + 5000
yrotate object 1, player#

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.
cameraZ# = newzvalue(z# + 5000, playerY# - 180, 300)
cameraX# = newxvalue(x# + 5000, playerY# - 180, 300)
Position Camera cameraX#, 150, cameraZ#
Point camera x# + 5000, 150, z# + 5000

rem Refresh Screen.
sync

rem End Game Loop.
loop

Live And Let Learn
Trinita
20
Years of Service
User Offline
Joined: 29th Sep 2003
Location: Italy
Posted: 5th Jul 2006 18:41
You should consider the new position of the Player and the old Player position. If they are the same, then the player is idle, then the animation will stop.




Try to change the code like this, maybe it works.

"An eye for an eye will only make the whole world blind."
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 5th Jul 2006 19:37 Edited at: 5th Jul 2006 19:38
I'd do:


(=Part of your code)

Don't think too much

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
ZeroShade
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location:
Posted: 5th Jul 2006 21:33
Thanks... that helps... the simple things are the best!!

Live And Let Learn

Login to post a reply

Server time is: 2024-09-25 03:26:55
Your offset time is: 2024-09-25 03:26:55