- Code: Select all
key down "spacebar" =>create actor "bullet" x=+5; y=0
- Code: Select all
+xvelocity
- EasyHuMaN (EHMAN)
I CAN'T WAIT TO SEE YOUR RESPONSE AND TO PLAY THE GAME (+ [ ] × )
key down "spacebar" =>create actor "bullet" x=+5; y=0
+xvelocity
facingDir = 1; // The player starts facing right
// Your movement code is here
facingDir = 1;
// Your movement code is here
facingDir = -1;
int bulletSpeed = 20;
Actor *newBullet = CreateActor( ... ); // Get a pointer to the new bullet actor created
// If facingDir is 1, xvelocity will be 20, and if facingDir is -1, xvelocity will be -20
newBullet->xvelocity = bulletSpeed * facingDir; // Set the xvelocity for the bullet
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
tdmxross wrote:I am not good at programming, but this is my way to make the player shoot in the direction he is facing. Have a look at the fireball actors too.
lcl wrote:tdmxross wrote:I am not good at programming, but this is my way to make the player shoot in the direction he is facing. Have a look at the fireball actors too.
Yes, your solution also works, but it's needlessly complex. You use 4 variables for shooting direction, while only 1 is enough. Same goes for the fireball actor, you don't need 4 of those. Also, instead of using Draw Actor to update the bullet's x or y every frame, you could just use xvelocity, yvelocity or directional_velocity to give the actor a velocity when you create it.
tdmxross wrote:I am not good at programming, but this is my way to make the player shoot in the direction he is facing. Have a look at the fireball actors too.
facingY = 0;
facingY = - 1;
facingDir=0;
facingY = - 1;
facingDir=0;
Ehman wrote:And how can I make a restart button when my player is out of vision?
Ehman wrote:Thanks
Users browsing this forum: No registered users and 1 guest