Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411430 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 19, 2024, 05:52:04 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityDevLogsLife Eater - a snake that feeds on Conway's Game of Life
Pages: [1] 2 3
Print
Author Topic: Life Eater - a snake that feeds on Conway's Game of Life  (Read 10743 times)
dan19
Level 0
**



View Profile
« on: August 05, 2015, 03:56:15 AM »

Life Eater

The snake finds itself inside a cellular automaton known as The Game of Life. These two lifeforms cannot coexist peacefully! Help the snake survive for as long as possible by eating Life cells in huge numbers.

Recent playable build (work in progress, HTML5): http://danshved.github.io/life-eater/

Here is how it looks at the moment. The green pieces represent the snake, Life is all those yellow squares:



How to play

Main rule: surround Life to grow longer. Avoid hitting Life directly, this is fatal.

To eat a bunch of yellow Life cells, make a circle around them and seal the deal by biting yourself:



The longer the snake grows, the harder the game will become. The goal is to grow as long as you can.

Every once in a while an orange bonus cell will appear on the screen. If you manage to eat it before it disappears, this will wipe the game field clean:



Finally, a word of caution about biting yourself. You'll be doing a lot of this, and it is totally allowed, but don't do it in vain. If you bite yourself without surrounding any Life, you will grow shorter. This way you cannot escape dangerous situations for free by doubling back.



Still, you cannot grow shorter than a certain minimal length (currently 20), so that you always have a chance to regain what you lost by surrounding small groups of Life.

Plans

I'm using this project as an exercise to learn making HTML5 games. I'll try to keep it small and simple. As soon as it's done, I'll put it on Newgrounds.
« Last Edit: January 18, 2016, 01:20:20 PM by dan19 » Logged

jctwood
Level 10
*****



View Profile WWW
« Reply #1 on: August 05, 2015, 04:19:09 AM »

So what are the smaller pieces of Life and how do they come about? Really lovely concept, look forward to some deeper technical insight into how you are implementing Life. What are you building the game in?
Logged

dan19
Level 0
**



View Profile
« Reply #2 on: August 05, 2015, 05:25:31 AM »

So what are the smaller pieces of Life and how do they come about?
Those small pieces are animations of appearing/disappearing Life cells caught on a screenshot between ticks Smiley

Really lovely concept, look forward to some deeper technical insight into how you are implementing Life. What are you building the game in?
Thanks. I'm using the Phaser engine. Implementation of Life itself is very simple and straightforward, all the ideas are standard.

1. I represent the field as a 1-dimensional array of booleans instead of an array of arrays. The state of a cell at coordinates (x, y) is kept in arr[x * SIZE_Y + y]. In other words, I emulate C-style 2-d arrays. Not sure if this gives much in terms of performance though.

2. I allocate all the memory only once. I also avoid copying large amounts of data. I achieve that by using double-buffering. That is, I have two boolean arrays: one for the current situation, one for the situation one tick later. After each tick I swap buffers. Of course, I do it instantly by swapping references to the buffers rather than swapping data cell-by-cell.

You can see the code here, lines 30-94.

That's basically it. What little experimenting I've done shows that these Life calculations take very little CPU. It's nothing in comparison with what Phaser itself takes to handle all the sprites that actually animate what's going on on the game field.
Logged

BlackseaOdyssey
Level 1
*



View Profile WWW
« Reply #3 on: August 05, 2015, 05:34:00 AM »

This is pretty cool :D I'll be honest though, I totally thought it was going to be like snake, but you can't run into the cells or whatever! Might be pretty cool xp
Logged

dan19
Level 0
**



View Profile
« Reply #4 on: August 05, 2015, 05:47:27 AM »

This is pretty cool :D I'll be honest though, I totally thought it was going to be like snake, but you can't run into the cells or whatever! Might be pretty cool xp
Yeah, for now you don't even run into Life cells. That's because I haven't implemented dying of any kind just yet. In the 2 days that I've been working on this, I've only finished the core mechanic of destroying Life by surrounding it. So, running into walls, running into Life cells, eating cherries -- all that stuff is way in the future Smiley
Logged

