|
Author |
Topic: Cave! (Read 1396 times) |
|
levinbeicht
|
Cave!
« on: Feb 25th, 2005, 3:50pm » |
|
I quickly built this one for a friend of mine. http://www.clan-lsf.de/processing/cave/ Problem is: It runs smooth on most computers...but on some machines it gets incredibly slow (i.e. very unsmooth...even on my 2.5 ghz P4 at work) and i have no idea why... Here is the code, maybe someone has an idea what went wrong with it http://www.clan-lsf.de/processing/cave/Cave.java Edit: Gameplay suggestions also welcome
|
« Last Edit: Feb 25th, 2005, 3:51pm by levinbeicht » |
|
|
|
|
Quasimondo
|
Re: Cave!
« Reply #1 on: Feb 25th, 2005, 9:27pm » |
|
One possible problem with your code is that it's not really working efficently. As you are continouusly scrolling in one direction, everything that changes from frame to frame is just the right edge. The rest you could simply copy. I quickly hacked up an example how you could create the level and how to do horizontal scrolling in a different way. If you want to compose the player and the score on top of it you will have to render the cave in a separate BImage and then copy it to the main screen. So instead of pixels[] you would use yourImage.pixels[] Code: int[] level; int currentPosition; int levelLength; int caveHeight; void setup(){ size(640,200); background(0); currentPosition=0; levelLength=5000; caveHeight=80; level=new int[levelLength]; // fill the level with random values for (int i=0;i<levelLength;i++){ level[i]=(int)random(height); } // use a 1-dimensional blurring algorithm to smooth it. // in this case it runs 10 times. The more often it runs // the smoother it gets. for (int j=0;j<10;j++){ for (int i=0;i<levelLength;i++){ level[i]=( level[(i-2+levelLength)%levelLength] +2*level[(i-1+levelLength)%levelLength] +3*level[i] +2*level[(i+1)%levelLength] +level[(i+2)%levelLength] )/9; } } } void loop(){ int scrollStep=mouseX/64; int pixelColor; System.arraycopy(pixels, scrollStep, pixels, 0, pixels.length-scrollStep); for (int x=-scrollStep;x<0;x++){ int rightEdge=width+x; for (int y=0;y<height;y++){ pixelColor=0x000000; if (currentPosition+x>0){ if(y>level[currentPosition+x] && y <level[currentPosition+x]+caveHeight){ pixelColor=0xffffff; } } pixels[rightEdge] = pixelColor; rightEdge+=width; } } currentPosition=(currentPosition+scrollStep)%levelLength; } |
|
|
Mario Klingemann | Quasimondo | Incubator | côdeazur
|
|
|
levinbeicht
|
Re: Cave!
« Reply #2 on: Mar 1st, 2005, 10:06am » |
|
Thx for the ideas to do the level a bit more efficient! I already tried blurring, but i didn't like the look of it...well, it seems to be the best thing to let the scrolling look smoother... but the main problem is not solved...i tested the game (and also your code) on several computers now. the wierd thing is, it runs smoothest on my old 0.7 ghz AMD. I think it gets worse the faster the cpu is, which is incredibly weird.... so my inefficient code seems not to be the problem. anybody has any ideas?
|
|
|
|
|