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 / mouse moving

Author
Message
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 31st Dec 2002 06:32
I want to be able to move a gun with the mouse. The directions in the book are really hard to understand, and I really want it. How do I make it move and fire? Also, I tried to make the bullet fire out of a cylinder, but it didn't work. Here's my code;

`Hide mouse
hide mouse

` Load bitmaps
load bitmap "grass1.bmp",1
get image 1,0,0,256,256
delete bitmap 1

` Load music track
load music "Over5.mid",1
loop music 1

` Activate manual sync
sync on

` Make landscape and ceiling matrix
make matrix 1,2000,5000,10,25
prepare matrix texture 1,1,2,2
make matrix 2,2000,5000,10,25
prepare matrix texture 2,1,2,2
fill matrix 2,0,2
randomize matrix 2,350.0
for t=0 to 25
set matrix height 2,0,t,-100
set matrix height 2,10,t,-100
next t
update matrix 2

`Make Bullets
Make Object Sphere 4,2
hide object 4

`Make Cockpit
load Object "gunL.x",1
load Object "gunR.x",2

`Make Gun
Make Object Cylinder 3,2
XRotate Object 3,90
Fix object pivot 3
Scale Object 3,100,100,500

` Begin game loop
do

` Set seed for same random numbers
randomize 1

` Clear cave floor
fill matrix 1,0,1

` Set lighting, fog and setupset ambient light 20
color backdrop 0
if fog available()=1 then fog on : fog color 0 : fog distance 3000

` Reset speed
x=0
z=0
speed#=0.0

` Begin main loop
repeat

` Record old variables
oldx=x
oldgy#=gy#

` Control key movements
if upkey()=1 then speed#=speed#+1.0 else speed#=speed#-1.0
if leftkey()=1 then rz#=rz#+1.0
if rightkey()=1 then rz#=rz#-1.0

