Help with analog joystick

Started by swamprocker, November 18, 2014, 05:35:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

swamprocker

Hello... first time poster, long time lurker...

I'm attempting a top-down shooting game that requires 360 degree fixed movement (the ship points upwards at all time, but can move in all directions), and am having trouble trying to figure out how to move the object in a circular motion with the analog joystick. I can get 8-way movement using "x+=1", "x-=1", "y+=1", and "y-=1", but would like full circular motion, and can't wrap my head around it for some reason. Think of Dodonpachi or any myriad of shmups' movement as an example of what I'd like to accomplish. Any advice would be greatly appreciated. Thanks!

Kloppix

You can use the predefined local variable: angle. For example


if ( key( _left) )
     angle = angle + 5000;
end


The function advance() works pretty well with angle. Here you have a full program:


import "mod_map"
import "mod_key"
import "mod_video"
import "mod_grproc"

process main()
begin
    set_mode(640,480,32);
    graph = map_new(20,20,32);
    map_clear(0, graph, rgb(255,255,255) );
    x = 320; y = 240;
   
    repeat
        if (key(_left))
            angle = angle + 5000;
        end
       
        if (key(_right))
            angle = angle - 5000;
        end
       
        if (key(_up))
            advance(10);
        end
       
        frame;
    until (key(_esc))
end

swamprocker


swamprocker

I'm afraid that didn't work. I guess a better example of what I'd like to accomplish would be the old arcade game Centipede, and how the player's shooter moves. In that game, the player has a static sprite, but it can move in all directions using a trackball. What I'd like to be able to do is the same, except with the analog stick. I know how the analog stick functions work as far as how to tell when they're not dead-center, but can only get eight-way control with my method. Here's the code I'm using (pretty typical for eight-way movement):



if (stickx<0)
x-=plspd;
end
 
if (stickx>0)
        x+=plspd;
end
 
if (sticky<0)
        y-=plspd;
end
 
if (sticky>0)
        y+=plspd;
end

if (key(_left))
x-=plspd;
end

if (key(_right))
x+=plspd;
end

if (key(_up))
y-=plspd;
end

if (key(_down))
y+=plspd;
end

stickx and sticky point to the analog stick functions (joy_select, joy_getaxis, joy_getbutton).

So, basically I'm trying to get mouse movement, but with the analog stick. I hope this is a clearer explanation.

Thanks again for any help offered.