Page 2 of 3

Re: Snake

PostPosted: Sat Apr 18, 2015 2:04 pm
by Zivouhr
That is great to hear you have prior knowledge of C.
I might consider making a demo Tron game if I have some extra time, but not sure yet.
Snake is a challenging game, but still fun to play. I can imagine later levels could have moving blocks to capture, or new walls to avoid.

Re: Snake

PostPosted: Sat Apr 18, 2015 4:04 pm
by koala
Zivouhr wrote:That is great to hear you have prior knowledge of C.
I might consider making a demo Tron game if I have some extra time, but not sure yet.
Snake is a challenging game, but still fun to play. I can imagine later levels could have moving blocks to capture, or new walls to avoid.
Great idea! I've already planned to add new walls, but I didn't think of moving blocks. :D

Re: Snake

PostPosted: Mon Apr 20, 2015 2:52 am
by Zivouhr
Yeah, if you want to add it, moving blocks would be cool and challenging. Maybe even a moving enemy that slowly goes after your character's tail. But that would be a different game though. Just ideas since you're already on your next project. 8)

Re: Snake

PostPosted: Fri Apr 24, 2015 2:58 am
by Zivouhr
koala wrote:I didn't play this Snake that much, just to see are things working fine (apparently they are not :roll: ). I've played original Snake a long time ago and I was good, but I don't remember the highscore.

It seems rand() is good enough for block position randomization :D .

Game I am currently working on is a card game and it'll take some time to finish it. :)


Hi Koala,

On my new test game in development, I have a prize that I plan to have appear in a different spot in the maze each time it's hit by the player, and while I have a functioning solution ready to use, I would like to learn a new way of doing it, with your game Snake as inspiration.

I was wondering how you are able to get the block to appear at different, random spots on the map each time it's caught?
I checked the code of the player and the block, but didn't find where you might have the code for random placement, rand(); to make the target block appear in random spots each time.

If you have a brief tip you can share about how to get the block to appear in a random spot each time it's contacted, that would be a help, but only if you have time for a short answer. I know you're busy on your new projects, so no hurry. Thanks!

Re: Snake

PostPosted: Fri Apr 24, 2015 5:12 am
by koala
Zivouhr wrote:
koala wrote:I didn't play this Snake that much, just to see are things working fine (apparently they are not :roll: ). I've played original Snake a long time ago and I was good, but I don't remember the highscore.

It seems rand() is good enough for block position randomization :D .

Game I am currently working on is a card game and it'll take some time to finish it. :)


Hi Koala,

On my new test game in development, I have a prize that I plan to have appear in a different spot in the maze each time it's hit by the player, and while I have a functioning solution ready to use, I would like to learn a new way of doing it, with your game Snake as inspiration.

I was wondering how you are able to get the block to appear at different, random spots on the map each time it's caught?
I checked the code of the player and the block, but didn't find where you might have the code for random placement, rand(); to make the target block appear in random spots each time.

If you have a brief tip you can share about how to get the block to appear in a random spot each time it's contacted, that would be a help, but only if you have time for a short answer. I know you're busy on your new projects, so no hurry. Thanks!
Hi, Zivouhr! :D
When you collect actor point, it is destroyed. That event sends activation event to wall, which creates timer spawn_point. At the end of that timer this happens:

wall -> Events: Timer -> Script Editor (spawn_point):
Code: Select all
int i;
int create = 1;
int point_x, point_y; // coordinates of a new point
 
if (game_over != 1) {
    while (1) {
        // setting new coordinates
        point_x = (int)(10 - rand(21)) * 20;
        point_y = ((int)(10 - rand(21)) + 3) * 20 - 10;
 
        // coordinates must be different than coordinates of snake's parts
        for (i = 0; i < length; i++)
           if ((array[i].partX == point_x) && (array[i].partY == point_y)) {
               create = 0;
               break;
           }
 
        if (create == 1) break;
    }

    CreateActor("point", "point", "no parent", "no path", point_x, point_y, true);
}
:D

Thank you for asking this, now I know why game freezes!

If point spawns at the same place as snake, create = 0 and it doesn't change to 1. So there's a bug! Program stays in while (1) loop.
It should be like this:
Code: Select all
int i;
int create;
int point_x, point_y; // coordinates of a new point
 
if (game_over != 1) {
    while (1) {
        //crucial change
        create = 1;

        // setting new coordinates
        point_x = (int)(10 - rand(21)) * 20;
        point_y = ((int)(10 - rand(21)) + 3) * 20 - 10;
 
        // coordinates must be different than coordinates of snake's parts
        for (i = 0; i < length; i++)
           if ((array[i].partX == point_x) && (array[i].partY == point_y)) {
               create = 0;
               break;
           }
 
        if (create == 1) break;
    }

    CreateActor("point", "point", "no parent", "no path", point_x, point_y, true);
}