`Control gun movement


` Control variables
if speed#40.0 then speed#=40.0
rz#=rz#/1.1
x=x-(2*rz#)

` Scroll landscape
z=z+speed#
if z>200
z=z-200
if rnd(3)=0
mp=mp-1
mp=mp+rnd(3)
if mp4 then mp=4
endif
for t=0 to 0 : set matrix height 1,t,24,450 : set matrix tile 1,t,24,2 : next t
for t=1 to mp : set matrix height 1,t,24,rnd(200) : set matrix tile 1,t,24,2 : next t
for t=mp+1 to mp+1 : set matrix height 1,t,24,rnd(200) : set matrix tile 1,t,24,3 : next t
for t=mp+2 to mp+3 : set matrix height 1,t,24,rnd(20) : set matrix tile 1,t,24,1 : next t
for t=mp+4 to mp+4 : set matrix height 1,t,24,rnd(200) : set matrix tile 1,t,24,4 : next t
for t=mp+5 to 9 : set matrix height 1,t,24,rnd(200) : set matrix tile 1,t,24,2 : next t
for t=10 to 10 : set matrix height 1,t,24,450 : next t
update matrix 1
shift matrix up 1
shift matrix up 2
endif

` Position matrix
position matrix 1,0,0,2500-z
position matrix 2,0,100,2500-z


` Position camera
gy#=curvevalue(50+get ground height(1,500+x,z),gy#,3)
position camera 500+x,gy#,2500
zrotate camera wrapvalue(rz#)
Position Object 1,498+x,gy#,2500.7
Position Object 2,502+x,gy#,2500.7
Position object 3,500+x,gy#-5,2510

`Fire bullets
If mouse click()=1 and bulletlife=0
Position Object 4,500+x,gy#-5,2515
Set object to camera orientation 4
Bulletlife =25
Show object 4
lock object on 4
endif
If bulleylife > 0
dec bulletlife
lock object off 4
Move object 4,20
If bulletlife = 0 then hide object 4
endif

` Update screen
sync

` End main loop when collision with ceiling
until get ground height(2,500+x,y)
"When you were born, you cried and the world rejoiced. Live so when you die, the world cries and you rejoice."
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 31st Dec 2002 22:36
Hey, I got the bullets to fire, but I have them positionedso they fire strait from my craft. The problem is that the follow the front of my craft when I move. Any help on this matter?

this is what defines gy#
gy#=curvevalue(50+get ground height(1,500+x,z),gy#,3)

Code for launching projectile
`Fire bullets
If controlkey()=1
Position Object 4,498+x,gy#-5,2490
Set object to camera orientation 4
Show object 4
endif
Move object 4,20

"When you were born, you cried and the world rejoiced. Live so when you die, the world cries and you rejoice."
soap_shoes
21
Years of Service
User Offline
Joined: 22nd Dec 2002
Location: United States
Posted: 1st Jan 2003 04:15
um...bishop? did u become a pro overnite? man, now im the only noob. how the hell do u make a function, and wtf do u use them for?

o anyway....i dont know bishop, sorry!
Good luck!

noobie game designer
John H
Retired Moderator
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 1st Jan 2003 04:58
-um...bishop? did u become a pro overnite? man, now im the only noob. how the hell do u make a function, and wtf do u use them for?

Very good code Its very, very easy to make a function, and you use them to make your code more efficient and stuff.

What do you want to do with the gun? Point it using the mouse? Well, first, you need to have an aiming sprite to use as the aiming thing. You need to hide the mouse, and position that image at the mouse coordinates. Next, do to it the easy way, you can point the object at the mouse position. The better way to do it, would be to slightly rotate the object when the cursor is moved.

RPGamer

Current - RPG: Eternal Destiny : Help Wanted!
http://www.halbrosproductions.netfirms.com
I hate those stupid backfaces! They are always screwing up!!!
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 1st Jan 2003 08:11
Thanx=)
Thanx for the help

Bishop

"When you were born, you cried and the world rejoiced. Live so when you die, the world cries and you rejoice."
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 1st Jan 2003 11:26
I have another question. I spent all day with my brother trying to get this code to word. I have a mouse retical, so ehn I move the mouse, the retical does as well. The problem is, when I move the craft, the mouse retical cannot move out of the screen to far. Here is my code;

`Hide mouse
hide mouse

` Load bitmaps
load bitmap "grass1.bmp",1
get image 1,0,0,256,256
delete bitmap 1

` Load music track
load music "Over5.mid",1
loop music 1

` Activate manual sync
sync on

` Make landscape and ceiling matrix
make matrix 1,2000,5000,10,25
prepare matrix texture 1,1,2,2
make matrix 2,2000,5000,10,25
prepare matrix texture 2,1,2,2
fill matrix 2,0,2
randomize matrix 2,350.0
for t=0 to 25
set matrix height 2,0,t,-100
set matrix height 2,10,t,-100
next t
update matrix 2

`Import cursor
load object "cusor.x",9
scale object 9,100000,100000,100000

`Make Screen
Make Object Cube 7,4

`Make Bullets
Make Object Sphere 4,2
hide object 4
Make Object Sphere 8,2
hide object 8

`Make Cockpit
load Object "gunL.x",1
load Object "gunR.x",2

`Make Gun
Make Object Cylinder 3,2
XRotate Object 3,90
Fix object pivot 3
Scale Object 3,100,100,500
Make Object Cylinder 6,2
XRotate Object 6,90
Fix object pivot 6
Scale Object 6,100,100,500

` Begin game loop
do

` Set seed for same random numbers
randomize 1

` Clear cave floor
fill matrix 1,0,1

` Set lighting, fog and setupset ambient light 20
color backdrop 0
if fog available()=1 then fog on : fog color 0 : fog distance 4000

` Reset speed
x=0
z=0
speed#=0.0

` Begin main loop
repeat

` Record old variables
oldx=x
oldgy#=gy#

`make mouse
mx#=mousex()+260
my#=mousey()*-1+260
oldmx#=mx#
oldmy#=my#

` Control key movements
if upkey()=1 then speed#=speed#+1.0 else speed#=speed#-1.0
if leftkey()=1 then rz#=rz#+1.0
if rightkey()=1 then rz#=rz#-1.0
if downkey()=1 then speed#=speed#-1.0

`Control gun movement


` Control variables
if speed#<0.0 then speed#=0.0
if speed#<10.0 then speed#=speed#+1.1
if speed#>40.0 then speed#=40.0
rz#=rz#/1.1
x=x-(2*rz#)

` Scroll landscape
z=z+speed#
if z>200
z=z-200
if rnd(3)=0
mp=mp-1
mp=mp+rnd(3)
if mp<1 then mp=1
if mp>4 then mp=4
endif
for t=0 to 0 : set matrix height 1,t,24,450 : set matrix tile 1,t,24,2 : next t
for t=1 to mp : set matrix height 1,t,24,rnd(200) : set matrix tile 1,t,24,2 : next t
for t=mp+1 to mp+1 : set matrix height 1,t,24,rnd(200) : set matrix tile 1,t,24,3 : next t
for t=mp+2 to mp+3 : set matrix height 1,t,24,rnd(20) : set matrix tile 1,t,24,1 : next t
for t=mp+4 to mp+4 : set matrix height 1,t,24,rnd(200) : set matrix tile 1,t,24,4 : next t
for t=mp+5 to 9 : set matrix height 1,t,24,rnd(200) : set matrix tile 1,t,24,2 : next t
for t=10 to 10 : set matrix height 1,t,24,450 : next t
update matrix 1
shift matrix up 1
shift matrix up 2
endif

`Position matrix
position matrix 1,0,0,2500-z
position matrix 2,0,100,2500-z

`Ghost on cube 7
Ghost object on 7

` Position camera
gy#=curvevalue(50+get ground height(1,500+x,z),gy#,3)
position camera 500+x,gy#,2500
zrotate camera wrapvalue(rz#)
Position Object 1,498+x,gy#,2500.7
Position Object 2,502+x,gy#,2500.7
Position object 3,498+x,gy#-5,2510
Position object 6,502+x,gy#-5,2510
Position object 7,497+x,gy#+1,2510
position object 9,mx#,my#,2800
disable object zdepth 9

`Fire bullets
If controlkey()=1
Position Object 4,498+x,gy#-5,2490
Position Object 8,502+x,gy#-5,2490
Set object to camera orientation 4
Set object to camera orientation 8
Show object 4
Show object 8
endif
Move object 4,20
Move object 8,20

` Update screen
sync

` End main loop when collision with ceiling
until get ground height(2,500+x,y)<gy#-100.0

` Return camera to point before collision
position camera 500+oldx,oldgy#,2500

` Game Over
for c=0 to 255 step 20
cls rgb(c,0,0)
if fog available()=1 then fog distance (c*5) : fog color (c*256*256)
sync
next c

` End game loop
Loop

Any help would be helpful. Thanx in advance!

Bishop

"When you were born, you cried and the world rejoiced. Live so when you die, the world cries and you rejoice."
John H
Retired Moderator
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 1st Jan 2003 17:51
So you want to be able to move the mouse as far left and right as you can- would it be to turn around easier? Well- id suggest if the mouse x value is < > a certain number- then swing the camera around 180 degrees.

RPGamer

Current - RPG: Eternal Destiny : Help Wanted!
http://www.halbrosproductions.netfirms.com
Dont ask those questions! Read the help files lazy!
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 1st Jan 2003 21:24
I can move my mouse as far left as right on the initial screen, but when my craft turns right or left from my initial screen, the mouse seems to be blocked in by invisable walls.

Bishop

"When you were born, you cried and the world rejoiced. Live so when you die, the world cries and you rejoice."
John H
Retired Moderator
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 1st Jan 2003 22:26
Hmmm, that is strange! Id at least try positioning the camera farther in the opposite direction of the cam and just see if it works.

RPGamer

Current - RPG: Eternal Destiny : Help Wanted!
http://www.halbrosproductions.netfirms.com
Dont ask those questions! Read the help files lazy!

Login to post a reply

Server time is: 2024-11-23 20:54:44
Your offset time is: 2024-11-23 20:54:44