jctwood
Level 10
*****



View Profile WWW
« Reply #5 on: August 05, 2015, 05:52:52 AM »

Thank you for the explanations! I am kind of obsessed with snake so great to see a new take on it. (see snakeball for my take)
Logged

dan19
Level 0
**



View Profile
« Reply #6 on: August 05, 2015, 06:59:21 AM »

Thank you for the explanations! I am kind of obsessed with snake so great to see a new take on it. (see snakeball for my take)
It's nice. Only 14 points so far though :D
Logged

jctwood
Level 10
*****



View Profile WWW
« Reply #7 on: August 06, 2015, 12:47:47 AM »

The best I've seen is 127. Do you have plans for variable difficulties? Maybe larger play areas or more life or faster life?
Logged

dan19
Level 0
**



View Profile
« Reply #8 on: August 06, 2015, 01:15:35 AM »

The best I've seen is 127. Do you have plans for variable difficulties? Maybe larger play areas or more life or faster life?
Yes, I'm planning to make everything go faster as the game progresses. The speedup is for both Life and Snake, since they follow the same clock ticks. Hopefully, this will be enough to make it interesting.

There are other possibilities: larger areas, more life (higher frequency for spawning colonies). Or one can make levels with undestructible rigid walls. Also, one can achieve unequal speedups for Life and Snake by having, for example, 2 life-ticks per each snake-tick. But I consider all these possibilities as "backups". I want to keep things simple, so Plan A is to change nothing but the speed.
« Last Edit: August 06, 2015, 01:23:29 AM by dan19 » Logged

BlackseaOdyssey
Level 1
*



View Profile WWW
« Reply #9 on: August 06, 2015, 04:41:14 AM »

Yeah, for now you don't even run into Life cells. That's because I haven't implemented dying of any kind just yet. In the 2 days that I've been working on this, I've only finished the core mechanic of destroying Life by surrounding it. So, running into walls, running into Life cells, eating cherries -- all that stuff is way in the future Smiley

Oh okay sweet :D I'll keep an eye out for updates. Smiley
Logged

dan19
Level 0
**



View Profile
« Reply #10 on: August 07, 2015, 01:29:06 AM »

I've implemented two things yesterday: 1. There are now cherries that make the snake grow longer; 2. Life starts out as an empty field, and new Life colonies are spawned on the field every once in a while.

Cherries aren't very interesting. Far more worthy of attention is the spawning of colonies. I'm planning to add to the game a small base of interesting Lifeforms, such as oscillators and spaceships, but for now I'm just spawning 2x2 squares aka blocks. This is the simplest still life there is.

Even this one lifeform is enough to produce some unpredictable results. When blocks are spawned near each other, they begin to interact and evolve. Look at the animation below. A new block is spawned. Things are peaceful so far. There have been some short interactions which produced a beehive and a beacon:



Now look what can happen later in the game. This one block is like a small match starting a big fire:



I have a feeling that ignitions of this sort can make the game more interesting than I thought. From what little practice I had with them so far, they seem pretty difficult to completely put out. On the other hand, if you survive long enough, fires tend to expire all by themselves, leaving only a bunch of still lifes and blinkers on the field.

