GameMaker: Studio

GameMaker: Studio

View Stats:
segasaturn Sep 13, 2021 @ 3:13pm
Important help required
Hello

I'm currently on my way to make a shoot'em up game. But already on the first day of development, a big problem appears : My test ship can't even shoot....diagonally when going to the Northwest or the Southeast (But EVERYTHING else is perfectly fine, when not moving, in the four main directions and when going in diagonal SW or NE). What could possibly be the cause of it? This project means a lot for me as I intend it to be my first released game to finance my studies (and I've been able to make other shmup in the past, they just didn't went diagonal in their movement). Can someone please help me? I use Game Maker Studio 1, v.1.4.9999. Guarantee to be in the credits of my game for helping ;)

First, the problem doesn't seem to be from the projectile since when changing the spawning of the projectile to an inanimate block that doesn't move for testing, everything went fine and as intended...except for these cursed two directions of NW and SE, period.

Secondly, here is the code for the ship :

Create (just code):
hsp = 0; (unused)
vsp = 0; (unused)
movespeed = 4;
can_shoot = true;

Step : Code
//keyboard

key_right = keyboard_check(vk_right);
key_left = keyboard_check(vk_left);
key_up = keyboard_check(vk_up);
key_down = keyboard_check(vk_down);
key_space = keyboard_check(vk_space);

//inputs (unused)

//move = key_left + key_right;
//movev = key_up + key_down;
//hsp = move * movespeed;
//vsp = movev * movespeed;

//shooting

if key_space = true
{{
if can_shoot = true
{{
alarm[0] = 2
}}
}}

if x < 0 {{x = 0;}}
if x > room_width {{x = room_width}}
if y < 0 {{y = 0}}
if y > room_height-16 {{y = room_height-16}}

Step : setting variables (with blocks)
if global.Proj_number is less than or equal to 4
-»Set Variable can_shoot to true

if global.Proj_number is greater than 4
-» Set Variable can_shoot to false

Alarm 0 : Create instance (the one I manipulated earlier with the blue lazy block)
Create instance of TriangleTestShipProj at relative position (0,-16)

Left : x -= movespeed;
Up : y -= movespeed;
Right : x += movespeed;
Down : y+= movespeed;

P.S: If, by the way, someone could give a tip on how to be able to autofire by keeping the space bar pressed, that'd be amazing.:steamhappy:
< >
Showing 1-12 of 12 comments
The Winter Bud Sep 13, 2021 @ 4:01pm 
//move = key_left + key_right; // key_right-key_left //movev = key_up + key_down; // key_down-key_up

