Page 1 of 2

space invaders

PostPosted: Fri Jan 08, 2010 7:58 pm
by Behdadsoft
I want make a game similar to space invaders , But When I add shooting for ship don't act. I did many times before by use of the Tutorial but I didn't Successed. Please Guide Me
THANK A LOT

Re: space invaders

PostPosted: Fri Jan 08, 2010 8:24 pm
by Superbeni
One shot per key down or shooting until key is released?

The first version is easy:
make a key down event, add the key(s) to press for shooting, repeat: disabled and then select script editor.
Put this into the script:
Code: Select all
CreateActor("shot", "animation", "(none)", "(none)", 0, 0, false);

This create a shot every time you press the key.

If you want to shoot until the key is released, there are two ways: a timer or controlling it in the scrip.

The timer is better for the performance.

You put this instead of the other script:
Code: Select all
CreateTimer("Event Actor", "name", 30);


Add an timer event and put the first code in the script edtior.
This will create a shot every 30 frames, with 30 fps is this one shot per second.

The other way is a bit more complicating:
make a key down event, add the key(s) to press for shooting, repeat: enabled and then select script editor.
put this in it:
Code: Select all
x = x + 1;
if(x == 30)
{
CreateActor("shot", "animation", "(none)", "(none)", 0, 0, false);
x = 0;
}

This should also create the shot every second, because the variable (x) is increased every frame, the shot is created in every 30th frame.

Both ways should work, but i didnĀ“t test it.
I hope i could help.

Re: space invaders

PostPosted: Sat Jan 09, 2010 11:14 am
by thunderios
Or instead of 30 you can have a variable "FireRate" in case you want more than one type of ammo.
May I ask what you mean with "When I add shooting for ship don't act"? Does it mean the ship doesn't move? Or that the bullet isn't created? Something else?

Re: space invaders

PostPosted: Sat Jan 09, 2010 3:07 pm
by Behdadsoft
when add key down for shoot don't work it.

Re: space invaders

PostPosted: Sat Jan 09, 2010 4:51 pm
by j2graves
have you given the bullet actor a motion action?

Re: space invaders

PostPosted: Sun Jan 10, 2010 5:25 am
by Scorpion50o1
for bullet did you put Create Actor > Script Editor > yvelocity = yvelocity - 5;

Re: space invaders

PostPosted: Sun Jan 10, 2010 7:07 am
by Behdadsoft
Hi. I did everything that you told me,but the player still can't shoot.I'll send you my created file for you,please check it and find the problem,because I become confused and I don't know what should I do.Thanks a lot.

Re: space invaders

PostPosted: Sun Jan 10, 2010 7:18 am
by skydereign
You need to include the data folder when posting your game, otherwise we can't run it.

Re: space invaders

PostPosted: Sun Jan 10, 2010 8:56 am
by Behdadsoft
OK.

Re: space invaders

PostPosted: Sun Jan 10, 2010 9:14 am
by skydereign
You mean like this? If so, what you needed to do was add a keydown event for your ship that created the bullet actor. You already had the create actor event for the bullet setting the speed, but you did not actually have an event that would create the bullet.

Re: space invaders

PostPosted: Sun Jan 10, 2010 11:07 am
by j2graves
and make sure that 'create at startup' is set to 'no' on the bullet actor, that way it will only be created when you need it.

Re: space invaders

PostPosted: Sun Jan 10, 2010 12:16 pm
by Behdadsoft
OK. Thank you Very much.

Re: space invaders

PostPosted: Mon Jan 11, 2010 1:22 pm
by Behdadsoft
Hi.My ship fire from center,I want to fire from left and right side too.What should I do?

Re: space invaders

PostPosted: Mon Jan 11, 2010 3:40 pm
by thunderios
You'll have to set the position half the width of the ship to the left and to the right (x = 20 and x = -20, if the ship is 40 pixels wide).
Or, if you are using the Script Editor, type:
Code: Select all
CreateActor("Bullet", "Bullet", "(none)", "(none)", .5*width, 0, false);
and replace .5*width with -.5*width for the left bullet.

Re: space invaders

PostPosted: Fri Jan 15, 2010 10:00 am
by Behdadsoft
Ok.Thanks