pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
pysand

pysand - 1.4

aexyl93 (aexyl93)

Tags:

Description

A falling sand game clone
Instructions:
Choose an element on the palette to the left and draw.
Sand changes to the color you pick on the palette
Press 'c' to clear the screen.
Press 'l' to have particles loop around screen
Press 's' to save current state
Press 'r' to load a state
Right click to erase the area under your mouse

Thanks to monkjr for getting saving and loading to work
Thanks to Khono for helping get network mode run at playable speeds.

Changes

Major changes in this release.
I've split the game into two different versions.
One version uses pygame and the other uses pyglet.
The pyglet version is faster, so i recommend playing that one, but i've kept a pygame version if you don't want to install pyglet.

**Speed**
I've tried everything to speed up the game.
First I tried storing coordinates as a string because I read that dictionaries are faster if the keys are strings but converting them to a string wasted too much time.
Then I tried hashing the tuple coordinates of a particle and using that as the key but that didn't do anything.
Then I tried parallel processing, giving each particle their own process but some error about pickling and objects with pointers in them came up. Then i tried fixing the error but that led to a lot of confusing code which still didn't work.
Then I tried using an array to store the particles and another array to keep track of their coordinates but that was even slower.
Then I tried storing what objects have interacted into a list and then check if they're in that list they don't interact again but that was even slower too.

I finally managed to double the speed of the game by giving each particle a variable telling if it's interacted or not and checking it. If it has interacted then it doesn't interact again, saving some time.
And then I doubled it again by using pyglet and using opengl to draw to the screen :D
I think the only way to make this any faster is to use a different language. I actually tried this in c++ with SDL a while back but the best i could get was some sand falling on the screen, a weird buggy clearing function, and the sand piling up. Some day I'll get back to it...maybe...
And if you have any ideas on how to speed it up please don't hesitate telling me :D I'm completely out of ideas or any kind of clue on how to speed it up. And if you really wanna know the most intensive operations are the draw and interact functions.

**New Additions**
*Added Steam

**Extras**
I've made it where the game doesn't try connecting to the server now until you tell it to so that way if the server is down when you start the game it won't freeze.
Also I now have it save your game when you exit, and load it when you play again.
And one of the times when I gave up on making it faster I decided to finally comment the code. The code is now heavily commented! (except for save and load functions... I have no idea how those work xD I'm terrible with files and strings)
And perhaps the best change of all is that you don't have to move the mouse to draw an element now. You can just hold it down and it'll continuously draw it.

And if the particles are too big for you, you can change the size by changing the variable 'grid_size' in the particle file in the Particle class.

Links

Home Page: http://doltin93.webs.com/python.html
Source: http://doltin93.webs.com/pysand/pysand14.zip
Windows: https://sourceforge.net/projects/pysand/

Screenshot


click to view original size

Releases

pysand - 1.5 - Mar 18, 2010
pysand - 1.4 - Mar 15, 2010
pysand - 1.2 - Mar 7, 2010
pysand - 1.1 - Mar 6, 2010
pysand - 1 - Mar 5, 2010
pysand - 0.9 - Feb 27, 2010
pysand - 0.8 - Jan 26, 2010
pysand - 0.7 - Jan 23, 2010
pysand - 0.6 - Jan 21, 2010
pysand - 0.5 - Jan 19, 2010
pysand - 0.4 - Jan 18, 2010
pysand - 0.3 - Jan 18, 2010
pysand - 0.2 - Jan 17, 2010
pysand - 0.1 - Jan 17, 2010

Pygame.org account Comments

If you wish to leave a comment with your pygame.org account, please sign in first.

March 30, 2010 8:48am - David Khono Hackland - nickname: (khono)
Yeah, magnie, in the network people can cooperatively sandbag each other :)
March 24, 2010 12:27am - Magnie Mozios - nickname: (magnie) - 3/5
Reminds me of the Falling Sand Game, which I bet is what it's based off of. ;) But amazing! Is the network where anyone can change the sandbox?
March 18, 2010 5:57pm - Gio Di Russo - nickname: (bulbear4444)
Suggestion:
Fire + Sand = Glass
Just an Element I came up with

Still, pwnful game!
March 11, 2010 7:11pm - Gio Di Russo - nickname: (bulbear4444)
I think there is an error with Networking, it unexpectdedly endswhen I hit "Network" Also, do you plan on bringing back "???"?
March 9, 2010 9:49pm - David Khono Hackland - nickname: (khono) - 4/5
Cool game! Based on other stuff, of course. I played something like this
many years ago, but a nice implementation!

I'd love to see some optimization and much smoother response from user input.

It'd also be cool if the currently selected button is highlighted in some way.

A quick and easy optimization would be to only refresh the play area (not the
palette).