To add some randomness, you could do this:
Code: Select all
int choice;
stTime  t = getTime();

//instead of ---> choice = rand(52);

choice = fmod((t.sec_utc + (int) rand(52)), 52);

Re: Snake

PostPosted: Fri Apr 24, 2015 8:10 am
by bat78
I will always be in the curious state why are you explicitly type-casting to int, Because we know rand() returns int implicitly and type-casting is simply.. unneeded.

Re: Snake

PostPosted: Fri Apr 24, 2015 1:24 pm
by koala
bat78 wrote:I will always be in the curious state why are you explicitly type-casting to int, Because we know rand() returns int implicitly and type-casting is simply.. unneeded.
I've thought rand() returns double.
Script Reference
rand: Generates a sequence of pseudorandom numbers. Each time it is called, an number between zero and max will be returned.
double rand (double max);

Windows executable
source (ged and data file)

Re: Snake

PostPosted: Fri Apr 24, 2015 2:14 pm
by bat78
koala wrote:
bat78 wrote:I will always be in the curious state why are you explicitly type-casting to int, Because we know rand() returns int implicitly and type-casting is simply.. unneeded.
I've thought rand() returns double.
Sscript Reference
rand: Generates a sequence of pseudorandom numbers. Each time it is called, an number between zero and max will be returned.
double rand (double max);

Windows executable
source (ged and data file)

Hm, this is weird. Originally rand() returns int. I knew that rand is a different, but I didn't know it is THAT different.
You shouldn't throw so much efforts in exemplifying it XD

Re: Snake

PostPosted: Fri Apr 24, 2015 3:29 pm
by koala
bat78 wrote:
koala wrote:
bat78 wrote:I will always be in the curious state why are you explicitly type-casting to int, Because we know rand() returns int implicitly and type-casting is simply.. unneeded.
I've thought rand() returns double.
Sscript Reference
rand: Generates a sequence of pseudorandom numbers. Each time it is called, an number between zero and max will be returned.
double rand (double max);

Windows executable
source (ged and data file)

Hm, this is weird. Originally rand() returns int. I knew that rand is a different, but I didn't know it is THAT different.
You shouldn't throw so much efforts in exemplifying it XD
I use every opportunity to make a new GE executable. XD

Re: Snake

PostPosted: Fri Apr 24, 2015 6:03 pm
by Zivouhr
Cool, thanks a lot Koala! I'll take a look at that code and test it out.
Glad it was able to help you find the crash bug too. 8)

I have much to learn about C, even after creating a large adventure game like Tomb of Twelve with Game-Editor. The user interface of Game Editor is what keeps me interested in this game creation program, along with a focus on classic 2D games which Game Editor is geared for.

Re: Snake

PostPosted: Wed May 06, 2015 1:07 am
by koala
Hi, I am back to Snake and I will probably finish it soon. More info in update. :D

Re: Snake

PostPosted: Wed May 06, 2015 1:45 am
by Zivouhr
koala wrote:Hi, I am back to Snake and I will probably finish it soon. More info in update. :D


Nice! Looking forward to see more.

Re: Snake

PostPosted: Sat May 23, 2015 2:10 am
by koala
A new update is available. :D :mrgreen:

Re: Snake

PostPosted: Sat May 23, 2015 3:16 pm
by Hblade
Cool, koala =D!

Re: Snake

PostPosted: Sun May 24, 2015 2:41 pm
by Zivouhr
koala wrote:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Saturday, May 23, 2015
4:10 AM (UTC+1)
PanĨevo, Serbia


Hi, guys, I am back!

I've been absent for a few days and I didn't do anything related to Game Editor, but tonight I've decided to work a little bit more on Snake and now you can play it.
There are some new things. You can choose one map, or levels. The snake speeds up. There are sounds, as well as music, made by Eric Matyas (http://www.soundimage.org).
I should make points spawn faster and maps that have holes in it so snake can enter one hole and appear from another.
Leave your feedback, suggestions and have a nice day.

Sanke GED (source and data files)
Snake Game (Windows Executable)




Cool! The game is a lot more challenging now and that crash glitch is gone too. I like the music and new sound effects to add to the immersion into the game. I have just reached level 2 after a challenging level 1 with 1325 points so far. Great job Koala updating this game. The segments act as a wall after enough segments have been added, and much more challenging as a result. 8)
snakelevel2.jpg