Page 1 of 2

Some questions for my almost-complete game.

PostPosted: Sat Jan 11, 2014 10:25 am
by DeltaLeeds
Hello gE! It has been months since I last posted a post, and even longer since I posted a new topic. Alright, so now I'm making my first released game which is almost complete. (It was actually first made to make me remember codes in gE)

So the questions I really want to ask is:
1. How do I make an actor move to the nearest actor clone. Usually they just move to the oldest actor clone made (Not sure though.), but this time, I want the actor to move to the NEAREST specific actor clone around(Bombs). This part of the game is collecting bombs with 3 "Computer" players in the screen. This avoids them from aiming at the exact same bomb and having a smarter A.I too.
2. Ok, so if we go too low to the screen, the bombs will explode. When the bombs explode, they could stun the player or computers. So I want a smarter computer that won't get bombs too low. I tried making filled regions or objects that will halt them, but they'll go through eventually and become stunned all the time. How do I avoid them from going to low?
3. I want all clones of an actor (Pre-made clones) to be transparent in 1 mode of the game, but only the Actor.0 is transparent. How do I change that? (Fixed by DarkParadox.)

I guess that's all the questions for now. I'll appreciate any answer. If you need the demo, I'll send it, but I don't think that's really necessary yet. (More questions to come!)

Re: Some questions for my almost-complete game.

PostPosted: Sun Jan 12, 2014 10:09 am
by DeltaLeeds
Er... Anyone else want to answer them? Maybe Skydereign, or anyone else?... Well, I have another question coming...
4. How to make an "In-Vision" event? I mean we have an out of vision event, I did see viewtopic.php?f=2&t=11989&p=84828 but it doesn't work. The actor won't do the out of vision events. Or I might have done something wrong.... So, anyone?

EDIT: Added else as DarkParadox helped one of my issues. xD

Re: Some questions for my almost-complete game.

PostPosted: Sun Jan 12, 2014 11:24 am
by skydereign
jonathang wrote:1. How do I make an actor move to the nearest actor clone. Usually they just move to the oldest actor clone made (Not sure though.), but this time, I want the actor to move to the NEAREST specific actor clone around(Bombs). This part of the game is collecting bombs with 3 "Computer" players in the screen. This avoids them from aiming at the exact same bomb and having a smarter A.I too.

This is currently a bit tricky. To do this you'll need to be able to loop through all clones and there is no built in way to do that. Also you'll need to use Actor*s and the getclone2 function. What you have to do is keep track of the highest cloneindex of the bomb actor. Luckily any clone being created is guaranteed to be the highest indexed clone of that type.
bomb -> Create Actor -> Script Editor
Code: Select all
highest_bomb = cloneindex;

Now in the draw event of your actor that should move to the nearest bomb you can do this.
actor -> Draw Actor -> Script Editor
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++) // loop through from the lowest index to the highest
{
    Actor* temp_bomb = getclone2("bomb", i); // get a reference to the bomb
    if(temp_bomb->cloneindex!=-1) // if this bomb exists
    {
        int temp_dist = distance(x, y, temp_bomb->x, temp_bomb->y);
        if(temp_dist < dist) // this new bomb is closer
        {
            dist = temp_dist; // set new shorter distance
            target = i; // adjust to new target
        }
    }
}
// at this point target holds the cloneindex which bomb is the closest to the event actor
closest = getclone2("bomb", target);
if(closest->cloneindex!=-1)
{
    // you now have a reference to the bomb, and can move to it with MoveTo or some other method
}


jonathang wrote:2. Ok, so if we go too low to the screen, the bombs will explode. When the bombs explode, they could stun the player or computers. So I want a smarter computer that won't get bombs too low. I tried making filled regions or objects that will halt them, but they'll go through eventually and become stunned all the time. How do I avoid them from going to low?

You're going to need to explain more. What is causing the bombs to go down? Bare in mind I know nothing about your game except what you've posted here.
jonathang wrote:4. How to make an "In-Vision" event? I mean we have an out of vision event, I did see viewtopic.php?f=2&t=11989&p=84828 but it doesn't work. The actor won't do the out of vision events. Or I might have done something wrong.... So, anyone?

You need to use the draw actor event. Simplest way conceptually is just to use an if to make sure the actor is in bounds.
Code: Select all
if(xscreen>=0 && xscreen<view.width && yscreen>=0 && yscreen<view.height)
{
    // the code here only runs when the actor is in view
}

If you do go with the above route, I suggest making a function out of it.

Re: Some questions for my almost-complete game.

