Making a player shoot....

Non-platform specific questions.

Making a player shoot....

Postby LucasA33 » Mon Jan 12, 2009 10:05 pm

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...
LucasA33
 
Posts: 79
Joined: Mon Jul 21, 2008 12:17 am
Location: Science, Technology, Computers, Programming, and Robotics.
Score: 1 Give a positive score

Re: Making a player shoot....

Postby skydereign » Tue Jan 13, 2009 12:04 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Making a player shoot....

Postby DST » Tue Jan 13, 2009 2:38 am

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.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: Making a player shoot....

Postby skydereign » Tue Jan 13, 2009 2:41 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron