View Full Version : Falling Sand Game
Nicknack
08-03-2007, 01:43 PM
I've created a small water simulation, also known as Falling Sand Game. Here is a screenshot:[br]../../e107_files/public/1186143238_132_FT0_screen.png[br]
Features:-Adding water and sand(uuhhh... :) )
-Display current water and sand quantity
-Option to redraw screen
Controls:-Press A to close the prog.
-Press B to chance the drawmode between water and
sand.
-Press C to redraw screen.
You see, it isn't much yet, but this way beginners have the possibility learning from the code easily, changing it and adding more features.
One more feature, I'm interested in, is to raise the speed. Has any more experienced programmer an idea, how to realise this?
Here is the file.I've commented the code and if you have still questions, feel free to ask.
[br]1186144942_132_FT0_falling_sand_game.zip
kornalius
08-03-2007, 04:42 PM
Hi,
I have just tested your game. Very interesting. You should check for water particles not to be drawn off-screen, this can cause problems.
To speed it up, try changing the value 25 in your GameApiInit line to 5.
kornalius
08-03-2007, 06:59 PM
Try using the particle engine also, the drawing will be faster. Process the particles manually.
Here are some of the functions you can use:
AddParticle()
DelParticle()
RenderParticles()
ClearParticles()
SetParticleX()
SetParticleY()
etc..
Nicknack
08-04-2007, 10:03 PM
i have selected the 25 value on purpose to get an nearly equal speed on pc and ppc.
I use the std version so i can't use the particles engine.Is it real faster then my method?
kornalius
08-05-2007, 03:23 AM
Yes it is. Particles are faster to display then going through a List variable.
Another way would be to possibly create sprites with no surface assigned to them, PPL will draw pixels automatically using the Tint for color and Width and Height for pixel sizes.
In the new 1.30 (Std or Pro I don't remember, I would have to check), there is a new function that allow you to draw sprites or pixels stored in a List variable. There is a specific structure type to use for each List element.
I will post more on this new function called DrawList() soon.
Nicknack
08-05-2007, 10:16 AM
I used this "nosurface sprite"-method in another prog and it was already hanging on a quantity of 100 sprites on the ppc, so i'm looking forward to try out this drawlist() function.
kornalius
08-05-2007, 05:04 PM
The drawlist function will only be available in the Pro version.
In this case try using switching to Array instead of List. Arrays should be a little faster.
I suggest you update your pixels movement inside the draw function, this will limit the foreach loops to one.
Nicknack
08-17-2007, 04:15 PM
I tried now to use arrays, but i have one problem: how can i place a structure in an array?
kornalius
08-17-2007, 05:10 PM
#include "console"
func WinMain
InitConsole;
ShowConsole;
struct(s$, "a", tdouble, "b", tbyte);
TDIM(s$, 2, 2);
//Dim(s.a$, 2, 3);
//Dim(s.b$, 2, 3);
s.a$[0, 0] = "ALAIN";
s.b$[0, 1] = 2;
s.a$[1, 0] = "DESCHENES";
s.b$[1, 1] = 4;
writeln("s.a$[0,0] = " + s.a$[0, 0]);
writeln("s.b$[0,0] = " + s.b$[0, 1]);
writeln("s.a$[1,1] = " + s.a$[1, 0]);
writeln("s.b$[1,1] = " + s.b$[1, 1]);
return (true);
end;
Nicknack
08-17-2007, 06:30 PM
thanks for your help. I have also implented your other suggestions, so the next version will coming soon. ;)
Nicknack
09-30-2007, 03:18 PM
i was distracted by other projects in the meantime, but now i tried the array topic once more. I know how to create an constant "list" of arrays, but i have problems to flexible them: with linked-lists it's easy, you can add and del elements, but how can i free an array so it isn't recognized anymore by the for loops? and should i always redim or is it better to place the new arrays in the freed ones?
ps: i have also one question about the linked-list: is it absolute necessary that the structure in the list and the list itself have the same name?
Nicknack
10-02-2007, 10:40 AM
ok, to give you a better perspective of my problem i give an example how tried to realize the flexible loop:
My goal is to get only two of the three messages.
Code:
dim(a$, 3);
free(a$[1]); // get all three messages
//free(a$[0]); //no messages
i$ = 0;
ForEach(a$, addr$)
addr$ = i$;
showmessage(a$[addr$]);
i$++;
end;
the other "free memory commands" doesn't help me, too so how can i do this?
kornalius
10-02-2007, 11:58 AM
If you want to free an array use:
dim(array$, 3);
free(array$);
If you only want to remove an array element, you should use the following:
dim(a$, 3);
a$[0] = "HELLO";
a$[1] = "WORLD";
a$[2] = "YEAH";
a$[1] = NULL;
ForEach(a$, elem$)
if (elem$ != NULL)
ShowMessage(elem$);
end;
end;
You cannot easily remove an array element, just make it NULL and then in your loops (For or ForEach) check if the element is NULL or not.
Nicknack
10-02-2007, 01:01 PM
now it's plain to me :P
have i overlooked it anywhere in the tuts or in the manual? i think it would be a nice thing to add there, although now it's says here in the forum.
Nicknack
10-09-2007, 03:44 PM
ok here is Falling Sand Game 2.0:
[br]../../e107_files/public/1191940677_132_FT6101_screen.png
Changelog:
-dots are 4 times bigger
-improved speed
-added growing (in contact with water) plant-dots
-bigger brushes
-bugfixes
have fun and give a comment ;)
[br]1191941021_132_FT6101_falling_sand_game_2.0.zip
kornalius
10-09-2007, 05:48 PM
Nice job!
Keep them coming :)
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.