your way move can be
0,1,2
my way move can be
-1,0,1
Last edited by The Winter Bud; Sep 13, 2021 @ 4:02pm
The Winter Bud Sep 13, 2021 @ 4:05pm 
you only need 1 set of curly braces not 2
if key_space = true {{ if can_shoot = true {{ alarm[0] = 2 }} }} //turn into if key_space = true { if can_shoot = true { alarm[0] = 2 } }
The Winter Bud Sep 13, 2021 @ 4:07pm 
why check for move_keys in the step event and set the a speed variable and then turn around and not use any of it just to set the left,right,up,down button events to movespeed?
key_right = keyboard_check(vk_right); key_left = keyboard_check(vk_left); key_up = keyboard_check(vk_up); key_down = keyboard_check(vk_down); move = key_right-key_left movev = key_down-key_up hsp = move * movespeed; vsp = movev * movespeed; if(place_empty(x+hsp,y)) x += hsp; if(place_empty(x,y+vsp)) y += vsp; //EDIT: get rid of the move key events
Last edited by The Winter Bud; Nov 23, 2021 @ 9:40am
The Winter Bud Sep 13, 2021 @ 4:16pm 
P.S: If, by the way, someone could give a tip on how to be able to autofire by keeping the space bar pressed, that'd be amazing
//create event can_shoot=true; shoot_timer=0; shoot_max=30; // 1 every 30 steps - lower it to shoot faster, increase teh value to go slower
//step event shoot_key=keyboard_ check(vk_space); shoot_timer++; if(shoot_timer>shoot_max){ can_shoot=true; shoot_timer--; } if(shoot_key){ if(can_shoot){ can_shoot=false; shoot_timer=0; var bul=instance_create(someX,someY,obj_bullet); bul.direction=direction; //EDIT: fixed the problem } }
Last edited by The Winter Bud; Nov 23, 2021 @ 9:50am
segasaturn Sep 18, 2021 @ 4:50pm 
your var bul.direction is causing problem, my program marks it as an error and refuses to boot the game so i had to cut it out, otherwise the autofire is just fine. Also can you explain why only these 2 directions out of 8 refuses to spawn things, because this main problem continues to exist (I can't even move NW or SE while autofiring, it just block, lol)
segasaturn Sep 18, 2021 @ 4:52pm 
Also, my projectile is called TriangleTestShipProj if that can help you.
segasaturn Sep 18, 2021 @ 4:53pm 
And my game is a vertical shoot'em up like 1942 or Space Invaders (only now with the possibility of moving in 8 directions if I could just pull it off).
segasaturn Sep 21, 2021 @ 10:29pm 
hello?
The Winter Bud Nov 23, 2021 @ 9:43am 
Originally posted by segasaturn:
your var bul.direction is causing problem, my program marks it as an error and refuses to boot the game so i had to cut it out, otherwise the autofire is just fine.
the line needs to cut out "var" from it. I don't know why I put that there. See code again for correction.
Last edited by The Winter Bud; Nov 23, 2021 @ 10:09am
The Winter Bud Nov 23, 2021 @ 10:02am 
Originally posted by segasaturn:
Also can you explain why only these 2 directions out of 8 refuses to spawn things, because this main problem continues to exist (I can't even move NW or SE while autofiring, it just block, lol)
when you create objects like projectiles you have to give them a direction and a speed or they just stay where they are created. You can do this by either giving them a speed and direction when you create them:
//step event of shooter if(can_shoot){ can_shoot=false; var bul=instance_create(someX,someY,obj_bullet); bul.speed=10; bul.direction=direction; } // the above code will create an instance of a bullet and tell that bullet to move in the same direction as the shooter at a speed of 10.
or the projectile itself can have a default speed and direction in it's create event
// projectile create event speed=10; direction=point_direction(x,y,room_width div 2, room_height div 2); // the above code will move the projectile to the center of the room
one way to make a spatter is to create 6-8 bullets in a circle around teh ship
if(can_shoot){ can_shoot=false; for(var i=0;i<8;i++;){ var bul=instance_create(x,y,obj_bullet); bul.direction=direction+45*i; bul.speed=10; } } //the above code will create 8 bullets in a circle around the shooter and have them radiate outwards from the ship.
You can add in a target variable (you must supply the target if you do so)and have the bullets radiate out from the target.
if(can_shoot && instance_exists(target)){ can_shoot=false; for(var i=0;i<8;i++;){ var bul=instance_create(target.x,target.y,obj_bullet); bul.direction=45*i; bul.speed=10; } } //the above code will create 8 bullets in a circle around the target and have them radiate outwards from the target.
Last edited by The Winter Bud; Nov 23, 2021 @ 10:11am
The Winter Bud Nov 23, 2021 @ 10:20am 
one thing to note is you must give your ship a direction value for the shooting code to work otherwise the bullet will just move to the right as a direction value of (0) is to the right. If you are using teh movement code supplied above you can easily adapt the code to receive direction.
key_right = keyboard_check(vk_right); key_left = keyboard_check(vk_left); key_up = keyboard_check(vk_up); key_down = keyboard_check(vk_down); move = key_right-key_left movev = key_down-key_up hsp = move * movespeed; vsp = movev * movespeed; //below is the adaptation for direction direction=point_direction(x,y,x+hsp,y+vsp); if(place_empty(x+hsp,y)){ x += hsp; } if(place_empty(x,y+vsp)){ y += vsp; }
Last edited by The Winter Bud; Nov 23, 2021 @ 10:23am
The Winter Bud Nov 23, 2021 @ 10:25am 
another thing is you can shoot towards the mouse instead of the ship's direction
if(can_shoot){ can_shoot=false; var bul=instance_create(x,y,obj_bullet); bul.speed=10; bul.direction=point_direction(x,y,mouse_x,mouse_y); }
< >
Showing 1-12 of 12 comments
Per page: 1530 50