Oh, sorry, I thought you were making a platformer with basic shooting to left and right. But it's not that different if you want to shoot 4 ways (left, right, up, down).
Instead of -1 and 1 for left and right, which is nice for shooting only on the horizontal axis, we will now have to define 4 different directions. Let's choose these numbers:
- 0 - right
- 1 - up
- 2 - left
- 3 - down
At first look, it might seem a bit weird to start from right and go counter-clockwise from there, but there's a reason for that. Game Editor's angle system starts with 0 for right and rotates counter-clockwise from there, so 90 degrees for up, 180 for left and 270 for down. So, as you can see, our numbers align with that setup.
So, the next step is to just add the corresponding codes to the movement events to change the facingDir variable to the values listed above.
Now, you may not be familiar with angle and directional_velocity in Game Editor. These variables are actor variables (= variables, that each actor has their own values for. x and y are actor variables as well) that can be used together to move an actor in any direction by given angle with the speed of the given directional_velocity. For more information, check
GE script reference: angle and
GE script reference: directional_velocity.
Now, the only thing left is to adjust the shooting event. What we will do is to create a new bullet actor, set its angle equal to facingDir * 90, and then set it's directional_velocity to the speed we want to give to the bullet.
- Code: Select all
int bulletSpeed = 20; // Temporary variable for the speed to give to the bullet
Actor *newBullet = CreateActor( ... ); // Get a pointer to the new bullet actor created
newBullet->angle = facingDir * 90; // Set bullet movement angle
newBullet->directional_velocity = bulletSpeed; // Set bullet movement speed