Page 1 of 3

Snake

PostPosted: Tue Mar 31, 2015 11:41 pm
by koala
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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)



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tuesday, May 06, 2015
3:20 AM (UTC+1)
Pančevo, Serbia


Hi!!!

I am taking break from Tablic so I have returned to Snake.
I've found the way to make the snake move faster, fixed the freeze bug that I've solved thanks to Zivouhr, and one more bug that made the game suddenly end and return to main screen. Those were the main problems I have had with this game, so all I need to do now is add your suggestions, like new levels, new walls and sound. Maybe some moving blocks. Also, I will add option not to play levels, but you play until you die, how would you call it, I can't remember XD, pause and pause and exit shortcuts. On later levels snake could be bigger, instead of one block it could consist of more blocks. I should finish it this week and post it here to see what you guys think and discuss it some more.
By the way, working on Tablic I've learned some new things that helped me with this game.

So, soon this game should be completed and ready for the world. :)

One more thing, I've made a short video about current Snake and its progress: Snake (Game Editor).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Wednesday, April 01, 2015
1:41 AM (UTC+1)
Pančevo, Serbia


Hi, everybody! :D

I'm working on a well known game called Snake. It is more of an experiment, than a serious project. Game is not finished yet. I need to make the snake move faster. Game is working well when launched inside GE, but it has some bug as an executable file. I think the problem is with array of coordinates, but never mind. :D I'll move to another project, but soon I'll get back to this one, so I would like to hear your opinion. :D

Ged and data files:
http://www.mediafire.com/download/xovpljz2xv323cg/Snake_GED.zip

Image Image Image

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Re: Snake

PostPosted: Wed Apr 01, 2015 1:00 am
by koala
The snake consist of one square called head and the rest called tail. Snake has a timer (200 ms) and it moves 20 pixels every time. You move the snake using arrow keys and collect points. It is simple Snake game.

Global Variables:

Code: Select all
length // snake's length
score
highscore // saves in snake.sav, Save Group: High Score
game_over // 1 when it is game over, otherwise it is 0
index // new index for every part of tail; for every part of snake except for head
up, down, left, right // in which direction is snake moving

Global code:

coordinates - saves the coordinates of snake's parts
Code: Select all
typedef struct coord {
   int partX;
   int partY;
} coordinates;

#define MAX 462

coordinates array[MAX];
MAX should be 441, not 462.

destroy - script includes function destroy() which activates when snake collides with the wall, or tail
Code: Select all
void destroy() {
   game_over = 1;

   DestroyActor("head");
   DestroyActor("tail");
   DestroyActor("point");

   if (score > highscore)
       highscore = score;
   saveVars("snake.sav", "High Score");

   CreateActor("game_over_message", "game_over", "no parent", "game_over_path", -465, 20, true);

   CreateActor("space", "no animation", "no parent", "no path", -150, 190, true);
   strcpy(space.text, "PRESS [SPACE] TO CONTINUE");

   CreateActor("reset", "no animation", "no parent", "no path", -110, -150, true);
}
Destroy head, tail and a new point.
Set highscore.
Write messages.

set_coordinates - script include function set_coordinates() which sets coordinates x and y of every part of snake, except head
Code: Select all
void set_coordinates () {
   int i;

   for (i = length - 1; i > 0; i--) {
       array[i].partX = array[i - 1].partX;
       array[i].partY = array[i - 1].partY;
   }
}

head:

When head collides with the wall or tail, function destroy() activates.

Pressed key down (Event Key Down: down)
Code: Select all
if (up != 1) {
   down = 1;
   left = 0;
   right = 0;
}

EventDisable("head", EVENTKEYDOWN);
Set direction to down, except if snake is already moving up. Next, Event Key Down is disabled and pressing any other arrow key will not change the snake's direction until this Event is activated again. This is important in case that player very quickly presses, in this case, arrow left, or right, but timer didn't activate and register that move, more about timer after this, and then arrow down, and snake was moving up. In other words, you pressed left, now up = 0 and left = 1, but timer didn't update new direction, and immediately after that you pressed down. up is not 1 any more and down is set to 1, by now timer should activate and update next direction to down. Then snake would move down, and head will go over the tail, which will activate Event Collide (snake and tail).

head's timer (200 ms):
Code: Select all
EventEnable("head", EVENTKEYDOWN);

if (up == 1)
   array[0].partY += -20;
else if (down == 1)
   array[0].partY += 20;
else if (left == 1)
   array[0].partX += -20;
else if (right == 1)
   array[0].partX += 20;
else {
   array[0].partX = head.x;
   array[0].partY = head.y;
}

x = array[0].partX;
y = array[0].partY;

if (x == point.x && y == point.y) {
   score += 25;

   DestroyActor("point");

   length++;

   CreateActor("tail", "tail", "no parent", "no path", 300, 300, true);

   tail.index = length - 1;
}

