Hello, LÖVErs. I've been creeping around the scenes now for a few weeks, trying to get a good hold on LÖVE and Lua, as well as popping into the IRC channel to get a feel for the community. I'm sort of getting the grasp on the whole thing, or rather I thought I was making good progress haha! Well, this is what I'm working with right now.
I've been working on a snake clone, and I've been doing all of the coding without looking at any others for reference, and it worked great; till it came time to conceptualize how to add more bodies to the original snake after each dot is eaten. I've tried looking at bmzz's snake game but it seriously has me lost in way to many places to count. I just can't grasp what is going on in that source code no matter how many times I look at it. I've been reading through Programming in Lua ( Just got second edition in the mail ) and I'm starting to understand how the ipairs function works and stuff like that, it's just that I can't seem to grasp the idea of what I need to do to get this to work.
I've gotten the movement, spawning of the dots, collision detection (Thanks to the HardonCollider), scoring, etc. Really, all I need to finish the first phase of this game is to figure out how to make the trailing bodies. Then I can work on making a menu and other variables, perhaps obstacles and stuff, but I'll cross that bridge when I get to it
Below is my example right now. I've included many comments so who ever looks at it has a good idea of where I'm going with this whole thing, or at least what I'm thinking or aiming for.
Thanks in advanced, you guys and the wiki are very helpful!
EDIT - Upload didn't work at first.
My attempt at a snake clone. Fail.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
My attempt at a snake clone. Fail.
- Attachments
-
- game.love
- Re-uploaded...
- (2.92 KiB) Downloaded 187 times
Re: My attempt at a snake clone. Fail.
I think it would be much easier to do with a grid of sorts. E.g. represent your snake as an array of dots on this grid, and each time the snake moves, add one dot to its head in the direction of movement, and remove the last dot of the tail. If the snake eats something, you just don't remove the dot from its tail. To draw the snake, you just draw every dot in this array.That would probably be the simplest way of doing it, and I'm pretty confident that it was just like this in most of the snake games.
Besides, why are you using such a cryptic way of representing directions (I know, clock dial numbers)? You can just use strings like "left" of "down".
Besides, why are you using such a cryptic way of representing directions (I know, clock dial numbers)? You can just use strings like "left" of "down".
Re: My attempt at a snake clone. Fail.
Yes, you seem to have the concept mixed up. From the following code:Purdy wrote:Really, all I need to finish the first phase of this game is to figure out how to make the trailing bodies. Then I can work on making a menu and other variables, perhaps obstacles and stuff, but I'll cross that bridge when I get to it
Code: Select all
for i,v in ipairs(snake.l) do
v.tx = snake.x
v.ty = snake.y
end
What you need to do is to:
- append the head of the snake as a body element (with it's x,y position) to the body table (snake.l)
- if the snake.l length is greater than the current snake lenght, remove the last element
- once the element is added to the table, you dont mess with it (don't change its position - it is "static"), you can only remove it from the table
- when drawing the snake, draw all its body segments at their x,y positions
So basicaly the body of the snake (a list of elements) is a FIFO table, with its length increasing over time.
EDIT: and please name your attached file file like "snake-purdy.love" or so, because "game.love" is so generic...
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
Re: My attempt at a snake clone. Fail.
Hmm... That seems like a pretty legit way of doing things, I will definitely look into doing it like this. I'm not 100% sure how to do this, but I'm gonna think it over and hopefully come up with something. The more I think of it, the more it makes sense!Rad3k wrote:I think it would be much easier to do with a grid of sorts. E.g. represent your snake as an array of dots on this grid, and each time the snake moves, add one dot to its head in the direction of movement, and remove the last dot of the tail. If the snake eats something, you just don't remove the dot from its tail. To draw the snake, you just draw every dot in this array.That would probably be the simplest way of doing it, and I'm pretty confident that it was just like this in most of the snake games.
Yeah, I know; I just figured it would be less typing, ya know?Rad3k wrote:Besides, why are you using such a cryptic way of representing directions (I know, clock dial numbers)? You can just use strings like "left" of "down".
And thanks for the quick reply!
On a side note: I wanna get some other people's take on this, so please keep the great ideas coming!
Re: My attempt at a snake clone. Fail.
this is my nice looking snake game thingy, i still need to ad blocks that you can eat but snake works good
maybe you can learn from it and get some ideas
Edit : SORRY PEOPLE I UPLOADED THE WRONG VERSION WICH HAS NO QUIT BUTTON, DO NOT DOWNLOAD
Edit : Oke i fixed it press 'escape' or 'q' to quit
maybe you can learn from it and get some ideas
Edit : SORRY PEOPLE I UPLOADED THE WRONG VERSION WICH HAS NO QUIT BUTTON, DO NOT DOWNLOAD
Edit : Oke i fixed it press 'escape' or 'q' to quit
- Attachments
-
- Snake.love
- (966 Bytes) Downloaded 159 times
Last edited by GijsB on Wed Sep 14, 2011 3:54 pm, edited 2 times in total.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: My attempt at a snake clone. Fail.
That is just horrible. Everyone, do not run that. It sets itself to fullscreen, which should be punishable by death in the first place, and it has no way to quit, which means I had to break out to the shell and killall love, leaving my desktop in a messed up state.GijsB wrote:this is my nice looking snake game thingy, i still need to ad blocks that you can eat but snake works good
maybe you can learn from it and get some ideas
Help us help you: attach a .love.
Re: My attempt at a snake clone. Fail.
OH NO i uploaded the wrong version wich has no quit button 3:!!Robin wrote:That is just horrible. Everyone, do not run that. It sets itself to fullscreen, which should be punishable by death in the first place, and it has no way to quit, which means I had to break out to the shell and killall love, leaving my desktop in a messed up state.GijsB wrote:this is my nice looking snake game thingy, i still need to ad blocks that you can eat but snake works good
maybe you can learn from it and get some ideas
- The Doctor
- Prole
- Posts: 3
- Joined: Thu Sep 08, 2011 6:00 pm
Re: My attempt at a snake clone. Fail.
Woah! The circeling/gravity mode was really addicting! It feels as I've been hypnotized for 1 hour!GijsB wrote:this is my nice looking snake game thingy, i still need to ad blocks that you can eat but snake works good
maybe you can learn from it and get some ideas
Edit : SORRY PEOPLE I UPLOADED THE WRONG VERSION WICH HAS NO QUIT BUTTON, DO NOT DOWNLOAD
Edit : Oke i fixed it press 'escape' or 'q' to quit
Re: My attempt at a snake clone. Fail.
thanksThe Doctor wrote:Woah! The circeling/gravity mode was really addicting! It feels as I've been hypnotized for 1 hour!GijsB wrote:this is my nice looking snake game thingy, i still need to ad blocks that you can eat but snake works good
maybe you can learn from it and get some ideas
Edit : SORRY PEOPLE I UPLOADED THE WRONG VERSION WICH HAS NO QUIT BUTTON, DO NOT DOWNLOAD
Edit : Oke i fixed it press 'escape' or 'q' to quit
Re: My attempt at a snake clone. Fail.
Sadly I couldn't get it to run for some reason... I dunno, it just opened up love and exited. That's really besides the point though, I've been looking at the code and I think I'm starting to get a good picture on what needs to be done. I'm gonna have to get back to you all with my progress!GijsB wrote:this is my nice looking snake game thingy, i still need to ad blocks that you can eat but snake works good
maybe you can learn from it and get some ideas
Edit : SORRY PEOPLE I UPLOADED THE WRONG VERSION WICH HAS NO QUIT BUTTON, DO NOT DOWNLOAD
Edit : Oke i fixed it press 'escape' or 'q' to quit
Thanks for the help everyone!
Who is online
Users browsing this forum: Google [Bot] and 0 guests