Jump to content


Photo

Help with 8 way Direction variables!


  • Please log in to reply
12 replies to this topic

#1 Jeaper

Jeaper

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 03 March 2012 - 01:06 PM

Hi!
I am new to this community, this is my first post, so "hello world!" (sorry for my english)
Me and my friend are creating an arena style MOBA game for an arcade machine we are currently building, this machine is going to use an 8-way competition joystick.
Therefor I have coded the movement to 4 buttons (WASD) and it uses 8 way movement.

My problem is that I coded all the abilities to work with the built in variable direction (I was using 8 buttons to move before the joystick arrived) and another variable "global.direct" which sets a number for every direction (0-7).



Character information:
Object name: RedRavager
Visible = true
Solid = false
Depth = 0
Persistent = true
Parent = <no parent>
Mask = <same as sprite>

Room information:

Room Speed: 30

This is the code that affects the movement.

In Create:

directionOfPlayerSprite[0]=spr_right;
directionOfPlayerSprite[1]=spr_UpRight;
directionOfPlayerSprite[2]=spr_up;
directionOfPlayerSprite[3]=spr_UpLeft;
directionOfPlayerSprite[4]=spr_left;
directionOfPlayerSprite[5]=spr_DownLeft;

directionOfPlayerSprite[6]=spr_down;
directionOfPlayerSprite[7]=spr_DownRight;

// Här sätter upp en array för att hålla reda på vilken sprite som skall användas för varje riktning man rör sig i.

in Step:

This is the code for the movement. The variable "Spin" is to track if an ability is activated, if it is, its speed is higher then normal.

if canmove = true //om spelaren har tillåtelse att röra sig (pga av eventuella "stuns" eller "pushbacks".
{
if spin = false // Om spelaren använda Spin attacken eller inte, om han gjör det så ökar speed med 2.
{

//Här använder spelaren inte attacken Spin, därav är hastigheten lägre än i nästa stycke.


vx = (keyboard_check(ord("D")) - keyboard_check(ord("A"))) * 7; // 'ord("D")' = Höger och 'ord("A")' = Vänster.  // nummeret '*7;' = speed (Hastigheten man rör sig).
vy = (keyboard_check(ord("S")) - keyboard_check(ord("W"))) * 7; // 'ord("S")' = Nedåt och 'ord("W")' = Uppåt.    // nummeret '*7;' = speed (Hastigheten man rör sig).

if (vx != 0 || vy != 0) // Om någon riktnings knapp är nedtryckt.
{ 
 
        // Sätter rätt spriteanimation för det hållet som spelaren rör sig emot, sätter även animations hastighet.
        sprite_index = directionOfPlayerSprite[round(point_direction(
0, 0, vx, vy) / 45) mod 8];
        image_speed = 0.4;

        if (place_free(x, y + vy)) // Kollar om man kan röra sig i riktningen.
        {
                y += vy;
        }
        
        if (place_free(x + vx, y)) // Kollar om man kan röra sig i riktningen.
        {
                x += vx;
        }
}
else // Om ingen knapp är nedtryckt.
{
        image_speed = 0;
}
}
else // När spelaren använder attacken Spin
{

//Här använder spelaren attacken Spin, därav är hastigheten högre än i föregående stycke.


vx = (keyboard_check(ord("D")) - keyboard_check(ord("A"))) * 9; // 'ord("D")' = Höger och 'ord("A")' = Vänster.  // nummeret '*9;' = speed (Hastigheten man rör sig).
vy = (keyboard_check(ord("S")) - keyboard_check(ord("W"))) * 9; // 'ord("S")' = Nedåt och 'ord("W")' = Uppåt.    // nummeret '*9;' = speed (Hastigheten man rör sig).

if (vx != 0 || vy != 0) // Om någon riktnings knapp är nedtryckt.
{ 
 
        // Sätter rätt spriteanimation för det hållet som spelaren rör sig emot, sätter även animations hastighet.
        sprite_index = directionOfPlayerSprite[round(point_direction(
0, 0, vx, vy) / 45) mod 8];
        image_speed = 0.4;

        if (place_free(x, y + vy)) // Kollar om man kan röra sig i riktningen.
        {
                y += vy;
        }
        
        if (place_free(x + vx, y)) // Kollar om man kan röra sig i riktningen.
        {
                x += vx;
        }
}
else // Om ingen knapp är nedtryckt.
{
        image_speed = 0; // Animationen stannar.
}
}
}

Also in step:

This is my attempt to set the direction variables.

if keyboard_check(ord("W")) // Om spelaren rör sig uppåt (rör joysticken uppåt).
{

direction=90; // Variabel för att hålla reda på gradantalet.
global.direct = 0; // Varibel för att hålla reda på riktningen.
if keyboard_check(ord("D")) {direction=45; global.direct = 7;} // Om spelaren rör sig åt Höger och Upp så ändras variablerna till detta.
if keyboard_check(ord("A")) {direction=135; global.direct = 1;} // Om spelaren rör sig åt Vänster och Upp så ändras variablerna till detta.
}

if keyboard_check(ord("S")) // Om spelaren rör sig nedåt (rör joysticken nedåt).
{

direction=270; // Variabel för att hålla reda på gradantalet.
global.direct = 3; // Varibel för att hålla reda på riktningen.
if keyboard_check(ord("D")) {direction=315; global.direct = 5;} // Om spelaren rör sig åt Höger och Nedåt så ändras variablerna till detta.
if keyboard_check(ord("A")) {direction=225; global.direct = 4;} // Om spelaren rör sig åt Vänster och Nedåt så ändras variablerna till detta.
}