set_coordinates();
Event Key Down is activated again, and snake, or precisely head, receives instructions from arrow keys.
New coordinates for head are set.
If head's and point's coordinates are same, if snake caught the point:
- increase the score
- destroy the point
- increase the length of snake
- create a new part of tail; it creates outside the view for these 200 ms, because coordinates are still unknown
- new part gets its index
Set coordinates for the rest of snake.

tail:

Timer (200 ms) sets new coordinates for that part of tail:
Code: Select all
x = array[index].partX;
y = array[index].partY;


view:

When you start the game:
Code: Select all
CreateActor("space", "no animation", "no parent", "no path", -140, 190, true);
strcpy(space.text, "  PRESS [SPACE] TO BEGIN ");

CreateActor("reset", "no animation", "no parent", "no path", -110, -150, true);

game_over = 1;

When you press [SPACE]:
Code: Select all
if (game_over == 1) {

int i;
int create = 1;
int point_x, point_y;

while (1) {
   point_x = (int)(10 - rand(21)) * 20;
   point_y = ((int)(10 - rand(21)) + 3) * 20 - 10;

   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);


CreateActor("head", "head", "no parent", "no path", 0, 250, true);

DestroyActor("space");

DestroyActor("reset");

DestroyActor("game_over_message");

length = 1;
game_over = 0;
score = 0;

up = 0;
down = 0;
left = 0;
right = 0;

array[0].partX = 0;
array[0].partY = 250;

loadVars("snake.sav", "High Score");

}
The code executes if the game is not active.
Set a new point to catch, coordinates must not be the same as any part of snake.
Create the head.
Delete unnecessary messages.
Initialize variables.
Set head's coordinates.
Open the snake.sav which saves the highscore.

Deleting highscore:
Code: Select all
if (game_over == 1) {

loadVars("snake.sav", "High Score");

highscore = 0;

saveVars("snake.sav", "High Score");

}

wall:

wall creates new points you need to catch:
Code: Select all
int i;
int create = 1;
int point_x, point_y;

if (game_over != 1) {
   while (1) {
       point_x = (int)(10 - rand(21)) * 20;
       point_y = ((int)(10 - rand(21)) + 3) * 20 - 10;

       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);
}

score, highscore:

These two variables are written the same way. Digits on screen are not text, but independent actors. Value of the third digit of the score:
Code: Select all
switch ((int) fmod ((int) (score / 100), 10)) {
   case 0: ChangeAnimation("digit_c", "0", FORWARD); break;
   case 1: ChangeAnimation("digit_c", "1", FORWARD); break;
   case 2: ChangeAnimation("digit_c", "2", FORWARD); break;
   case 3: ChangeAnimation("digit_c", "3", FORWARD); break;
   case 4: ChangeAnimation("digit_c", "4", FORWARD); break;
   case 5: ChangeAnimation("digit_c", "5", FORWARD); break;
   case 6: ChangeAnimation("digit_c", "6", FORWARD); break;
   case 7: ChangeAnimation("digit_c", "7", FORWARD); break;
   case 8: ChangeAnimation("digit_c", "8", FORWARD); break;
   case 9: ChangeAnimation("digit_c", "9", FORWARD); break;
}
Instead of making a new font, I did it this way. I think it is better to make a new font, it is more convenient, it takes less space, but I wanted to try it this way and to do it faster.

Re: Snake

PostPosted: Thu Apr 02, 2015 5:36 am
by Zivouhr
Looks interesting.
If I get a chance soon I'll give it a try.

Re: Snake

PostPosted: Thu Apr 02, 2015 10:48 am
by koala
Zivouhr wrote:Looks interesting.
If I get a chance soon I'll give it a try.
Thanks! :D

I've made it retro on purpose.
And I need to learn more about GE script, so I can use its full potential. I'm sure these scripts can be much better. :D

Re: Snake

PostPosted: Fri Apr 03, 2015 12:35 pm
by bat78
Why isn't skydereign in here.. Now it is a matter of hope that he comes back.

Re: Snake

PostPosted: Fri Apr 03, 2015 6:01 pm
by koala
bat78 wrote:Why isn't skydereign in here.. Now it is a matter of hope that he comes back.
I am not sure what do you want to say? He can help with this game?

Re: Snake

PostPosted: Fri Apr 03, 2015 7:12 pm
by bat78
koala wrote:
bat78 wrote:Why isn't skydereign in here.. Now it is a matter of hope that he comes back.
I am not sure what do you want to say? He can help with this game?

He is /or was/ the only one working on gE (the actual engine) as well as he is the GM.
Therefore, he is a good programmer, old, respectful and helpful user and he would like to see potentially similar user joining.

Re: Snake

PostPosted: Thu Apr 09, 2015 10:42 pm
by Zivouhr
koala wrote:
Zivouhr wrote:Looks interesting.
If I get a chance soon I'll give it a try.
Thanks! :D

I've made it retro on purpose.
And I need to learn more about GE script, so I can use its full potential. I'm sure these scripts can be much better. :D


