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 / Need Help Making a character move

Author
Message
kuwagata
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location:
Posted: 8th May 2012 21:34
Can someone show me how to make a character move in this code? Thanks. Also I don't know how to put the code in a code box.


` This code was downloaded from The Game Creators
` It is reproduced here with full permission
` http://www.thegamecreators.com

`Project: Cool Rain Effects
`Author: The Game Guy

Rem Set up
sync on : sync rate 30 : hide mouse
color backdrop RGB(81,105,111) : autocam off : set camera range 0,.1,10000

Rem Creates a grass texture using random lines
V# = .5 : cls RGB(128,128,80) `Colors the background
for i = 1 to 10000 `Creates 10000 lines
inc V#,.0001 : ink RGB(112*V#,128*V#,20*V#),0 `Changes the colors of the grass
y1 = rnd(256) : y2 = rnd(256) `Randomizes the positions of the lines
s1 = rnd(30)-15 : s2 = rnd(30)-15 `The length of each line
line y1,y2,y1+s1,y2+s2 `Draws the lines
line y1-256,y2,y1+s1-256,y2+s2 : line y1,y2-256,y1+s1,y2+s2-256 `makes the lines seamless
line y1+256,y2,y1+s1+256,y2+s2 : line y1,y2+256,y1+s1,y2+s2+256
next i : get image 1,0,0,256,256 `Gets the grass image

Rem Creates random dots for a simple splash effect
cls
ink rgb(255,255,255),0
for i = 1 to 10
dot rnd(128),rnd(128)
next i
get image 2,0,0,128,128

Rem Loads the image for the clouds
load image "E:\8th Grade\Adv tech\4th QRT GAME\images for game/storm clouds.bmp",3

`load sound "rain01.wav",1
`loop sound 1

Rem invisible object used for positioning the camera
make object cube 1,5
make object collision box 1,5,5,5,-5,-5,-5,1

rem door
load image "E:\8th Grade\Adv tech\4th QRT GAME\images for game/Door to Narnia.bmp",12
make object box 12,5,10,5
position object 12, 500,5,500
texture object 12,12
if object collision (1,12)>0
gosub endsection
endif
rem house
load image "E:\8th Grade\Adv tech\4th QRT GAME\images for game/old mossy house.bmp",13
make object box 13,100,50,80
position object 13,100,25,100
texture object 13,13


Rem make the grass plain
make object plain 1000,2000,2000
texture object 1000,1
scale object texture 1000,1000,1000
pitch object down 1000,90

Rem make the rain splash effects
make object plain 1001,1000,1000
pitch object down 1001,90
scale object texture 1001,100,100
texture object 1001,2
set object transparency 1001,5

Rem Create the clouds
make object plane 1002,40000,40000
texture object 1002,3
scale object texture 1002,20,20
ghost object on 1002,2
pitch object down 1002,90
position object 1002,0,100,0

Rem Makes a duplicate of the clouds for a second layer
instance object 1003,1002
pitch object up 1003,90
position object 1003,0,110,0

Rem Creates the rain particles
particles = 1000
for i = 10001 to particles+10000

if i = 10001 `creates the rain particles source object
make object triangle i,0.04,0,0,0,0,0,-0.02,3.5,0
ghost object on i,2
endif

if i > 10001 then instance object i,10001 `copys the rain particles

position object i,(rnd(140)-70)/2.0,(rnd(180))/2.0,(rnd(140)-70)/2.0
rotate object i,0,rnd(180),0
pitch object down i,(rnd(30)-15.0)/2.0

next i

Rem Variables
Speed# = 10
Slide# = 0
JumpStrength# = 10.5
Kirby = 0



Rem Main Loop
DO

Rem display frames per second
set cursor 0,0 : print "FPS: ";screen fps()

Rem Mouse variables
MMX# = mousemovex() : MMY# = mousemovey()

Rem Camera and Object rotation Programing
rotate object 1,0,0,0
mox# = mox# + MMX#*Speed#
turn object right 1,mox#
rotate camera 0,0,0,0
turn camera right 0,mox#
cax# = cax# + MMY#*Speed#
if cax# > 90 then cax# = 89
if cax# < -90 then cax# = -89
pitch camera down 0,cax#

Rem speed adjust
MZS# = .06 * Speed#
MXS# = .04 * Speed#

Rem Arrowkey input
if upkey() then ZS# = ZS# + MZS#
if downkey() then ZS# = ZS# - MZS#
if rightkey() then XS# = XS# + MXS#
if leftkey() then XS# = XS# - MXS#

Rem Adjusts the slide amount if the player is in the air or on the ground
if ground = 1 then Slid# = 1.5
if ground = 0 then Slid# = 4

Rem Speed Adjust Z
if ZS# > 0 then ZS# = ZS# -MZS#/(Slid#*Slide#) `can be used for sliding
if ZS# < 0 then ZS# = ZS# +MZS#/(Slid#*Slide#)
if upkey() = 0 and Downkey() = 0
if ZS# > 0 then ZS# = ZS# -(0.001 * Speed#)
if ZS# < 0 then ZS# = ZS# +(0.001 * Speed#)
if ZS# > -MZS#/4 and ZS# < MZS#/4 then ZS# = 0
endif

