2 bullet actor

Talk about making games.

2 bullet actor

Postby Behdadsoft » Fri Sep 13, 2013 8:22 am

Hi.

I made a character that can shoot to 4 Direction and I made bullet actor for shoot. But I want change x, y position when the player is holding the gun up. Because I want Bullet out of the barrel of a gun.
Now I should make another bullet actor or can change x, y Position when the player is holding the gun up?

Please Guide Me.
There is no possible way, if we found will make a way.

http://behdadsoft.com/
*******************************************************************
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0
User avatar
Behdadsoft
 
Posts: 207
Joined: Wed Dec 16, 2009 9:19 pm
Score: 2 Give a positive score

Re: 2 bullet actor

Postby skydereign » Fri Sep 13, 2013 8:29 am

Don't create another bullet actor. In the event where you create the first bullet, add some code to create the actor in different positions depending on which direction the gun is facing.
Code: Select all
// something like this
switch(dir)
{
    case 0: // right
    CreateActor("bullet", "bullet", "(none)", "(none)", 10, 0, false);
    break;

    case 1: // up
    CreateActor("bullet", "bullet", "(none)", "(none)", 0,  -10, false);
    break;

     // and so on
}


Depending on the location of the barrel, you could simplify the code into one CreateActor call.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: 2 bullet actor

Postby Behdadsoft » Fri Sep 13, 2013 10:09 am

thanks

I use this code :

Code: Select all
// something like this
switch(right)
{
case 1: // right
CreateActor("White_Bullet", "White_Bullet", "(none)", "(none)",3.5, -4, false);
break;
}

switch (up)
{
case 1: // up
CreateActor("White_Bullet", "White_Bullet", "(none)", "(none)",2, -25, false);
break;
}


but when the Player is holding the gun up, two bullets out of the gun.

also I create actor on bullet actor and used this code:

Code: Select all
// Player shoot to Left & Right
if (right == 1 && left == 0) xvelocity += 7;
if (left == 1 && right == 0) xvelocity -= 7;

// Player shoot to UP
if (right == 1 && left == 0 && up == 1)
{
xvelocity = 0;
yvelocity -= 7;
}

if (left == 1 && right == 0 && up == 1)
{
xvelocity = 0;
yvelocity -= 7;
}
There is no possible way, if we found will make a way.

http://behdadsoft.com/
*******************************************************************
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0
User avatar
Behdadsoft
 
Posts: 207
Joined: Wed Dec 16, 2009 9:19 pm
Score: 2 Give a positive score

Re: 2 bullet actor

Postby skydereign » Fri Sep 13, 2013 10:17 am

I recommend only using one variable for direction. The problem is both those switch statements will create an actor if up and right are set to 1. You could use an if, else if, else statement to handle this, but cleaning up direction by putting it in one variable would be all around better.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: 2 bullet actor

Postby Behdadsoft » Fri Sep 13, 2013 10:49 am

even I used if statement but when I changed x, y bullet position don't change it.

Code: Select all

if ((right == 1 && left == 0) || (left == 1 && right == 0))
{
CreateActor("White_Bullet", "White_Bullet", "(none)", "(none)",3.5, -4, false);
}

else

if ((right == 1 && left == 0 && up == 1) || (left == 1 && right == 0 && up == 1))
{
CreateActor("White_Bullet", "White_Bullet", "(none)", "(none)",1, -10, false);
}
There is no possible way, if we found will make a way.

http://behdadsoft.com/
*******************************************************************
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0
User avatar
Behdadsoft
 
Posts: 207
Joined: Wed Dec 16, 2009 9:19 pm
Score: 2 Give a positive score

Re: 2 bullet actor

Postby skydereign » Fri Sep 13, 2013 11:01 am

That code is rather messy looking. It's hard to tell what direction you mean. Here's how it looks when simplified into pseudocode.
Code: Select all
if(right or left)
{
     create bullet at (3.5, -4)
}
else if ((up and right) or (up and left))
{
    create bullet at (1, -10)
}

Notice the else if part will never trigger. The first condition must be true for the second to ever trigger, and it is already caught by the first if. To do what you want, you would need to add up==0 checks to the first if. But again I don't recommend, as using one variable for direction will make your code much easier in the end.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: 2 bullet actor

Postby Behdadsoft » Fri Sep 13, 2013 11:11 am

Thanks skydereign It is much cleaner.
+1

my character have 8 direction how can use 1 variable ? I want improve it.
There is no possible way, if we found will make a way.

http://behdadsoft.com/
*******************************************************************
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0
User avatar
Behdadsoft
 
Posts: 207
Joined: Wed Dec 16, 2009 9:19 pm
Score: 2 Give a positive score

Re: 2 bullet actor

Postby skydereign » Fri Sep 13, 2013 11:26 am

It depends on how you handle directions. The general idea is you have one variable dir, that can have 8 values (0-7). Typically 0 is right, 1 is up right, 2 is up, and so on. When you press a key, you can change the dir variable depending on what the value already was via a switch statement.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: 2 bullet actor

Postby Behdadsoft » Fri Sep 13, 2013 11:31 am

this is an demo of my game:

right arrow = move to right
left arrow = move to left
up arrow = look up
down arrow = sit
space arrow = jump
right + up = mid right up
left + up = mid left up
right + down = mid right down
left + down = mid left down
x = shoot

https://www.dropbox.com/s/zsf9hlxsqzf9yjn/Contra.exe

i have some problem if you can help me.
There is no possible way, if we found will make a way.

http://behdadsoft.com/
*******************************************************************
My Game : Star Wars 1.0

http://behdadgame.com/index.php?topic=3.0
User avatar
Behdadsoft
 
Posts: 207
Joined: Wed Dec 16, 2009 9:19 pm
Score: 2 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron