NoviceMan
YaBB Newbies
Offline
Posts: 5
New and in need of some help.
Mar 23rd , 2009, 7:49pm
First off, I would like to say Hi to everyone here and look forward to working/collaborating with everyone in the future. Anyways, I am rather new to the processing language, but so far have been making some good progress with my work and am enjoying it thoroughly. Lately I have been working on creating various games, and so far have made some basic ones like pong, a simple space invader, etc..., but am stuck on my Snake game. I figure once I get the basics down I can move onto more complex games. Anyways, at the moment I have a running Snake game that has the initial snake and it moves and depending on if you push d(down), u(up), l(left),r(right), it will move that direction. However I am stuck in the whole make a random piece of food on the map, and how, once that piece of food is eaten, it adds one more ellipse to the very back of the snake. I will include the code I have so far, and if someone could show me how I could accomplish what I am having trouble doing it would be greatly appreciated. My code is as follows... int len=20; // length of worm int sz = 10; // size of worm segment in pixels int[] x = new int[len]; int[] y = new int[len]; int dx=1; int dy=0; void setup() { size(500,500); for (int i=0; i < len; i++) { x[i] = width/(2*sz)-i; y[i] = height/(2*sz); } frameRate(5); } void draw() { background(100); if (key == 'd') { dx = 0; dy = 1;} if (key == 'r') { dx = 1; dy = 0;} if (key == 'u') { dx = 0; dy = -1;} if (key == 'l') { dx = -1; dy = 0; } for (int i=0; i < len; i++) ellipse(sz*x[i],sz*y[i],sz,sz); for (int i=len-1; i > 0; i--) { x[i] = x[i-1]; y[i] = y[i-1]; } x[0] = x[1] + dx; y[0] = y[1] + dy; } //void make_food(){ // // fill(255); // rect(random(501),random(501),10,10); } I believe that this is good code and would like to not have to change what I currently have too greatly because I understand it well, but am open to new methods to accomplish what I am trying to achieve. That last part is unneccesary and was just me messing around with random placement. If this is the wrong section to put this in or not how this forum works I apologize.