Rem Speed Adjust X
if XS# > 0 then XS# = XS# -MXS#/(Slid#*Slide#) `can be used for sliding
if XS# < 0 then XS# = XS# +MXS#/(Slid#*Slide#)
if Rightkey() = 0 and Leftkey() = 0
if XS# > 0 then XS# = XS# -(0.001 * Speed#)
if XS# < 0 then XS# = XS# +(0.001 * Speed#)
if XS# > -MXS#/4 and XS# < MXS#/4 then XS# = 0
endif

if ZS# > MZS#*10 then ZS# = MZS#*10
if ZS# < -MZS#*10 then ZS# = -MZS#*10

if XS# > MXS#*10 then XS# = MXS#*10
if XS# < -MXS#*10 then XS# = -MXS#*10

Rem Move and position the camera
move object 1,ZS#
move object right 1,XS#
if ground = 1
if mouseclick() = 1 `makes the player jump
gravity# = -JumpStrength#
ground = 0
endif
endif


if Kirby = 1 `allows the player to jump in the air
if mouseclick() = 0 then ground = 1
if gravity# < 100 then gravity# = gravity# +.01
else
if ground2 = 0
if object position y(1) > 3 then ground = 0
endif
endif

Rem the gravity controls
move object down 1,gravity#
if ground = 0
gravity# = gravity# +.01
endif

if object position y(1) < 1 then position object 1,object position x(1),1,object position z(1)
if object position y(1) = 1
if mouseclick() = 0 then ground = 1
endif

Rem positions the camera
position camera 0,object position x(1),object position y(1),object position z(1)




REM RAIN PARTICLES LOOP
for i = 10001 to particles+10000
move object down i,2.5 `moves the rain particles down

Rem repositions the particles
if object position y(i) < object position y(1)-30
position object i,(rnd(140)-70)/2.0+Object position x(1),object position y(i)+50+rnd(20)+Object position y(1),(rnd(140)-70)/2.0+Object position z(1)

Rem adjust new rain angles
rotate object i,0,mox#,0
pitch object down i,ZS#*50
roll object right i,XS#*50
turn object right i,rnd(360)
pitch object down i,(rnd(30)-15.0)/2.0
endif

Rem Makes the rain particles follow the player
if object position x(i) > object position x(1)+50 then position object i,object position x(i)-100,object position y(i),object position z(i)
if object position x(i) < object position x(1)-50 then position object i,object position x(i)+100,object position y(i),object position z(i)
if object position z(i) > object position z(1)+50 then position object i,object position x(i),object position y(i),object position z(i)-100
if object position z(i) < object position z(1)-50 then position object i,object position x(i),object position y(i),object position z(i)+100

next i



Rem makes splash effects
position object 1001,object position x(1)+rnd(20)-10,.2,object position z(1)+rnd(20)-10


Rem Moves the clouds
move object up 1002,0.5
move object up 1003,0.3





sync
loop
Endsection:
end

Hello!
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 9th May 2012 17:50 Edited at: 9th May 2012 17:51
Hi!

To make code snippets, highlight your code and hit the "code" button in the message editing box. This will stuff your code between two tags which look like this: [ code ] code here [ /code ]. Additionally, you can specify what language your code was written in, which will enable syntax highlighting. To do this, edit the first code tag to look like this : [ code lang=dbp ] code here [ /code ] (of course you have to remove the spaces to make the code snippet actually appear). The result:



I skimmed over your code, and first of all I'm going to point out a few things you can improve on. After that we'll get to solving your problem.

The first thing I noticed - although this could also just be because you didn't put your code in a code snippet - is that you don't have any indentation. It is essential in order to eliminate nesting errors. Add an extra tab to your code whenever you write a command that has a "partner". When you write said partner, remove a tab. This turns ugly code like this:



into this beautiful, readable code:



Next thing I noticed is, well... This...



Ignoring the fact that you've mixed back-slashes and forward-slashes, try running your program on another computer. You'll quickly notice it won't work at all. This is because that other computer won't have the file storm clouds.bmp saved in the same directory as on your computer. How do we fix it? Use relative paths. Say your .dba file (your source code) is saved to this path:

C:\Program Files\The Game Creators\Projects\myProject\myProject.dba

And you have an image you want to load which is saved in the folder:

C:\Program Files\The Game Creators\Projects\myProject\media\image.bmp

All you have to do is write this to load it:




Alright, with that aside, let's attend to your problem. I find the way you are trying to handle your player is very strange. I saw an object which you're moving about, I later saw that it's supposed to be kirby, and then you just position your camera right in it's face so you don't even get to see it, making it a first person game.

The way you should handle movement in general should be using the IPO principle.

Input
Process
Output

So first section is to get the positions of your player (input):



Next we process those positions and angles. We should only affect the variables, not the camera.



That's all of the processing. Now we ouptut our values to the actual camera:



Hope that clears a few things. If you wanted to have your kirby object at the camera's position, you'd just add this:



Oh and one more thing. You don't actually have to do the input step in this case, because the variables are probably global and store your last positions anyway.

Hope that helps!

TheComet

kuwagata
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location:
Posted: 10th May 2012 21:19
Thank you for giving me this information

It is very useful.



Hello!

Login to post a reply

Server time is: 2024-11-23 20:59:45
Your offset time is: 2024-11-23 20:59:45