Some questions for my almost-complete game.

Talk about making games.

Re: Some questions for my almost-complete game.

Postby skydereign » Mon Jan 20, 2014 7:39 am

jonathang wrote:Hm, this doesn't work, doing if(temp_bomb->cloneindex!=-1 && yscreen< view.height) also doesn't work.

First off, do you know what and (&&) is? If you want an if statement to be dependent on two things, you should use the and operator instead of nesting if statements.
Code: Select all
if(this==0 && that==1)
{
    // only runs with this is 0 and that is 1
}


Now, that condition is not the one that I mentioned.
Code: Select all
int dist = distance(x, y, bomb.x, bomb.y); // this sets the distance to the lowest indexed bomb
int target = bomb.cloneindex; // for now assume the lowest indexed is the target
int i;
Actor* closest;

for(i=bomb.cloneindex; i<highest_bomb; i++)
{
    Actor* temp_bomb = getclone2("bomb", i);
    if(temp_bomb->cloneindex!=-1) // <-- this is the line you want to change
    {
        int temp_dist = distance(x, y, temp_bomb->x, temp_bomb->y);
        if(temp_dist < dist)
        {
            dist = temp_dist;
            target = i;
        }
    }
}

closest = getclone2("bomb", target);
if(closest->cloneindex!=-1)
{
 
}

The above code has the line you want to change commented. That if statement acts as a filter, in this case it filters out all invalid bomb actors.What you want it to do is ignore all of the bombs that are targeted and in the danger zone. You know a bomb is tarted if temp_bomb->targeted is equal to one. You know a bomb is in the safe zone if temp_bomb->yscreen < view.height - 50 (or however big the danger zone is). That code you added about target!=i doesn't do anything you want it to do. The only other time you use targeted is in the last if statement of the code I provided. At that point you want to set closest->targeted equal to one, so no other computer will target it.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Some questions for my almost-complete game.

Postby DeltaLeeds » Mon Jan 20, 2014 8:18 am

Code: Select all
int dist = distance(x, y, bomb.x, bomb.y); // this sets the distance to the lowest indexed bomb
int target = Bomb.cloneindex; // for now assume the lowest indexed is the target
int i;
Actor* closest;

for(i=Bomb.cloneindex; i<highest_bomb; i++)
{
    Actor* temp_bomb = getclone2("bomb", i);
    if(temp_bomb->cloneindex!=-1)//<-- this is the line you want to change
    {
        if(temp_bomb->yscreen < view.height - 50)
        {
        int temp_dist = distance(x, y, temp_bomb->x, temp_bomb->y);
        if(temp_dist < dist)
        {
            dist = temp_dist;
            target = i;
        }
        }
    }
}

closest = getclone2("bomb", target);
if(closest->cloneindex!=-1)
{
    if(closest->Targeted==0 || closest->Targeted==3)//If targeted is 1, the 2nd computer will get it, if targeted is 2, the 3rd computer will get it, and etc. (Until 3.)
    {
    closest->Targeted=3;
 //Refrence
    }
}

Ok, so this is what I've changed so far. I don't think I did it right, again...
Code: Select all
    if(temp_bomb->cloneindex!=-1)//<-- this is the line you want to change

