EDIT: deleted original post
Wait, hold on dont post yet im thinking of something about changing my game because i just got a great idea... so i will have a diff. question on the same lines, but hold on one second
EDIT: new idea: ok since my game is top view, i was remembering this old arcade game i used to play that was like this, and what you did was just moved forwards and backwards , and when you hit left and right, it didnt strafe it just rotated it, so i put this in instead of what i originnaly had:
`if up arrow hit then increase hero speed
if Keystate(17)=1 then INC speed#,acceleration#
`down arrow decrease hero speed
if Keystate(31)=1 then DEC speed#,acceleration#
if Keystate(30)=1 then yrotate object hero,ay1#-1.4
if Keystate(32)=1 then yrotate object hero,ay1#+1.4
ok so then back to the mouse thing, instead of having my object shoot in the direction its facing, i was thinking of having it shoot in the direction of where the mouse was at, so you could shoot backwards while being chased by enemies.. but that is my delema..
i changed the code like this so you could see where the mouse was :
posx=mousex()
posy=mousey()
set cursor posx,posy
print "+"
but because when i rotated ....... blahhhh im confusing myself and thus you, just how could i make it so the bullets go towards the mouse position , not shooting from the front of the guy like it is now, this is my full code :
sync on
sync rate 60
set display mode 1024,768,32
backdrop on
Autocam Off
hide mouse
`Fog on
`Fog distance 200
`Fog color RGB(128,128,128)
Color Backdrop RGB(128,128,128)
Image_Size=64
for x = 0 to Image_Size
for y = 0 to Image_Size
dot x,y,rgb(0,rnd(156),0)
next x
next y
get image 1,0,0,Image_Size,Image_Size
cls
`matrix stuff
World=1
Size=1000
Segments=10
make matrix World,Size,Size,Segments,Segments
prepare matrix texture 1,1,1,1
update matrix World
hero=400
make object cube hero,4
randomize timer()
position object Hero,rnd(200),1,rnd(200)
`SET UP VARIABLES FOR HERO SPEED
`speed for hero
speed#=0.0
`acceleration speed
acceleration#=.009
`max speed hero can move at
MaxSpeed=1.4
`min speedhero can move at
MinSpeed=-1.0
`slowly move charector speed down when not moving
Friction#=.01
`make powerups for hero
PUpMSpeed=500
PUpAcc=501
AmmoCrate=502
`create power up objects and color
make object cube PUpMSpeed,3
color object PUpMSpeed,RGB (200,0,0)
make object cube PUpAcc,3
color object PUpAcc,RGB(0,200,0)
make object cube AmmoCrate,3
color object AmmoCrate,RGB(0,100,100)
`random position on matrix
randomize timer()
position object PUpMSpeed,rnd(800),1,rnd(800)
randomize timer()
position object PUpAcc,rnd(800),1,rnd(800)
randomize timer()
position object AmmoCrate,rnd(900),1,rnd(900)
`collision variables
set object collision on hero
set object collision on PUpMSpeed
set object collision on PUpAcc
set object collision on AmmoCrate
set object collision to boxes hero
set object collision to boxes PUpMSpeed
set object collision to boxes PUpAcc
set object collision to boxes AmmoCrate
dim active(200,2)
maxwait=100
for b=1 to 100
make object sphere b+100,2.6
color object b+100,rgb(255,0,0)
hide object b+100
next b
ammo#=50
Number_of_Enemies=50
dim EnemyState(Number_of_Enemies)
Enemy_Aware#=50
Enemy_Speed#=.7
for x = 1 to Number_of_Enemies
make object cube x,3
EnemyState(x)=rnd(2)
position object x,rnd(Size),1,rnd(Size)
next x
`MAIN LOOP
do
`Here are our variables for the Hero. These are just position values
x1#=object position x(Hero)
z1#=object position z(Hero)
y1#=get ground height(World,x1#,z1#)
ax1#=object angle x(hero)
ay1#=object angle y(Hero)
gosub Pos_Powerups
`stay on matrix
if x1#>Size then x1#=x1#-1
if x1#<0 then x1#=0
if z1#>Size then z1#=z1#-1
if z1#<0 then z1#=0
`camera follow hero
`set camera to follow x1#,y1#,z1#,ay1#,100,100,1,1
position object Hero,x1#,y1#+3,z1#
position camera object position x(hero),object position y(hero)+200,object position z(hero)
point camera object position x(hero),object position y(hero),object position z(hero)
`if up arrow hit then increase hero speed
if Keystate(17)=1 then INC speed#,acceleration#
`down arrow decrease hero speed
if Keystate(31)=1 then DEC speed#,acceleration#
`strafe left
if Keystate(30)=1 then yrotate object hero,ay1#-1.4
`strafe right
if Keystate(32)=1 then yrotate object hero,ay1#+1.4
`cap the speed off
if speed#>MaxSpeed then speed#=MaxSpeed
`cap the speed off
if speed#<MinSpeed then speed#=MinSpeed
`cap strafe speed off
if StrafeSpeed#>MaxStrafe then StrafeSpeed#=MaxStrafe
`when dec strafe cap it off
if strafespeed#<MinStrafe then StrafeSpeed#=MinStrafe
`move the hero
move object Hero,speed#
if Keystate(17)=0 and Keystate(31)=0
`if moving forward and not hitting up or down arrows, decrease speed
if speed#>=0.0
DEC speed#,Friction#
endif
`if moving backwards and not hitting up or down arrows, increase speed
if speed#<=0.0
INC speed#,Friction#
endif
endif
gosub Collision
gosub shoot
set cursor 900,600
print "Ammo: "; ammo#
set cursor 0,0
`display hero variables for viewing
print "X Position "; x1#
print "Z Position ";z1#
print "Y Position ";y1#
print "Speed ";speed#
posx=mousex()
posy=mousey()
set cursor posx,posy
print "+"
sync
loop
shoot:
for b=1 to 100
if mouseclick()=1 and ammo#>0 and active(b+100,1)=0 and (timer()-lasttime)>maxwait
position object b+100,x1#,y1#,z1#
set object to object orientation b+100,hero
active(b+100,1)=1
active(b+100,2)=100
show object b+100
ammo#=ammo#-1
lasttime=timer()
endif
if active(b+100,1)=1
move object b+100,7
active(b+100,2)=active(b+100,2)-1
endif
if active(b+100,2)<0
active(b+100,1)=0
active(b+100,2)=0
hide object b+100
endif
next b
return
Pos_Powerups:
`=====POWER UP VARIABLES=====
`FOR MAX SPEED
PUpMSpeed_X#=object position x(PUpMSpeed)
PUpMSpeed_Z#=object position z(PUpMspeed)
PUpMspeed_Y#=get ground height(world,PUpmspeed_x#,pupmspeed_z#)
`For Acceleration
PUpAcc_X#=object position x(PUpAcc)
PUpAcc_Z#=object position z(PUpAcc)
PUpAcc_Y#=get ground height(World,PUpAcc_X#,pupacc_z#)
AmmoCrate_X#=object position x(AmmoCrate)
AmmoCrate_Z#=object position z(AmmoCrate)
AmmoCrate_Y#=get ground height(world,AmmoCrate_x#,AmmoCrate_Z#)
`using PowerUp variables position the powerups on the map (in good spots)
position object PUpMSpeed,PUpMSpeed_X#,PUpMSpeed_Y#+2,PUpMspeed_Z#
position object PUpAcc,PUpAcc_X#,PUpAcc_Y#+2,PUpAcc_Z#
position object AmmoCrate,AmmoCrate_X#,AmmoCrate_Y#+2,AmmoCrate_Z#
return
Collision:
return
Enemies:
for x=1 to Number_of_Enemies
x2#=object position x(x)
z2#=object position z(x)
y2#=get ground height(World,x2#,z2#)
ay2#=object angle y(x)
color object x,rgb(128,0,0)
if x2#<x1# then x2#=x2#+Enemy_Speed#
if x2#>x1# then x2#=x2#-Enemy_Speed#
if z2#<z1# then z2#=z2#+Enemy_Speed#
if z2#>z1# then z2#=z2#-Enemy_Speed#
position object x,x2#,y2#+1,z2#
rotate object x,object angle x(x),ay2#,object angle z(x)
next x
return