I'm a bit worried that fires will make the game too difficult, but we'll see. Maybe they will become less of a problem if I spawn life colonies with lower frequency. Also, fires become much less dangerous and end quickly when warping around screen edges is turned off for Life (it's as if screen edges had zero temperature and made everything that touches them cool down). There's also an option of slowing down all Life by a factor of 2 (say). This makes it much, much easier to simply outrun any serious danger. Don't know yet which way of firefighting I'll choose.
« Last Edit: August 09, 2015, 02:42:12 AM by dan19 » Logged

BlackseaOdyssey
Level 1
*



View Profile WWW
« Reply #11 on: August 07, 2015, 03:55:28 PM »

Looks like the game is getting a nice difficulty curve going. :D Cool additions Smiley
Logged

dan19
Level 0
**



View Profile
« Reply #12 on: August 07, 2015, 10:30:57 PM »

Looks like the game is getting a nice difficulty curve going. :D Cool additions Smiley
Thanks!

I have a feeling that the difficulty curve is what will make or break this game. Hopefully, I'll find a good balance there.
Logged

Zorg
Level 9
****



View Profile
« Reply #13 on: August 08, 2015, 06:18:26 AM »

For fun, throw in the R-pentomino. Wink

##
##
#

Logged
PypeBros
Level 0
***


Simplest, but not Simpler


View Profile WWW
« Reply #14 on: August 08, 2015, 07:19:41 AM »

nice idea. It would be neat if the snake's speed was increased a bit, though.
Logged

dan19
Level 0
**



View Profile
« Reply #15 on: August 08, 2015, 07:41:30 AM »

For fun, throw in the R-pentomino. Wink
Done. Makes a nice explosion, thanks!

Due to the limited game field it doesn't behave exactly as in your picture. But it wouldn't anyway, because something else would be spawned and get in the way.
Logged

dan19
Level 0
**



View Profile
« Reply #16 on: August 08, 2015, 07:49:51 AM »

nice idea. It would be neat if the snake's speed was increased a bit, though.

Thanks! Increased the speed by 33% for now. The speedup is both for the snake and for Life, since they are in sync.

I will probably be tinkering quite a bit with the speed (and all other constants). The current pace of the game isn't representative of what it will be in the final version. Not to mention that I'm planning to make things speed up gradually as a function of the score.
« Last Edit: August 08, 2015, 08:11:52 AM by dan19 » Logged

TheWing
Level 1
*



View Profile WWW
« Reply #17 on: August 08, 2015, 09:07:18 AM »

Ooh, nice! you should also add some basic gliders and spaceships, they might be fun to try and trap :D

Loving the graphics and general feel of the game, and as a more 'late-in-the-dev'-suggestion I'd like to see custom colour schemes

Nice project, so keep it up o/
Logged

- - - -
dan19
Level 0
**



View Profile
« Reply #18 on: August 08, 2015, 10:55:00 AM »

... you should also add some basic gliders and spaceships, they might be fun to try and trap :D
By all means! I'll add more, but even now there already is a simple glider, you'll definitely see it if you play long enough.

PS: Right now the spawned lifeform is chosen at random from this short list: a 2x2 block, a glider, a blinker, or an R-pentomino.

PPS: Your late-in-the-dev-suggestion is noted Smiley
« Last Edit: August 08, 2015, 11:02:19 AM by dan19 » Logged

dan19
Level 0
**



View Profile
« Reply #19 on: August 09, 2015, 02:24:57 AM »

The looks
I've changed the way the snake is displayed. Instead of plain and simple squares, its body now consists of 4 types of segments: the head, the end of the tail, middle segments, and corner segments. Here's the sprite sheet I ended up with:



As you can see, I've also changed the colors. I'm quite happy with what I'm seeing, so I think there won't be any more drastic changes in this department. Here's what the game looks like now:



The gameplay

I've added one important feature: you can die now. It doesn't look too impressive though: the game simply restarts. Still, now it's actually a well-functioning program: you shouldn't be able to produce weird unexpected results when the snake goes out of the screen boundaries, as you could before.

One other thing: the list of spawned lifeforms has grown from 1 to 4 patterns: block, blinker, glider, and, by zorg's request, R-pentomino. Of course, the list is far from final.

Now I think it's time to start playing with the difficulty. First: make a score counter. Second: increase TPS (ticks per second) and spawn frequency as the score grows. Third: fill the "database" with several dozen lifeforms and unlock them little by little.
Logged

Pages: [1] 2 3
Print
Jump to:  

Theme orange-lt created by panic