Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,382 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
REQ: 2D snake type game ? #257238
03/21/09 20:35
03/21/09 20:35
Joined: Apr 2008
Posts: 437
dracula Offline OP
Senior Member
dracula  Offline OP
Senior Member

Joined: Apr 2008
Posts: 437
Do you recall a 2D snake game where the snake gets longer when it "eats" things. If it touches certain things (or itself), it dies ?
Does anyone have any code or even suggestions how it could be implemented ?

Thanks

Re: REQ: 2D snake type game ? [Re: dracula] #257244
03/21/09 21:49
03/21/09 21:49
Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
slacer Offline
Expert
slacer  Offline
Expert

Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
Hi,

I don't have such a script for you, but some suggestions how you could do it.

- create a large room with some wall fragments inside this level.
- add some entities with a simple action and enable the needed events.
- you need a player entity. Mark it as player by setting an entity flag to ON
- put a camera above the level in WED (add->position) and turn it downwards. Play a bit with its z-value until the camera can see the whole level.

- add some keyboard control to your program in order to turn your player to the left or right side. Your action needs the code to always run into current direction.

If you detect a collision with an entity, you check the "you.flag1" to see, if it was your tail - and maybe you let the snake die in this case.

If it is a wall, the snake has to die, too.

If it was something to eat, you increase a grow skill in your player entity.

----------------------
This was the main part.

----------------------
How does a snake work?
- create an array of structs to hold x- and y- positions, or create two arrays if you dislike structs.

Initialize the array with the inital length of your snake (depends on the game level)
write xy positions into your array.
if your snake moves one step forward and it does not grow, you copy the position values from the last-1 element into the last element and you do this for all elements.
move your head one step forward and write its new position into the array element with the highest index.
Now let all tail segment read its position from the array and move it to its new position.

If you are in groth mode, you simply fill an additional array element and don't change a single position of the tail.

This should get you started.

-- slacer

Re: REQ: 2D snake type game ? [Re: slacer] #257325
03/22/09 17:20
03/22/09 17:20
Joined: Apr 2008
Posts: 437
dracula Offline OP
Senior Member
dracula  Offline OP
Senior Member

Joined: Apr 2008
Posts: 437
Hi Slacer, thanks for the input.

How is the snake made ? I was thinking about using pan_create to generate the new segments. Getting it to "bend" is where I am stuck

Thanks

Re: REQ: 2D snake type game ? [Re: dracula] #257329
03/22/09 17:40
03/22/09 17:40
Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
slacer Offline
Expert
slacer  Offline
Expert

Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
Hi dracula,

I would not use panels because they would not create the collisions with walls.
Use a simple sphere as body.

In fact, this game would be a 3D game seen from above (like a bird looking down). Because the camera is so high, that it can see the whole level, it looks like a 2D game. smile

Try to make your game without the snake (only the head) and let it eat all things in the area.

Once you get this done, I can help you if you don't understand to use my previos post.

-- slacer

Re: REQ: 2D snake type game ? [Re: slacer] #257335
03/22/09 18:36
03/22/09 18:36
Joined: Apr 2008
Posts: 437
dracula Offline OP
Senior Member
dracula  Offline OP
Senior Member

Joined: Apr 2008
Posts: 437
BTW: If you wanted it to be truly 2D, how might you do it ?

Thanks

Last edited by dracula; 03/22/09 18:37.
Re: REQ: 2D snake type game ? [Re: dracula] #257341
03/22/09 19:16
03/22/09 19:16
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
My game "Rudi" has similar game mechanics, check out my website. The source is free.

Re: REQ: 2D snake type game ? [Re: HeelX] #257348
03/22/09 20:20
03/22/09 20:20
Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
slacer Offline
Expert
slacer  Offline
Expert

Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
Hi HeelX,
nice game and great workshop document.
Maybe you want to add this document to the wiki? A lot of questions about organization of work, etc. are discussed in your work.


-- slacer


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1