Contra style shooting
by Dave Gilligan · in Torque Game Builder · 08/12/2008 (4:01 pm) · 19 replies
Hi everyone! I'm a bit of a beginner, and I'm trying to make a 2D style shooting game similar to Contra. I've got everything set up to where my character can move around and jump on platforms, but I can't get him to shoot properly. I went over the Shooter tutorial, and I got it to the point where a projectile will spawn, but it doesn't move, and for some reason my character moves backwards like an inch every time I shoot.
I tried downloading and using the shooter behavior from this site and the same problem happens. Can anybody help shed some light on this?
I tried downloading and using the shooter behavior from this site and the same problem happens. Can anybody help shed some light on this?
About the author
#2
08/12/2008 (5:41 pm)
That fixed that, thanks! Now I have to get him to shoot left when facing left, as he only shoots right at the moment. Any suggestions on how to do that?
#3
08/12/2008 (6:34 pm)
Also, I have a shooting animation, but I'm having trouble getting it to play when I call my shooting function. Sorry about all the questions
#4
If the player is flipped, the direction will be negative, otherwise it will be positive.
08/12/2008 (6:50 pm)
%bulletDirection = 2 * ($player.getFlipX() == false) - 1; %myBullet.setLinearVelocity(%bulletDirection * %bulletSpeed);
If the player is flipped, the direction will be negative, otherwise it will be positive.
#5
08/12/2008 (6:59 pm)
I don't understand exactly where this code would go and how it would work with my code, I'm sorry. =[
#6
08/12/2008 (7:23 pm)
I told it to shoot left when my character is in his running left state, so he shoots left while he's running left, and right while he's running right. My problem right now is that I don't know how to tell it to shoot left when my character is facing left and not moving. =\
#7
08/13/2008 (12:51 am)
Assuming you've drawn your art with the character facing right, and you're using something like $player.setFlipX(true) to make him face left, then you can check which way the player is facing, and fire the bullet left or right like this...if ($player.getFlipX()) %buletVector = "-100 0"; else %bulletVector = "100 0"; %bullet.setLinearVelocity(%bulletVector);
#8
the way connor put it, is a clever one, i 1st thought on using a dedicated boolean var that gets updated whenever the player changes its facing direction... but the method connor puts here, its a lil faster and economic.
08/14/2008 (10:57 pm)
Basically, its the same i told you in the other thread you started, using a test to check where the palyer is facing and shooting according to the result of that test....the way connor put it, is a clever one, i 1st thought on using a dedicated boolean var that gets updated whenever the player changes its facing direction... but the method connor puts here, its a lil faster and economic.
#9
Does that line really work? Or is it pseudocode? Its kind of reminiscent of a conditional, but without the "?".
08/17/2008 (5:22 am)
%bulletDirection = 2 * ($player.getFlipX() == false) - 1;
Does that line really work? Or is it pseudocode? Its kind of reminiscent of a conditional, but without the "?".
#10
08/17/2008 (7:31 am)
Looks valid. The comparison operation returns either 0 or 1, which gets factored into the math operation.
#11
08/18/2008 (9:04 pm)
But doesn't (2 * 0) - 1 = -1 ?? So you would need to check for a -1 or 1. It's not pretty, even by MY standards lol.
#12
08/18/2008 (9:47 pm)
Isn't that the point? It evaluates to either -1 or 1 and that tells you whether the x linear velocity should be positive or negative.
#13
If the player is flipped: 2 * (1 == 0) - 1 => 2 * 0 - 1 => -1;
If the player is not flipped: 2 * (0 == 0) - 1 => 2 * 1 - 1 => 1;
It is the same as:
Only shorter!
08/18/2008 (9:50 pm)
Bwah? That is an awesome snippet of code!If the player is flipped: 2 * (1 == 0) - 1 => 2 * 0 - 1 => -1;
If the player is not flipped: 2 * (0 == 0) - 1 => 2 * 1 - 1 => 1;
It is the same as:
if ($player.getFlipX())
%bulletDirection = -1;
else
%bulletDirection = 1;Only shorter!
#14
08/18/2008 (10:43 pm)
Oops ok I thought it was supposed to be a boolean 0 or 1. My bad. Still I'd go with that if/else Phillip just posted for readability sake, but hey whatever floats your boat ;)
#15
08/19/2008 (5:41 am)
That's awesome.
#16
Nifty math, but bad explainifying!
08/26/2008 (11:51 pm)
Phillip - your 'awesome' snippet scared the guy who asked the question right out of the thread! ;-)Nifty math, but bad explainifying!
#17
08/27/2008 (10:05 am)
I am back! I need to try some stuff and I'll let you guys know if I still can't get it!
#18
08/31/2008 (8:58 pm)
That fixed the directional problem! Thanks guys, that was pretty brilliant, I appreciate the help. :] I don't suppose you guys could help me get started on creating a duck state for my character now for when I press down. That's what I'm trying to do now, so I just thought I would ask. :]
#19
since its a contra style game, i suppose you use the directional keys to move around, up key for looking (and shooting) up, and the down key for shooting down (while airborne) or to crouch (if standing on the ground), am i right? (keep in mind that if what i just described is true, you need a dedicated key for jumping)...
well, if thats the case, a simpler way of doin the "duck" move is detect if the player is ariborne or not (you can do that by triggering certain condition at the very moment the jump key is pushed... thats just a way of doing it, anyway), that way, when you press the down key, you change the state to "crouch" or to "shoot down", depending on the condition stated above.
i hope its nearly clear what i just tried to explain w/o using code snippets.
09/03/2008 (6:53 am)
Well... it depends on how you designed your game.since its a contra style game, i suppose you use the directional keys to move around, up key for looking (and shooting) up, and the down key for shooting down (while airborne) or to crouch (if standing on the ground), am i right? (keep in mind that if what i just described is true, you need a dedicated key for jumping)...
well, if thats the case, a simpler way of doin the "duck" move is detect if the player is ariborne or not (you can do that by triggering certain condition at the very moment the jump key is pushed... thats just a way of doing it, anyway), that way, when you press the down key, you change the state to "crouch" or to "shoot down", depending on the condition stated above.
i hope its nearly clear what i just tried to explain w/o using code snippets.
Associate James Ford
Sickhead Games
Sounds like your player is colliding with his own projectiles. Setup your graphGroups / collisionGroups so this doesn't happen.