PostPosted: Sun Jan 12, 2014 2:26 pm
by DeltaLeeds
Thank you for your assistance Skydereign. :D

About number 1: Alright I'll try doing that in the game, I'll post about the progress later. (Or tomorrow.)

About number 2: Sorry that I wasn't that specific in number 2, plus a mistake I made in the post. The bombs go down by yvelocity (Changes every time the player is nearer to the goal), and about the mistake:
I wrote:2. Ok, so if we go too low to the screen, the bombs will explode. When the bombs explode, they could stun the player or computers. So I want a smarter computer that won't get bombs too low. I tried making filled regions or objects that will halt them, but they'll go through eventually and become stunned all the time. How do I avoid them from going to low?
The bold part was supposed to be "Ok, so if the bombs reach the bottom of the screen"

About number 4: Cool, it works like a charm! Thanks! :D

Re: Some questions for my almost-complete game.

PostPosted: Sun Jan 12, 2014 10:30 pm
by skydereign
jonathang wrote:About number 2: Sorry that I wasn't that specific in number 2, plus a mistake I made in the post. The bombs go down by yvelocity (Changes every time the player is nearer to the goal), and about the mistake:
I wrote:2. Ok, so if we go too low to the screen, the bombs will explode. When the bombs explode, they could stun the player or computers. So I want a smarter computer that won't get bombs too low. I tried making filled regions or objects that will halt them, but they'll go through eventually and become stunned all the time. How do I avoid them from going to low?
The bold part was supposed to be "Ok, so if the bombs reach the bottom of the screen"

How does the computer stop the bombs from reaching the bottom? You said that the bomb's yvelocity changes every time the player is closer to the goal, but does the computer do this as well? What exactly do you want the computer to do that would trigger the bombs from not reaching the bottom?

Re: Some questions for my almost-complete game.