Hi Koala. Cool version of Snake, nicely done!
It controls responsively with the arrow keys. The spacebar to start the game is nice. The retro graphics are fun to revisit the past. I was able to reach 600 points, but then the game froze and I had to exit out. Not sure what happened.

I was thinking a sound heard whenever you successfully hit a block would be cool, and a neat feature would be to hear a sound when you smash into a wall and the game ends. It's nice to see there is not timer that speeds the snake up too fast, but the whole challenge is avoiding the tail as it turns to get the next piece.

Thanks for sharing this demo. I was thinking of the Tron Lightcycles from the arcade game TRON while playing this version.

Re: Snake

PostPosted: Fri Apr 10, 2015 10:56 am
by koala
Zivouhr wrote:
koala wrote:
Zivouhr wrote:Looks interesting.
If I get a chance soon I'll give it a try.
Thanks! :D

I've made it retro on purpose.
And I need to learn more about GE script, so I can use its full potential. I'm sure these scripts can be much better. :D


Hi Koala. Cool version of Snake, nicely done!
It controls responsively with the arrow keys. The spacebar to start the game is nice. The retro graphics are fun to revisit the past. I was able to reach 600 points, but then the game froze and I had to exit out. Not sure what happened.

I was thinking a sound heard whenever you successfully hit a block would be cool, and a neat feature would be to hear a sound when you smash into a wall and the game ends. It's nice to see there is not timer that speeds the snake up too fast, but the whole challenge is avoiding the tail as it turns to get the next piece.

Thanks for sharing this demo. I was thinking of the Tron Lightcycles from the arcade game TRON while playing this version.
Hi, Zivouhr! :D
Thank you for playing game and for review.

I'll check what is the problem, why the game froze. Sounds and increasing speed step by step are first things I am going to make. I will also add some levels, so snake goes through different field every time.

Currently I am working on another game and it takes a lot of time to make it right, but I want it to be as good as possible. Then I'll post it here for reviews and when I finish that game, I'll continue making Snake and Byzantine Empire.

:D

Re: Snake

PostPosted: Fri Apr 10, 2015 3:28 pm
by Zivouhr
Sounds good!

What is your high score on this game?
I like how each time it's played, a new pattern appears to find the next block.

Work on the game that interests you the most, agreed. Cool to hear you're working on new games. I just need some more spare time to work on a new one.

Re: Snake

PostPosted: Fri Apr 10, 2015 4:48 pm
by koala
Zivouhr wrote:Sounds good!

What is your high score on this game?
I like how each time it's played, a new pattern appears to find the next block.

Work on the game that interests you the most, agreed. Cool to hear you're working on new games. I just need some more spare time to work on a new one.
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. :)

Re: Snake

PostPosted: Wed Apr 15, 2015 11:59 pm
by Zivouhr
The random command did a nice job keeping the blocks varied, yes.
Best of success with the card game you're working on now. 8)

Re: Snake

PostPosted: Thu Apr 16, 2015 11:34 am
by koala
Zivouhr wrote:Best of success with the card game you're working on now. 8)
Thank you. There's a lot more work than I thought and it goes really slowly, but it's still advancing. However, it won't be finished for at least a week, probably more.

Re: Snake

PostPosted: Sat Apr 18, 2015 1:41 pm
by Zivouhr
Koala, is this your first time programming for games or have you created games in the past on other systems too? I've made games in the past on consoles and computers, but usually with a program that did all of the scripting for the user, so most of it was just adjusting parameters, enemy placement, paths and options to create.
One was an old program called the Shoot' Em Up Construction Kit on the old computers.
Switching to Game Editor was a challenge, but thankfully it was fun to see how changing the coding could make something different happen onscreen in the game.

On topic: I'm wondering how a Tron Light cycle game could be created using Game Editor. Your game is inspiring for something like that.
The arcade Tron had the light cycles game every fifth game choice (4 choices of games) but the difficulty got very tough after the 3rd replay of the Light Cycle challenge.

Re: Snake

PostPosted: Sat Apr 18, 2015 1:53 pm
by koala
Zivouhr wrote:Koala, is this your first time programming for games or have you created games in the past on other systems too? I've made games in the past on consoles and computers, but usually with a program that did all of the scripting for the user, so most of it was just adjusting parameters, enemy placement, paths and options to create.
One was an old program called the Shoot' Em Up Construction Kit on the old computers.
Switching to Game Editor was a challenge, but thankfully it was fun to see how changing the coding could make something different happen onscreen in the game.
I've programmed before, but not games. I have experience in C and I know it well, although I still have a lot to learn. GE is the first game developing tool I use, and I've started using it a month ago.

Zivouhr wrote:On topic: I'm wondering how a Tron Light cycle game could be created using Game Editor. Your game is inspiring for something like that.
The arcade Tron had the light cycles game every fifth game choice (4 choices of games) but the difficulty got very tough after the 3rd replay of the Light Cycle challenge.
Nice idea. Are you going to make Tron Light?