rvj wrote:Good questions, and I'd like to see the answers to them (as well as a love file of your set up).
Since you ask, I've attached what I've got so far. It's not all that exciting. Some of it is very well documented, but most of it is not. Mostly I've been avoiding putting it up because it doesn't necessarily have all the correct attributions yet. I'm using Anim8 for the explosion which I borrowed from a free game art web site, HadronCollider [sic] for collisions (which I feel I need to rewrite just so I don't have to worry about my son seeing the name), and some code based on others work but entirely rewritten.
Start it up and you are the ship in the middle. Collision detection is not functional for the player so there's no way to die. You will never reach the end of space because it wraps around (you will notice when you wrap around if you look at the position in the lower left corner). All objects wrap around, bullets, you, gold discs, everything -- that was my big headache tonight, but it came out well in the end; unfortunately it means I have to draw things up to three extra times if they are at the wrong part of space (in the buffer). The following controls work:
- space bar to thrust which uses fuel (capacity shown in the bar along the bottom) which regenerates slowly. Once you're in motion, you'll stay that way until you thrust the other way. if you deplete your fuel entirely, it will become unusable for a short time.
- 'f' toggles the camera mode; it lets you do some cool stuff with the ship. It will toggle to static screen and then back to the follow mode. If you wrap around, the transition to follow mode will act bizarre.
- mouse button 1 shoots.
- mouse wheel up and down zoom in and out (only on the topmost layer, stars all remain the same size)
- the pause keyboard button will pause the game
- 1, 5, and 0 change the game speed (0.5x, 1x and 1.5x respectively)
It's not meant to be fully functional or it'd be in the demos section. Also, not fully optimized -- some things I know, many I don't. I'd certainly love for people to tell me obvious beginners mistakes if they are so inclined, but mostly I just wanted general answers to the questions rather than a grooming of my code.
rvj wrote:
I have one line of code that checks each object before it draws. I just commented it out and can't see a difference in FPS. The only lesson we can learn from that is that it's sweet to write code that lets you make these decisions later.
I did roughly the same thing and didn't notice any change in behavior. But there isn't a lot happening so I'm not sure that I'd see any benefit yet. Mostly I'm just looking for best practices and I don't think that's really been answered yet. I've been trying to design with future changes in mind, though some aspects are just randomly dumped into main for now until I find the right place for them.
verilog wrote:paritybit? nice nickname
Thanks.
verilog wrote:
The main idea here is that you usually draw stuff outside the screen to be able to present it in real-time to the user as the camera scrolls back and forth (or up and down!). Of course, you don’t want to be wasting resources drawing things that are 20 screens ahead of the actual viewport position.
So should I be using some kind of spatial data structure to limit the sections of the world tiles and actors are actually drawn? How far outside the current viewport should I draw? It seems like I don't really need to draw outside the viewport because as soon as something shows up I could just start drawing it and that would have the same effect? When I add something new to what's being drawn, there's no real hit that I can tell. I'm just slightly confused about all this.