Jump to content


Photo

2D shoot em up without a mouse


  • Please log in to reply
4 replies to this topic

#1 Subjugater247

Subjugater247

    GMC Member

  • GMC Member
  • 207 posts
  • Version:GM:Studio

Posted 03 June 2012 - 04:26 AM

Well I was having issues creating my bullets to fire in a certain direction. I got it to work in a way that it fires in the direction I want, but I also want to be able to fire in a direction behind me, like for example im running away and I want to shoot + run away. Does anyone have any idea's on how I can achieve it. My friend and I only came up with two ways... my solution was to have a key that fires forward and then have a key that fires backwards which could be annoying. My buddies idea was to have wasd for movement and use the arrow keys to specify direction. another issue within this is that I also want to try to find a way to make the bullets shoot in diagonal directions. Here is my code so far

if (keyboard_check(vk_left))
{
    x -= 5;
    player_direction = 180;
}
if (keyboard_check(vk_right)) 
{
    x += 5;
    player_direction = 0;
}
if (keyboard_check(vk_up)) 
{
    y -= 5;
    player_direction = 90;
}
if (keyboard_check(vk_down))
{
    y += 5;
    player_direction = 180;
}
if (keyboard_check(vk_space))
{
    bullet = instance_create(myufi_fighter.x, myufi_fighter.y, obj_bullet)
    bullet.direction = player_direction;
}

  • 0

#2 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5381 posts
  • Version:GM:Studio

Posted 03 June 2012 - 04:35 AM

you could lock the shooting direction when space is held down:

if (!keyboard_check(vk_space)) player_direction = 180; // if space isn't down .. change direction


EDIT: barely noticed your subquestion

you might want the script from this site:
http://www.gmlscripts.com/script/angle_difference

then you can change the same part of your code to:
if (!keyboard_check(vk_space))
&& alarm[0]<0{ // and alarm 0 is off
  player_direction += sign( angle_difference(player_direction,180) ) * 45; // could be that you need to switch around the angle_difference(A,B) arguments
  alarm[0] = 20; // the amount of delay before it should jump 45 more degrees towards the direction you want
}

and ofc.. you need to put a comment in the alarm 0 event to keep countdown active

Edited by FoxInABox, 03 June 2012 - 04:42 AM.

  • 0

#3 Jake Armstrong

Jake Armstrong

    GMC Member

  • GMC Member
  • 390 posts

Posted 03 June 2012 - 04:38 AM

One idea I have is that you could have a "keep direction" key. While you are holding that key, you won't turn and can keep shooting in the same direction you were last facing no matter which way you move. Once you let go of the key you will start facing in the direction you are moving again. EDIT: NINJA'D!

For diagonal you can do:

if (keyboard_check(vk_left) && keyboard_check(vk_up))
{
player_direction = 135;
}

// other 3 diagonals

You could also change all the ifs to else ifs and then put actual movement in the diagonal sections as well. Right now in your code when you walk diagonally you are actually walking 1.4 times faster than walking straight because you are moving full up/down speed and full left/right speed.

Edited by Jake Armstrong, 03 June 2012 - 04:39 AM.

  • 0

#4 Subjugater247

Subjugater247

    GMC Member

  • GMC Member
  • 207 posts
  • Version:GM:Studio

Posted 03 June 2012 - 05:12 AM

okay thanks for the info. I think for now I might have to use another key for that kind of shooting. The only reason I didn't want to do something like this was because I wanted tone this game down if it came out nice and release a little app version. Shooting could become a problem then since I could only touch the screen which seems inefficient or use joysticks which would be the same as the keyboard. So I would rather find out the info now so I can easily handle that problem later if it arises. Thanks again
  • 0

#5 fenyxofshadows

fenyxofshadows

    coobie

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 03 June 2012 - 05:13 AM

If you want to avoid using the mouse, then either using controller input to use two analog sticks, or using arrows to control direction, would be the best two options for an arena shoot-em-up like what you and your friend are aiming for. Of course, if you are willing to change the gameplay a bit, you can make it a scrolling shoot-em-up and have the player face 1 direction only (similar to the arcade shoot-em-up Galaga). Or you could make it intertia-based like Asteroids or Sinistar.

For shooting, look up Super Stardust. You control a ship with one joystick, and aim the direction you shoot with the other joy stick. While you are aiming your direction, you automatically shoot. Also, look up the iOS shooter Bug Princess. They have shooting be toggleable - either you are auto shooting or you are not shooting.

Edited by fenyxofshadows, 03 June 2012 - 05:15 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users