But yeah, very nice implementation and I'm bookmarking it to see what else you do :)
March 1, 2010 3:05pm - Gio Di Russo - nickname: (bulbear4444) - 5/5
I Love it!☺
Very nice code, even better game.
January 29, 2010 4:22pm - quarkspin - nickname: (quarkspin) - 5/5
0.0 How does it run so fast???
January 27, 2010 3:12pm - James - nickname: (monkjr)
Your grass does not grow right in ver 0.8 but it does in ver 0.7
I don't know if you know this already but I thought I'd let you know.
January 26, 2010 3:48pm - James - nickname: (monkjr)
You're welcome! Ok, I changed the permissions and the name. See if that works.
So now go here:http://jamesjenkins.info/pysand07_with_save_and_load.zip
January 25, 2010 8:35pm - aexyl93 - nickname: (aexyl93)
Thanks for helping me monkjr! I look forward to seeing what you did but unfortunately the link isn't working. If you could please fix it that would be great.
January 25, 2010 4:33pm - James - nickname: (monkjr)
I figured out how to save and load

go to: http://jamesjenkins.info/pysand07 with save and load.zip
To see my version.(most of the changes are in the "grid" module)

Hope this helps!
January 21, 2010 6:29pm - aexyl93 - nickname: (aexyl93)
If you want, you can change the size of the particles yourself. Go into the particle file, then into the Particle class and then into the __init__function.
change the grid_size value to anywhere in 1 and 5. The grid will adjust to the size you specify.
January 21, 2010 6:14pm - Josh T - nickname: (mrbluesky)
I'm really looking forward to the eraser!
January 21, 2010 5:01pm - Gummbum - nickname: (gummbum)
This is coming along nicely, aexyl93. Can I have my tiny sand particles back? And I need to sprinkle them: they come out too fast now.
January 21, 2010 4:58pm - Gummbum - nickname: (gummbum)
Very nice, James! I did something similar in concept for my Gummworld Pygame project. Didn't realize someone had done it in a broader scope. Bookmarking that. Just goes to show that not only is necessity the mother of all invention. Boredom has a claim on it as well. :)
January 20, 2010 8:19am - James Mills - nickname: (prologic) - 5/5
Hi pysand developer :)

Because I was bored I tried to port your demo
to use my circuits event framework that sports
a pygame driver to source external events from.

Here's the code:
http://codepad.org/vlawnjIm

This is based on your 0.2 version of pysand.

--JamesMills (prologic)
January 18, 2010 8:54pm - Gummbum - nickname: (gummbum)
A palette of colored sands, maybe on a HUD. Then I can pick a colored sand and put the HUD away so it doesn't obscure my beautiful doodle. :) Doesn't have to be a palette, that's just what popped into my head.
January 18, 2010 1:53pm - aexyl93 - nickname: (aexyl93)
Thanks Gummbum for the suggestions and help. I'm not sure what you mean by a sand color palette though. Do you mean choosing different colors for sand or choosing an element from a palette?

And it's nice to see some competition! I'm glad that you decided to post yours.
I'd really like to see where both our games go. And thanks for the tips on the interactions.
January 18, 2010 1:14pm - Josh T - nickname: (mrbluesky)
Posted: http://www.pygame.org/project-Mr+BlueSky's+Rising+Sand+Game-1389-2450.html

I like how we both found very different answers to the same application; you used classes and objects for particles and I used numbers on a grid for particles.

I'm not entirely sure how you'd go about making interactions occur, but I checked all the cells around my particles and if they were full of something that my particle would interact with, it interacted. Fire might replace a nearby grass particle or grass might replace a nearby water particle. Fire also dies out randomly. I think there is like a 1/20 chance every frame of a fire particle dying.
January 18, 2010 11:21am - Josh T - nickname: (mrbluesky)
Wow lmao. I JUST made a game nearly just like this less than a week ago in python. I'll clean up my version and post it too.

It seems that you've got some competition~
January 18, 2010 1:30am - Gummbum - nickname: (gummbum)
Wish list.

I'd like to be able to: draw lines of varying thickness and color; load images into the game, and save the game surface for reloading; create sand spouts to place here and there so I don't have to keep sprinkling with the mouse; a way to selectively undo, or at least a crude eraser; and of course, a sand color palette.

And before it gets too late, could you make the sand pile up at least a little instead of leveling like liquid? If you can do this, there will be great potential to create sand paintings like you see in the southwestern US tourist shops.

Keep up the interesting work. This could become quite a fun doodling game. =)
January 18, 2010 1:20am - Gummbum - nickname: (gummbum)
Hi again. Keeping an eye on this one. :) To get v0.2 working I needed to modify a class declaration in particle.py: "class Particle(object)". Python 2.6.
January 17, 2010 10:03pm - Gummbum - nickname: (gummbum)
This is pretty clever. The sand seems to find slopes even on flat surfaces. I made a little cup which took a surprisingly long time to fill. :) Makes me think of an hourglass with the potential to get extremely fancy.
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Sep 19, 2014

Sep 17, 2014

Sep 9, 2014

Sep 8, 2014

Sep 7, 2014


Sep 5, 2014

Aug 26, 2014

Aug 21, 2014


Aug 18, 2014

Aug 2, 2014

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)