I tried adding unit selection to my game today, but the camera angle that I have seems to mess it all up. You will notice right away, that the unit selection object shoots away from the camera, travelling on the z axis, I tried changing the unit selection code around, so that it would go up and down on the y axis, but when I do that, it just shoots away and doesn't come back! The unit selection code is supposed to make the green cube follow the mouse, and select units. This is the version with no media, my other version has a ton of media, that is all rotated and lined up exactly as I want it, so if I was to to rotate the camera to make the selection code work properly, I lose sight of all my objects that I created, and cannot seem to find them. Here is the media-free version of my code, the green square should stay level with the other objects on screen, and hould move the white cubes when I click on them with the object....
`Vital project stats
`Name: Worlds at war
`Started: wednesday, December 22, 2004
`Genre: Strategy
`Author: Jerad Laxson
`Programmer: Jerad Laxson
`Artist: Jerad Laxson
set display mode 1024,768,16
Set camera range 1,10000
set current bitmap 0
position mouse screen width()/2, screen height()/2
rem the new mouse object to play with
make object cube 8000,10
position object 8000,0,0,0
set object collision to boxes 8000
color object 8000,RGB(128,128,0)
dim player(0)
dim selection(0)
`selection, allows you to select units
selection:
rem the new object selection code
rem -- here we move the user selection cube...
if object screen x(8000)=<mousex()
position object 8000,object position x(8000)+4,object position y(8000),object position z(8000)
endif
if object screen x(8000)=>mousex()
position object 8000,object position x(8000)-4,object position y(8000),object position z(8000)
endif
if object screen y(8000)=<mousey()
position object 8000,object position x(8000),object position y(8000),object position z(8000)+4
endif
if object screen y(8000)=>mousey()
position object 8000,object position x(8000),object position y(8000),object position z(8000)-4
endif
rem the select bit (replace with distance equation) Player 1
if player(0)=1
if mouseclick()=1
rem -- here we move any object selected by the user
if selection(0)
position object selection(0),object position x(8000),object position y(8000),object position z(8000)
else
t = object collision(8000,0)
rem -- here we test for all user movable objects...
if t > 59 and t < 63
selection(0) = t
endif
endif
else
selection(0) = 0
endif
endif
return
`end of selection!
`PLANETARY ARRAYS
dim earth(0)
dim venus(0)
dim mercury(0)
dim jupider(0)
dim mars(0)
dim saturn(0)
dim neptune(0)
dim uranus(0)
dim pluto(0)
dim planetx(0)
`Other ARRAYS
dim victorytimer(0)
`resource arrays.
dim money(0)
dim jeradium(0)
dim energy(0)
`camera variables!
x#=0
z#=-100
y#=0
`Planetary variabes 0=neutral, 1=player, 2=enemy
earth(0)=1
venus(0)=0
mercury(0)=0
jupider(0)=0
mars(0)=1
saturn(0)=0
neptune(0)=0
uranus(0)=2
pluto(0)=2
planetx(0)=2
`resources
money(0)=1000
jeradium(0)=1000
energy(0)=1000
`VICTORY TIMER
victorytimer(0)=1000
`unit variables, stores their health.
fighterhealth(0)=1
battleshiphealth(0)=1
destroyerhealth(0)=1
dim fighterhealth(0)
dim battleshiphealth(0)
dim destroyerhealth(0)
`make planets
mercury=1
make object sphere mercury,10
set object collision on mercury
position object mercury,-400,0,0
rotate object mercury,90,0,0
venus=2
make object sphere venus,10
set object collision on venus
position object venus, -200,0,0
rotate object venus,90,0,0
earth=3
make object sphere earth,10
mars=4
make object sphere mars,10
set object collision on mars
position object mars,200,0,0
jupider=5
make object sphere jupider,60
position object jupider, 400,0,0
saturn=6
make object sphere saturn,20
set object collision on saturn
position object saturn, 600, 0,0
neptune=7
make object sphere neptune,30
set object collision on neptune
position object neptune,800,0,0
uranus=8
make object sphere uranus,30
set object collision on uranus
position object uranus, 1000, 0,0
pluto=9
make object sphere pluto, 15
color object pluto,RGb(0,0,255)
set object collision on pluto
position object pluto, 1200, 0,0
`planet x
planetx=10
make object sphere planetx,30
set object collision on planetx
position object planetx, 1300,0,0
for asteroids=11 to 50
make object cube asteroids,5
rotate object asteroids,0,rnd(50),rnd(50)
next asteroids
`make the units
fighter=60
make object cube fighter,3
set object collision on fighter
position object fighter,20,0,0
battleship=61
make object cube battleship,5
set object collision on battleship
position object battleship,20,15,0
destroyer=62
make object cube destroyer,6
set object collision on destroyer
position object destroyer,20,25,0
`main loop!
sync on
sync rate 30
do
gosub selection
`PAUSE BUTTON!
if inkey$()="p"
repeat
until inkey$()=""
repeat
center text screen width()/2,screen height()/2,"PAUSED"
sync
until inkey$()="p"
repeat
until inkey$()=""
endif
`Camera stuff!
position camera 0+x#,0+y#,0+z#
`moves camera right
if rightkey()=1 and x#<2000
x#=x#+5
endif
`moves camera left
if leftkey()=1 and x#>-2000
x#=x#-5
endif
`moves camera up
if upkey()=1 and y#<500
y#=y#+1
endif
`moves camera down
if downkey()=1 and y#>-500
y#=y#-1
endif
sync
loop
Oh, and by the way, if anyone has a better idea for unit selection, and can tell me how to do it I'm all ears.
Thanks.
Guns arn't the problem, people are the problem, shoot all the people and guns arn't a problem anymore.