if keyboard_check(ord("A")) // Om spelaren rör sig åt vänster (rör joysticken åt vänster).
{
direction=180; // Variabel för att hålla reda på gradantalet.
global.direct = 2; // Varibel för att hålla reda på riktningen.
if keyboard_check(vk_up) {direction=135; global.direct = 1;} // Om spelaren rör sig åt Vänster och Upp så ändras variablerna till detta.
if keyboard_check(vk_down) {direction=225; global.direct = 4;} // Om spelaren rör sig åt Vänster och Nedåt så ändras variablerna till detta.
}

if keyboard_check(ord("D")) // Om spelaren rör sig åt höger (rör joysticken åt höger).
{

direction=0; // Variabel för att hålla reda på gradantalet.
global.direct = 6; // Varibel för att hålla reda på riktningen.
if keyboard_check(ord("W")) {direction=45; global.direct = 7;} // Om spelaren rör sig åt Höger och Upp så ändras variablerna till detta.
if keyboard_check(ord("S")) {direction=315; global.direct = 5;} // Om spelaren rör sig åt Höger och Nedåt så ändras variablerna till detta.
}


The variable direction works for every direction except for Up-Left and Down-Left.
The variable global.direct does not work at all.

Any Ideas?

Please help a swedish nerd! :D
  • 0

#2 Jeaper

Jeaper

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 03 March 2012 - 01:08 PM

I am sorry that all the comments are in Swedish, I can translate them if you want. :)
  • 0

#3 Jeaper

Jeaper

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 03 March 2012 - 01:22 PM

Just realised this was in the wrong forum, moving it, sorry guys!
No idea how to remove it tough >.<
  • 0

#4 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16802 posts
  • Version:GM:Studio

Posted 03 March 2012 - 01:33 PM

Just realised this was in the wrong forum, moving it, sorry guys!
No idea how to remove it tough >.<


You click the "report" button and ask for it to be moved... You DON'T repost the same topic elsewhere, though... Posted Image

However, all fixed now, and welcome to the GMC!
  • 1

#5 Jeaper

Jeaper

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 03 March 2012 - 01:41 PM

[/quote]

You click the "report" button and ask for it to be moved... You DON'T repost the same topic elsewhere, though... Posted Image

However, all fixed now, and welcome to the GMC!
[/quote]

thanks for the help with the post, most apriciated and sorry for taking your time by being sloppy!
  • 0

#6 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 4714 posts
  • Version:GM8

Posted 03 March 2012 - 08:55 PM

My first suggestion is if you're using a keyboard to move, use different keys and see if you get the same problem. You could be causing an I/O error. Try using the arrow keys. If that causes an error, use the number pad. If that causes an error, use T, D, B and right-shift. If any sort of oddball key combination causes problems, then it's not a simple I/O error and we can work from there.
  • 0

#7 Jeaper

Jeaper

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 03 March 2012 - 10:53 PM

I managed to fix the direction variable (was a typo)
but the global.direct still wont work.
  • 0

#8 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 4714 posts
  • Version:GM8

Posted 07 March 2012 - 05:41 AM

GOT IT! ... maybe.

Look at your code. See how you have global.direct=0 and all that before checking for the key combos? Use else statements and make the straight global.direct=0 the very last else condition.

so

if keyboard_check(down)
{
if keyboard_check(ord('Q')) global.direct=135
else
if keyboard_check(ord('E')) global.direct=45
else
global.direct=90
}
  • 0

#9 Jeaper

Jeaper

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 07 March 2012 - 10:36 AM

GOT IT! ... maybe.

Look at your code. See how you have global.direct=0 and all that before checking for the key combos? Use else statements and make the straight global.direct=0 the very last else condition.


Ill try this when I get home, thanks!
  • 0

#10 Jeaper

Jeaper

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 07 March 2012 - 01:53 PM

GOT IT! ... maybe.

Look at your code. See how you have global.direct=0 and all that before checking for the key combos? Use else statements and make the straight global.direct=0 the very last else condition.

so

if keyboard_check(down)
{
if keyboard_check(ord('Q')) global.direct=135
else
if keyboard_check(ord('E')) global.direct=45
else
global.direct=90
}

I just tried this and it did not work :( , the thing is, I need to track the direction "RedRavager" moves, because when I press the button : N, I need it to send an object flying towards that same direction, I need to do it differently for every direction because it looks completely retarded if they have the same creation origin.

Also, I need the object to change its sprite if varying of the 8 directions.

I had all this working when I used 8 buttons to move, but with the joystick I need it to work on 4 buttons.
  • 0

#11 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14392 posts
  • Version:GM:Studio

Posted 07 March 2012 - 02:03 PM

The code is too simple to fail. are you using space to shoot?
  • 0

#12 Jeaper

Jeaper

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 07 March 2012 - 02:40 PM

I am redesining the ability.. cba with it anymore, I think it might be an I/O bugg :\
  • 0

#13 Jeaper

Jeaper

    GMC Member

  • New Member
  • 10 posts
  • Version:GM8

Posted 07 March 2012 - 03:39 PM

Well, I just tried changing from using the N button as a trigger to the X button, and now it works perfectly, gg gamemaker, gg.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users