### Autor Tema: Help with analog joystick  (Leído 2421 veces)

0 Usuarios y 1 Visitante están viendo este tema.

#### swamprocker

• Newbie
• Mensajes: 6
• Karma: 0
##### Help with analog joystick
« en: Noviembre 18, 2014, 09:35:23 am »
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!
« última modificación: Noviembre 18, 2014, 09:47:13 am por swamprocker »

#### Kloppix

• Full Member
• Mensajes: 241
• Karma: 14
• Sexo:
##### Re:Help with analog joystick
« Respuesta #1 en: Noviembre 20, 2014, 05:19:28 am »
You can use the predefined local variable: angle. For example

Código: [Seleccionar]
`if ( key( _left) )     angle = angle + 5000;end`The function advance() works pretty well with angle. Here you have a full program:

Código: [Seleccionar]
`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

• Newbie
• Mensajes: 6
• Karma: 0
##### Re:Help with analog joystick
« Respuesta #2 en: Noviembre 20, 2014, 05:50:31 am »
I'll give this a try. Thanks!

#### swamprocker

• Newbie
• Mensajes: 6
• Karma: 0
##### Re:Help with analog joystick
« Respuesta #3 en: Diciembre 07, 2014, 07:57:43 pm »
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):

Código: [Seleccionar]
` 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;endif (key(_right)) x+=plspd;endif (key(_up)) y-=plspd;endif (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.