How to use keyevent for Gun Movement

View: New views
3 Messages — Rating Filter:   Alert me  

How to use keyevent for Gun Movement

by asherbaig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I have made my robot where i defined keys for power button instead of
using Mouse movement i want to use buttons for Gun.

But i am facing problem with Gun.How to set my gun direction
independent of Body to use buttons key for example


if pressed Vk_U = move 180 degree clockwise
if pressed Vk_I = move 180 degree Anticlockwise


Please need suggestion for developer.





Re: How to use keyevent for Gun Movement

by flemmingnlarsen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You can have a look on the sample.Interactive robot available in
Robocode. You could copy this robot in order to create your own version.

Then, in the very end of the onKeyPressed(KeyEvent e) you insert these
lines:

    char c = e.getKeyChar();
    if (c == 'u') {
        setTurnGunLeft(180);
    } else if (c == 'i') {
        setTurnGunRight(180);
    }

Voila!

Best regards,
- Flemming

--- In Robocode@..., "asherbaig" <devilvsevil@...> wrote:

>
> Hi,
> I have made my robot where i defined keys for power button instead of
> using Mouse movement i want to use buttons for Gun.
>
> But i am facing problem with Gun.How to set my gun direction
> independent of Body to use buttons key for example
>
>
> if pressed Vk_U = move 180 degree clockwise
> if pressed Vk_I = move 180 degree Anticlockwise
>
>
> Please need suggestion for developer.
>



Re: How to use keyevent for Gun Movement

by flemmingnlarsen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You can have a look on the sample.Interactive robot available in
Robocode. You could copy this robot in order to create your own version.

Then, in the very end of the onKeyPressed(KeyEvent e) you insert these
lines:

    char c = e.getKeyChar();
    if (c == 'u') {
        setTurnGunLeft(180);
    } else if (c == 'i') {
        setTurnGunRight(180);
    }

Voila!

Best regards,
- Flemming

--- In Robocode@..., "asherbaig" <devilvsevil@...> wrote:

>
> Hi,
> I have made my robot where i defined keys for power button instead of
> using Mouse movement i want to use buttons for Gun.
>
> But i am facing problem with Gun.How to set my gun direction
> independent of Body to use buttons key for example
>
>
> if pressed Vk_U = move 180 degree clockwise
> if pressed Vk_I = move 180 degree Anticlockwise
>
>
> Please need suggestion for developer.
>