PostPosted: Mon Jan 13, 2014 10:52 am
by DeltaLeeds
Ergh why am I so unspecific. :oops:
This mode at number 2 is called Bomb Collector, so the player and computers should collect bombs (They must touch the bomb, and by collision, the bomb will be destroyed, and the toucher gets a point. So, like I said, the bombs explode on contact with the bottom of the screen, the explode stuns the player/ computer touching the explosion. I don't want the computer getting too low. (Maybe just let them stay on the upper half of the screen (640*480)).
Man, I hope I'm specific enough now...

About number 1: I've added the code, and I understand it all (I know understand what distance and Actor is for! :D) but it requires a pointer where there is b-> and target-> (Line 8 and 20). I don't really know what a pointer is... :oops:

Re: Some questions for my almost-complete game.

PostPosted: Mon Jan 13, 2014 4:03 pm
by skydereign
jonathang wrote:About number 1: I've added the code, and I understand it all (I know understand what distance and Actor is for! :D) but it requires a pointer where there is b-> and target-> (Line 8 and 20). I don't really know what a pointer is... :oops:

Ah, those were actually typos. I've updated the example. The b-> should have been temp_bomb->, and the target-> should have been closest->. And to explain a pointer is a variable that points to a place in memory. Essentially the value of a pointer is the location of a variable in memory. The points to operator (->) will dereference the pointer and access whatever value it points at (in this case the actor retrieved by getclone2).

jonathang wrote:This mode at number 2 is called Bomb Collector, so the player and computers should collect bombs (They must touch the bomb, and by collision, the bomb will be destroyed, and the toucher gets a point. So, like I said, the bombs explode on contact with the bottom of the screen, the explode stuns the player/ computer touching the explosion. I don't want the computer getting too low. (Maybe just let them stay on the upper half of the screen (640*480)).

Your idea of keeping the computer above a certain point would definitely work. Just keep them out of the blast radius at the bottom. Another option would be have it make sure that it only goes after bombs that it will be able to reach before it blows up. Depending on how you did it though the computer could still be hit by bombs, so you might want to stick with having the computer never leave the safe area of the screen. Your use of a filled region should work, as long as you set the collision to repeat. Otherwise you can alter the checking where the closest bomb is code to only check bombs that are in the safe area. This is pretty easy, just check the yscreen value of temp_bomb when you are checking cloneindex.

Re: Some questions for my almost-complete game.

PostPosted: Tue Jan 14, 2014 5:00 am
by DeltaLeeds
Hooray!! Number 1 is done!!! Thanks a million Skydereign! :lol:
But, as for number 2. Filled regions aren't that effective, because somehow, actors go stuck inside it, but I've solved that by making a y and x limit like
Code: Select all
if(y>50)
{
    y=50;
}

My game is almost done, but there are still a lot of bugs. If I could at least fix one of them, I'll release it! :D
5. So, after we finish every game, the bomb actors have to be destroyed. I did make the DestroyActor("Bomb"); after the Score to Goal reaches 0 or less, but for some reason (Most likely because the bombs aren't destroyed.), the scores keep rolling when we are in the results screen. (We go there using draw actor.) I tried using events received out of vision and not received, but it just comes out the same. To receive a score, the actor touches a bomb, defusing it, and when the bomb is drawn to a cannon, the score adds up, but for the computers, they have a specialized timer to add their score every time a bomb is created. When the score to goal reaches 0 or less, the specialized timer event is disabled, but for some reason, the score keeps rolling in the result screen... I wonder if sending the .ged is necessary in this problem?

Re: Some questions for my almost-complete game.

PostPosted: Tue Jan 14, 2014 8:03 am
by skydereign
jonathang wrote:5. So, after we finish every game, the bomb actors have to be destroyed. I did make the DestroyActor("Bomb"); after the Score to Goal reaches 0 or less, but for some reason (Most likely because the bombs aren't destroyed.), the scores keep rolling when we are in the results screen. (We go there using draw actor.) I tried using events received out of vision and not received, but it just comes out the same. To receive a score, the actor touches a bomb, defusing it, and when the bomb is drawn to a cannon, the score adds up, but for the computers, they have a specialized timer to add their score every time a bomb is created. When the score to goal reaches 0 or less, the specialized timer event is disabled, but for some reason, the score keeps rolling in the result screen... I wonder if sending the .ged is necessary in this problem?

To simplify this, what event causes the score to change ("keep rolling")? Can you post the code for it?

Re: Some questions for my almost-complete game.

PostPosted: Tue Jan 14, 2014 12:13 pm
by DeltaLeeds
That's what I really want to know.. :(
It's weird because the bombs should be off-screen and destroyed when the view is drawn to the result screen.
So, the code of what the score is supposed to be is:
Example for player 1's score in the result screen
Code: Select all
//Instead of a high score, the player's score is better when lower when in the result screen.
//Mode==1 is Easy, Mode==2 is normal and Mode==3 is hard.
//TerrifyingM==1 is a mode called Bomb Rush and TerrifyingM==2 is the Bomb collector mode, mentioned above.
ScoreTotal=P2+P3+P4-P1;
textNumber=ScoreTotal;
FinalScore=textNumber;
if(Mode==1)
{
if(ScoreTotal<EasyLowScore)
{
    PlaySound2("data/shiny.wav", 1.000000, 1, 0.000000);
    EasyLowScore=ScoreTotal;
    saveVars("data.sav", "HighScores");
}
}
else if(Mode==2)
{
    if(ScoreTotal<NormalLowScore)
    {
        PlaySound2("data/shiny.wav", 1.000000, 1, 0.000000);
        NormalLowScore=ScoreTotal;
        saveVars("data.sav", "HighScores");
    }
}
else if(Mode==3)
{
    if(ScoreTotal<HardLowScore)
    {
        PlaySound2("data/shiny.wav", 1.000000, 1, 0.000000);
        HardLowScore=ScoreTotal;
        saveVars("data.sav", "HighScores");
    }
}
if(TerrifyingM==1)
{
    if(ScoreTotal<MiniGame2LowScore)//MiniGame2LowScore is the Bomb rush low score
    {
        PlaySound2("data/shiny.wav", 1.000000, 1, 0.000000);
        MiniGame2LowScore=ScoreTotal;
        saveVars("data.sav", "HighScores");
    }
}
else if(TerrifyingM==2)
{
    if(ScoreTotal<MiniGame1LowScore)//MiniGame1LowScore is Bomb Collector's low score
    {
        PlaySound2("data/shiny.wav", 1.000000, 1, 0.000000);
        MiniGame1LowScore=ScoreTotal;
        saveVars("data.sav", "HighScores");
    }
}

The normal player 1 in-game score is reduce (Total score in the result game will be increased, as I said that the lower the score in the result screen, the better) when a bomb reaches out of screen when lit, (The player must first touch the bomb when unlit to light the bomb), and the score increases the bomb reaches the cannon when it is lit.
How the score keeps rolling is, the first place player's score keeps going down in the result screen, the other computer's scores might increase or decrease, but the player's score keeps decreasing... So, any tips?
EDIT: Making another actor's event out of vision solved the problem! Lol, the time I wasted for nothing!!! xD

Re: Some questions for my almost-complete game.

PostPosted: Sat Jan 18, 2014 6:02 am
by DeltaLeeds
Final question before I release the game!

It's about the move to nearest actor script. It does work great, but when there are too many bombs in the screen, the computers will get really confused and do nothing (Maybe it could be because the computer follows a bomb below y=50 and not follow nearer bombs?) If the computer is lower than y=50 (Lower as in higher y), they'll go back to y=50 automatically. How do we make that the computers will always go to the nearest bomb no matter how many there is?

Re: Some questions for my almost-complete game.

PostPosted: Sat Jan 18, 2014 9:38 am
by skydereign
jonathang wrote:(Maybe it could be because the computer follows a bomb below y=50 and not follow nearer bombs?)

I mentioned a fix for this in an earlier post.
skydereign wrote:Otherwise you can alter the checking where the closest bomb is code to only check bombs that are in the safe area. This is pretty easy, just check the yscreen value of temp_bomb when you are checking cloneindex.

This prevents the enemy from ever targeting a bomb in the unsafe zone. The idea is that now there are two conditions for the enemy to pick a bomb as a potential closest. First it needs to actually exist (cloneindex!=-1) and secondly it needs to be in the safe zone (yscreen < view.height - 50).
jonathang wrote:How do we make that the computers will always go to the nearest bomb no matter how many there is?

To do that you'll have to have to add something to the reset position to code to not jump the enemy back if they are chasing a bomb. This though eliminates the reason for the jump code anyways, so the aforementioned method is probably the way to go.

Re: Some questions for my almost-complete game.

PostPosted: Sat Jan 18, 2014 10:41 am
by DeltaLeeds
So we do this at the bomb reference part right?
Code: Select all
if(closest->cloneindex!=-1)
{
    if(closest->yscreen < view.height - 50)
    {
    //BombRefrence
    }
}

Or are there any other parts, because the computers are still confused on where to go. And (*Ahem, the previous question wasn't my final question after all. Heheh...*) is it possible for each computer to have different targets?

Re: Some questions for my almost-complete game.

PostPosted: Mon Jan 20, 2014 1:55 am
by skydereign
jonathang wrote:So we do this at the bomb reference part right?
Code: Select all
if(closest->cloneindex!=-1)
{
    if(closest->yscreen < view.height - 50)
    {
    //BombRefrence
    }
}

No, that won't work. That last bit of code is just to make sure the target exists. If you try to read what the code does using the names, you can tell that that doesn't actually filter which bomb's can be targeted. All that would do is stop it from moving toward the closest bomb if it isn't in the safe zone.

What I was talking about is a way of filtering out any bomb that is not in the safe zone. So it would not consider unsafe bombs when trying to find the closest one. The Actor* closest holds the closest bomb, while the Actor* temp_bomb is being used to find the closest one. Therefore the line you should change is the if(temp_bomb->cloneindex!=-1) one.

jonathang wrote:is it possible for each computer to have different targets?

Yes. The easiest way to do this is to create an actor variable that holds if the bomb is targeted or not. I'm going to assume any bomb that is targeted can never be untargeted. This might actually not be true depending on how you set up the movement code though. Anyways, when you have found the closest bomb, you'll need to set that bomb's targeted variable to 1. That way in the finding code (same place you had to add the yscreen check) you add one last condition if(temp_bomb->targeted==0). That will make sure that it ignores bombs that are already targeted by other actors.

Re: Some questions for my almost-complete game.

PostPosted: Mon Jan 20, 2014 7:31 am
by DeltaLeeds
Code: Select all

for(i=Ballz.cloneindex; i<highest_bomb; i++) // loop through from the lowest index to the highest
{
    Actor* temp_bomb = getclone2("Ballz", i); // get a reference to the bomb
    if(temp_bomb->cloneindex!=-1) // if this bomb exists
    {
        if(temp_bomb->yscreen < view.height - 50)
        {
        int temp_dist = distance(x, y, temp_bomb->x, temp_bomb->y);
        if(target!=i)
            {
        if(temp_dist < dist) // this new bomb is closer
        {
            dist = temp_dist; // set new shorter distance
            target = i; // adjust to new target
        }
            }
        }
    }
}

Hm, this doesn't work, doing if(temp_bomb->cloneindex!=-1 && yscreen< view.height) also doesn't work. Sorry for the inconvenience but which one do we need to change? About the different targeting, they somehow did think a split second before targeting, but they still go for same targets. I bet I did something wrong... Can you point out what I did wrong Skydereign? Thanks.