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 / Moving character

Author
Message
kuwagata
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location:
Posted: 10th Feb 2012 18:06 Edited at: 13th Feb 2012 18:35
Can someone help me make the box in this game move? I got this off the forums. Thanks to whoever made it. Here is the copy of the game:



Hello!
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 11th Feb 2012 02:50
Quote: "Can someone help me make the box in this game move?"

What kind of movement are your after?

Oh, and with code, it's best to place the code tags around your code.
Simply click the code button once, paste in your code and then click the code button again.

kuwagata
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location:
Posted: 11th Feb 2012 19:52
I'm trying to get the cube near the end of the code to move when the arrow keys are pressed. The problem is the camera is supposed to move when the keys are pressed. Thanks for your help!

Hello!
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 13th Feb 2012 09:13
Quote: "I'm trying to get the cube near the end of the code to move when the arrow keys are pressed. The problem is the camera is supposed to move when the keys are pressed. Thanks for your help"


1. !Edit! your original post and put code tags:


2. If you want the cube to move, then use different keys to control it. You also have to include a call to the function/sub responsible for handling you cube in the main loop


MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Feb 2012 14:08
curiosity got the cat some food (tagging in)

hello newcomer welcome to the forum

kuwagata
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location:
Posted: 13th Feb 2012 15:56
Thanks guys! I'll try that code.

Hello!
kuwagata
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location:
Posted: 14th Feb 2012 17:53
Quote: "2. If you want the cube to move, then use different keys to control it. You also have to include a call to the function/sub responsible for handling you cube in the main loop
+ Code Snippet

`Declarations
#CONSTANT mycube 1

GLOBAL speed# = 0.05

`Setup display and camera
SET DISPLAY MODE DESKTOP WIDTH(), DESKTOP HEIGHT(), 32
AUTOCAM OFF
POSITION CAMERA 0, 0,0,0
COLOR BACKDROP RGB(0,0,0)

`Create the object
MAKE OBJECT CUBE mycube, 0.5
POSITION OBJECT mycube, 0,0,5

`Mainloop:
WHILE SCANCODE() <> 16
`Call dbpro's control camera with arrows function
CONTROL CAMERA USING ARROWKEYS 0, speed# / 5, speed# / 2
`Cull our cube control function
ControlCube()
`Print instructions to screen
TEXT 1, 50, "Press arrow keys to move camera, press wasd to move cube, press q or Esc to exit"
ENDWHILE
END



Function ControlCube()
`The following is a set of WASD controls

`If W pressed
IF KEYSTATE(17) = 1
`Move object forward in it's facing direction using our predefined speed. I slowed it dow for smoother play
MOVE OBJECT mycube, speed# / 5
ENDIF
`If S pressed
IF KEYSTATE(31) = 1
`Move object backwards from its facing direction using a negative number for velocity
MOVE OBJECT mycube, speed# / -5
ENDIF
`If A pressed, rotate object on it's Y-axis, ie left/right
IF KEYSTATE(30) = 1
`Negative speed used for left turn
YROTATE OBJECT mycube, OBJECT ANGLE Y(mycube) - speed#
ENDIF
`If D pressed, rotate right
IF KEYSTATE(32) = 1
`Positive rotation value used for right turn
YROTATE OBJECT mycube, OBJECT ANGLE Y(mycube) + speed#
ENDIF
EndFunction

"



How should I put this in the game code? If I put it in now, it turns the world black. Thanks.

Hello!
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 15th Feb 2012 02:37
Quote: "How should I put this in the game code? If I put it in now, it turns the world black. Thanks."

You'll have to adapt it. It's not always as easy as copy/paste. So basically, take the concept of nonZero's code and apply it to your own.

Login to post a reply

Server time is: 2024-11-23 23:03:06
Your offset time is: 2024-11-23 23:03:06