I bet it's because I had to change something in this code, but I still don't really know what. Is this line: if(closest->Targeted==0 || closest->Targeted==3) supposed to be there too, or I had to move it there... I did try a first time, but I got the same results. Sorry I suck at getting instructions done right. :(
P.S: That piece of code was for the 4th computer.
Currently: Semi-Active.
Working on: Maybe putting my test games in gamejolt, polishing them a bit, but I still don't know when.
User avatar
DeltaLeeds
 
Posts: 693
Joined: Fri May 06, 2011 12:45 pm
Location: In front of my computer.
Score: 38 Give a positive score

Re: Some questions for my almost-complete game.

Postby skydereign » Mon Jan 20, 2014 9:04 pm

jonathang wrote:P.S: That piece of code was for the 4th computer.

Why are your computers separate actors?

jonathang wrote:Ok, so this is what I've changed so far. I don't think I did it right, again...

The targeted variable only holds two possible values. It is either one or zero. When it is one that means a computer has targeted the bomb and therefore other computers should ignore it. If it is zero that means no computer is targeting it and it should be able to be targeted. That is all the variable does. Targeted should never be set to 3. Currently you are trying to set it equal to the computer that is targeting it, but that means there is no way of telling if the first computer already targeted it. Here's a commented version of your code, explaining what the code is supposed to be doing and what lines are wrong.

jonathang wrote:
Code: Select all
int dist = distance(x, y, bomb.x, bomb.y); // this sets the distance to the lowest indexed bomb
int target = Bomb.cloneindex; // for now assume the lowest indexed is the target
int i;
Actor* closest;

// this loops through all possible bombs
for(i=Bomb.cloneindex; i<highest_bomb; i++)
{
    Actor* temp_bomb = getclone2("bomb", i); // temp_bomb holds a reference to bomb.i


    if(temp_bomb->cloneindex!=-1) // <-- this is the line that filters out bombs (the cloneindex!=-1) filters out bombs that have been destroyed
    {
        if(temp_bomb->yscreen < view.height - 50) // <-- this works as another filter (you should stick this with the above line using &&
        {
            // you want to add one more filter, temp_bomb->targeted==0
            // by this point only bombs that exist and are in the safe zone can possibly trigger this code

            int temp_dist = distance(x, y, temp_bomb->x, temp_bomb->y); // get the distance to bomb.i
            if(temp_dist < dist) // if it is less than the last closest bomb
            {
                dist = temp_dist; // make it the closest bomb
                target = i; // remember the cloneindex of the closest bomb
            }
        }
    }
}

// by this point the above code has already found the closest bomb based off of the filters
// in the above code it is filtering for real bombs and ones in the safe zone

// this last section gets a reference to the bomb so you can move to it
closest = getclone2("bomb", target); // gets bomb.target
if(closest->cloneindex!=-1) // double check if the bomb exists (this can happen if no bomb actors exist)
{
    // this next line of code is not what I told you to do
    if(closest->Targeted==0 || closest->Targeted==3) // <--- all this line of code should be doing is checking if closest->Targeted is equal to zero (as in the bomb has not been targeted)
    {
        closest->Targeted=3; // <-- this should be closest->Targeted=1 specifying that the bomb is being targeted
        //Refrence
    }
}


The three filters from the top section of code should all be in one if statement. Here's an example of how to do that. You'll have to change it to your filters when you put it in the above code.
Code: Select all
if(a!=-1 && b>0 && c==0) // this is how to use the and operator, it is much cleaner than nesting if statements
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Some questions for my almost-complete game.

Postby DeltaLeeds » Tue Jan 21, 2014 3:52 pm

Ah.. Yes, I used && wrong. I thought it was used like a==1 && !=2, instead of a==1 && a !=2. xD Thanks! And about the code, It works, but not perfectly. The computers still get a bit confused when the bombs get lower than the safe zone. Well other then that, thanks, the script is a lot more clear now, and described well! :D
P.S: I might still ask more questions, but is it allowed that I ask questions in my game development thread instead of this one, or is it ok to ask here?
Currently: Semi-Active.
Working on: Maybe putting my test games in gamejolt, polishing them a bit, but I still don't know when.
User avatar
DeltaLeeds
 
Posts: 693
Joined: Fri May 06, 2011 12:45 pm
Location: In front of my computer.
Score: 38 Give a positive score

Re: A question for my new game.

Postby DeltaLeeds » Sun Feb 02, 2014 7:04 am

Hello! I'm really going to release another game soon. (I admit, Bombs Away was horrible, but hopefully I could change the GUI, but this one is going to be much better, hopefully). So, there is an annoying bug where I made the player actor MoveTo a black hole (Final boss.). At first it moves at its velocity(2), but suddenly it moves instantly to the boss, like its velocity is 1000. I don't think there are any other events connected with the MoveTo, except maybe: Player->Draw Actor->
Code: Select all
if(directional_velocity>0)
{
    directional_velocity--;
}
Currently: Semi-Active.
Working on: Maybe putting my test games in gamejolt, polishing them a bit, but I still don't know when.
User avatar
DeltaLeeds
 
Posts: 693
Joined: Fri May 06, 2011 12:45 pm
Location: In front of my computer.
Score: 38 Give a positive score

Re: Some questions for my almost-complete game.

Postby skydereign » Sun Feb 02, 2014 11:42 am

That is a bug with MoveTo. That function works when nothing else is trying to move the player, but it starts to have problems when other movement code gets in the way. My recommendation is to not use MoveTo.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Some questions for my almost-complete game.

Postby DeltaLeeds » Sun Feb 02, 2014 2:49 pm

Thanks for the reply Skydereign! So what other movement code is best to make the player move to the black hole?
Currently: Semi-Active.
Working on: Maybe putting my test games in gamejolt, polishing them a bit, but I still don't know when.
User avatar
DeltaLeeds
 
Posts: 693
Joined: Fri May 06, 2011 12:45 pm
Location: In front of my computer.
Score: 38 Give a positive score

Re: Some questions for my almost-complete game.

Postby skydereign » Mon Feb 03, 2014 5:10 am

jonathang wrote:So what other movement code is best to make the player move to the black hole?

Are you actually trying to simulate gravity? If so using directional_velocity and vector addition would probably be best. Here's an example of how to use vectoradd.
http://game-editor.com/examples/vectoradd.zip
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Some questions for my almost-complete game.

Postby DeltaLeeds » Mon Feb 03, 2014 1:36 pm

Ah, it's like tintran's asceroid, which is pretty much what inspired me to make this new game, but I guess this helps me understand that code much more! Thanks Skydereign! :D
EDIT: Sorry for the late reply, been busy the whole day.
Currently: Semi-Active.
Working on: Maybe putting my test games in gamejolt, polishing them a bit, but I still don't know when.
User avatar
DeltaLeeds
 
Posts: 693
Joined: Fri May 06, 2011 12:45 pm
Location: In front of my computer.
Score: 38 Give a positive score

Previous

Return to Game Development

Who is online

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

cron