Page 1 of 1

Making a player shoot....

PostPosted: Mon Jan 12, 2009 10:05 pm
by LucasA33
How can you make it so, that when you push a certain button, it will shoot... I don't want it to stay, I want it to move the direction the player shoots...

Re: Making a player shoot....

PostPosted: Tue Jan 13, 2009 12:04 am
by skydereign
One way of doing this is to have a direction variable. You can make it an actor variable or global, it does not matter. When you move different directions, it will change this variable.
Moving left sets the variable to -1, while moving right to 1. You can expand this with the necessary directions.
Then you create actor, the projectile, perhaps with a keydown event. The actor will have create actor event, that should have code that sets the xvelocity.
Create Actor, Script Editor (Projectile)
Code: Select all
if (direction==1) // right
{
   xvelocity=5;
}
if (direction==-1) // left
{
   xvelocity=-5;
}
// Add the directions as necassary

There are other methods if you don't like this one, or this one does not work with your game.

Re: Making a player shoot....

PostPosted: Tue Jan 13, 2009 2:38 am
by DST
Code: Select all
xvelocity=direction*5;

will accomplish the same thing.

:)

The more we plan out our game, the less 'if' statements we'll need.

Here's an interesting one for spreadshots; when put into a keydown script, it will create more shots based on the powerup level of the shooter;

Event>MouseButtonDown>

Code: Select all
int i;
for (i=1; i<=powerlevel; i++){             //when powerlevel is 0, this loop will do nothing.
                                                     //20 is the angle offset for each 
                                                      //new shot in the spread.
myangle=(i*20);                              //sets bullet angle above
CreateActor("bullet", "bullet", "no parent", "no path", 0, 0, false);
myangle=-(i*20);                             //sets bullet angle below
CreateActor("bullet", "bullet", "no parent", "no path", 0, 0, false);
}
//Here's the main shot (0 degrees) which still happens if powerlevel is 0.
CreateActor("bullet", "bullet", "no parent", "no path", 0, 0, false);


You can then use the variable 'myangle' in the CreateactorEvent of Bullet:
angle=myangle; //myangle is a global integer
directional_velocity=5;


Now what this code does is create a larger spread of shots as the player grabs powerups; Eventually the player will be firing in 18 directions! (when his powerlevel is 9).

No if's or case switch needed. You could also add (player) angle to myangle; now for a smash tv type game, the spread emanates from whatever angle the player is shooting from.

Re: Making a player shoot....

PostPosted: Tue Jan 13, 2009 2:41 am
by skydereign
Yes, but it is easier to grasp the basics and build from that... at least that was the case for me. And I was using gameEditor to learn C. I had more complex ideas, but I started with the concepts I was learning, and built my game accordingly. Then again, not everyone is here to learn C.