Hi
24 hours into my #indievspewdiepie game. I’ve got circles that shoot bullets at you, a circle that is you, and a nice red reticle. The circles are generated by a (currently invisible) mother ship. The art is all just drawing primitives, and I think I will probably keep it that way for the jam.
I worked super hard on the infinite starfield. It probably took, like 4 hours or something stupid. I went off of a helpful article, but encountered many tricky tricks along the way.
The technique, basically, is to imagine an infinite square lattice. Each lattice point is indexed uniquely by a point in Z^2 — such as -2, 7. When you draw the screen, you first ask which lattice point will be in the upper left corner of the drawable space (maybe a little off the screen), and then iterate over enough lattice points to paint the whole screen.
Now the interesting part is the stars, of course: each lattice square has an index, as I mentioned. Pass the lattice square’s unique integer coords and a seed into a hashing function, and you will get a big ol’ 32 bit integer that is guaranteed to be unique for each lattice square. Use that 32 bit integer to choose the positions for a couple of stars (relative to the top left corner of the lattice) and you are good to go.
What is super duper cool about this is that, if the player leaves and returns to the same part of space, they will see all the same stars! So you’ve basically got an infinite expanse of randomly generated stars that never change or get lost or regenerated. Layer them for paralax if you care to! (I did, but you can’t see that from the screen shots)
Depending on how I feel, I might further customize it so that the stars closer are actually more pixellated. I kind of think that, since the rest of the game’s art will be rough edged geometry, the stars should fit the mold.
Finally, here is a link to the original article, and here is a link to a gist with my (lua) implementation. Feel free to offer criticism! I love you!
z.
0 comments