Snake

Talk about making games.

Re: Snake

Postby Zivouhr » Sat Apr 18, 2015 2:04 pm

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.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Snake

Postby koala » Sat Apr 18, 2015 4:04 pm

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
Phascolarctos cinereus
YouTube: Marko Radivojevic
Google+: Marko Radivojevic
User avatar
koala
 
Posts: 301
Joined: Thu Mar 26, 2015 7:03 pm
Location: Serbia
Score: 30 Give a positive score

Re: Snake

Postby Zivouhr » Mon Apr 20, 2015 2:52 am

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)
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Snake

Postby Zivouhr » Fri Apr 24, 2015 2:58 am

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!
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Snake

Postby koala » Fri Apr 24, 2015 5:12 am

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);
Phascolarctos cinereus
YouTube: Marko Radivojevic
Google+: Marko Radivojevic
User avatar
koala
 
Posts: 301
Joined: Thu Mar 26, 2015 7:03 pm
Location: Serbia
Score: 30 Give a positive score

Re: Snake

Postby bat78 » Fri Apr 24, 2015 8:10 am

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.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Snake

Postby koala » Fri Apr 24, 2015 1:24 pm

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)
Attachments
randVal_source.zip
source (ged and data file)
(80.49 KiB) Downloaded 102 times
randVal_exe.zip
Windwos executable
(798.51 KiB) Downloaded 112 times
Last edited by koala on Sat Apr 25, 2015 12:52 am, edited 1 time in total.
Phascolarctos cinereus
YouTube: Marko Radivojevic
Google+: Marko Radivojevic
User avatar
koala
 
Posts: 301
Joined: Thu Mar 26, 2015 7:03 pm
Location: Serbia
Score: 30 Give a positive score

Re: Snake

Postby bat78 » Fri Apr 24, 2015 2:14 pm

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
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Snake

Postby koala » Fri Apr 24, 2015 3:29 pm

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
Phascolarctos cinereus
YouTube: Marko Radivojevic
Google+: Marko Radivojevic
User avatar
koala
 
Posts: 301
Joined: Thu Mar 26, 2015 7:03 pm
Location: Serbia
Score: 30 Give a positive score

Re: Snake

Postby Zivouhr » Fri Apr 24, 2015 6:03 pm

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.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Snake

Postby koala » Wed May 06, 2015 1:07 am

Hi, I am back to Snake and I will probably finish it soon. More info in update. :D
Phascolarctos cinereus
YouTube: Marko Radivojevic
Google+: Marko Radivojevic
User avatar
koala
 
Posts: 301
Joined: Thu Mar 26, 2015 7:03 pm
Location: Serbia
Score: 30 Give a positive score

Re: Snake

Postby Zivouhr » Wed May 06, 2015 1:45 am

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.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Snake

Postby koala » Sat May 23, 2015 2:10 am

A new update is available. :D :mrgreen:
Phascolarctos cinereus
YouTube: Marko Radivojevic
Google+: Marko Radivojevic
User avatar
koala
 
Posts: 301
Joined: Thu Mar 26, 2015 7:03 pm
Location: Serbia
Score: 30 Give a positive score

Re: Snake

Postby Hblade » Sat May 23, 2015 3:16 pm

Cool, koala =D!
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Snake

Postby Zivouhr » Sun May 24, 2015 2:41 pm

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
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

PreviousNext

Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron