It looks like you're new here. If you want to get involved, click one of these buttons!
I've been developing a little homage to the 1979 arcade game, Asteroids, in Codea. I'm doing a series of articles, up to #17 right now and not done, describing how I build up a program like this. I've intentionally started in a procedural way, as one often does, and only now is the program beginning to move to a more object-oriented style.
Unlike many "how to" articles, my articles show the trials I make, the mistakes, the recoveries, all the things that happen to real programmers when we build real programs. I hope that folks interested in Codea will find this series useful.
Comments and questions are welcome.
Comments
@RonJeffries - been following your development of Asteroids with interest, like to see how real coders approach projects. I never seem to be able to finish mine, hit a snag, shelve and start a new project. Trying to get round that now.
I have made a few mods to your project on my pad - deleted the testAsteroids tab. Moved and modified the score display (just personal preferences).
Slightly modified the drawAsteroid() function to partially hide the circle showing the asteroid size by making it more transparent (still retained it for development).
Also, I increased the stroke and changed the colour on the ship to make it more prominent - just my preference.
I know these deviate from the original, but I think they do lift it a bit. Are you intending explosion of the ship on collision with asteroids?
Will continue to follow this, very neat and very professional. Thanks.
p.s. made me go back to my own thread with space invaders, which I hoped would suck in ideas, suggestions and code ideas. Must finish that!!!
p.p.s - not your code, but I have an issue with buttons near the iPad screen edge, dragging in other windows - distracts the concentration of us space pioneers dealing with the asteroid storm!!! I have raised this with @Simeon to see if we can switch out some iOS features to avoid this.
i'm glad you're finding value. i plan to build in most of the function of the original, so, yes, the ship will explode when hit by an asteroid. i removed the circle entirely this afternoon, as it had served its purpose.
the ship is not drawn properly so will be changed to better match the original. making it a bit more visible is probably a good idea.
one challenging bit may be the sounds, either emulating them or ideally getting the originals somehow.
questions and comments are welcome!
@RonJeffries very interesting blog - only just come across it now so have a backlog to work through. Though you say its aimed at those new to Codea - I’ve been using it for years and have taken a lot from it already.
Here’s a zip of a step by step tutorial I put together 6 or so years ago for asteroids. It’s been interesting going back over it (and seeing a bunch of stuff which has been deprecated and I’m not sure that the step by step one from the github works anymore). One thing that jumped out at me was that when putting it together I focussed on getting the player’s ship up and moving then firing bullets before adding the asteroids. I note that you’re going for a depth first approach on the asteroids - getting them faithful to the original before moving on. Not a criticism, just an observation.
The second zip is the game fleshed out a bit. Different asteroid types (custom graphics), different power ups, levels named after actual asteroids. Still very rough (and from a few years back). Like @Bri_G I don’t tend to finish things, but this was one of my more complete efforts.
Anyway, just thought some of it might spark some food for thought.
Looking forward to the rest of the series
Thanks for the look and feedback. I did the asteroid shapes mostly because I was studying the 6502 code for the original and decided to try to draw the asteroids to check my understanding, so I went at it when my mind was (relatively) fresh. In any reasonable sense, round ones would have been a good place to move on, coming back to refine the shapes later.
Naturally, at some point, I plan to replace them with more attractive sprites, but shhh that's a secret, and I want to get close to the original first anyway.
I'll have a look at your work but am trying not to contaminate my mind, so that the mistakes I make (and always document) are not made less likely by seeing something sensible.
Thanks!
@West - nice package, very good finish. Sure I saw your tutorials before but working through them slowly now. Thanks.
The tab trick is interesting but deep in the guts.
@RonJeffries the tab trick was something another forum member passed on way back - it was trying to convey the slow build up of a program in a self contained package, however I do think blog posts allow for much more depth
Thanks @Bri_G ther should be lander and snake somewhere, but not sure if they still work
Yes, I saw that you had borrowed the tab trick. I must try to figure out how it works one of these first days.
@RonJeffries - think kill the ship killed the score.
In the drawScore function, change self.score to Score.
@dave1707 - thank ‘ee your a gent!! Now when the ship goes blammo I get a 20 point lift in my score. Now checking for collisions to see where the score increase comes from.
Edit: looks like it comes from the asteroid score, so when you go blammo the asteroid takes damage but the ship is splatted.
ah. prob should be fixed the other way, i'll treat it as a bug report for next time. thanks! i wonder how to prevent these glitches.
@RonJeffries You can’t prevent glitches, you can only do a lot of testing to find and fix them. Question: If you have a bug in your code and nobody finds it, is it still a bug.
@RonJeffries - the answer to your question is play, play play!! Or, more sensibly, hand over the bug testing to a lot of willing hands/digits/minds - US !!!! Thanks.
better microtests would help a lot, and i've not been doing a good job of that. it's tricky with games.
not precisely. but small test, taking short time to write first, short time to make run next, then nailing that bit down thereafter
not quite. too tricky to fully explain here. Basically "Test-Driven Development" is the root discipline but in the case in hand, I've not been doing full TDD, for reasons, but using it sometimes. It can be used to test-drive anything, just that the tests are small steps as are the implementations. If you read my articles on Asteroids, you'll see that everything I do is in very small chunks which I make work before doing another chunk. With decent micro tests, each chunk would also have a tiny test to show / confirm that it works. Normally I always do that, but with a graphical game I don't see quite how to do it effectively yet.
A question. It's a pain to copy / paste the code from my web site, as it is large. I could save it as a text file to click on, or as a zip file. I'm not quite up to doing a magic copy-to-clipboard function, as the code is heavily formatted on the site.
Which of text file or zip file would be easier for someone loading into Codea? I only know how to load a text file into Codea: is there even a way to load a zip? What third way might be better?
Thanks!
@RonJeffries - you can export your Codea file as a zip and then post that. Codea users can then open the zip, using the iOS system, with Codea. That should ease any issues with copy/paste.
p.s. I approach development in a similar manner, but - having a large amount of code accumulated of years of playing with Codea I tend to make shortcuts by building on existing code and refining. I must say often running into many issues, but then again it’s all learning.
how does one open a zip with codea?
Failing that under the icon row iOS shows a text list of options, one of which is Open With - that should get you there.
I find the whole iOS filing a bit of a mess but you can usually find an option that works.
The sharing list can be configured, up to a point, through iOS.
Oh, by the way it depends on which iOS version you are running.
Ah, good. Odd that to import a paste you long-press the + that adds a project and that that does NOT bring up a file accessor. Thanks!
@RonJeffries worked my way through the blog - really useful and informative. Two major takeaways for me so far:
Now using working copy - I would always get the FOBC (fear of breaking code) if I wanted to change stuff - and would copy and comment out working sections as a backup - unsustainable so glad I've found a painless alternative
Splats[self] = self : An alternative to the way I normally manage objects (which was sub optimal and messy) - still am not 100% comfortable with it but getting there
Really looking forward to seeing where you take it
Hi @West Yes, working copy is quite good, if a bit hard to set up. It has way more than I ever use and seems quite solid.
Yes, the
Splats[self]
thing is odd but seems to work more nicely than updating an array. I imagine odd things can still happen if you nil out one while looping but so far I've not seen a timing issue arise.I look forward to seeing where I go too.
It's certainly fun.
so, i pretty much hate the controls on this game. was thinking about whether i could interpret swirling one or two fingers on the left as a turn, etc. there doesn't seem to be a lot of support for such a thing. ideas? thanks!
A 'largeish' area near the bottom right corner could take a tap for fire, doesn't have to be a small circle. One thumb on the right and the other on the left could be an easy option.
Alternatively you could reduce screen size and place controls in a panel at the bottom.
Then again you could add mouse input with the new iOS features.
@RonJeffries You could do something like this to rotate the ship. Just slide your finger right or left. You can add whatever restrictions you want on it.
@dave1707 thanks, i was thinking about something similar as we had supper, may give that a go.
@Bri_G i guess i could wait for mouse and pad support ...
thanks!
How about a multitouch control? Very short duration touches (taps) fires bullets. For longer touches the start of the touch acts as an anchor and the angle relative to the start controls the angle of the ship. A second touch while this is active would turn on the boosters applying a force at whatever direction the ship was pointing.
I’ve not had a look at the new gestures, which may make things simpler, but I’ve always relied on writing my own touch trackers. Let us know if you want me to share (though appreciate you are looking to figure things out by yourself for the purposes of the blog)
i like that idea of the "fixed" point and rotating around it. skips over the issue of recognizing something like a winding motion. thanks! got a few things to try now ...
Alternatively you could have a pointer from the centre to the edge.
@Bri_G Playing the game, I'm finding that a lot of my trouble is keeping my fingers in the designated areas. The circle idea seems to offer more of that trouble, though maybe I just don't understand the idea.
For now, I'm going to try a simplified version of @West 's idea.
A crucial feature is how you hold your iPad. Do you place it on a flat surface? Hold it in one hand and control with another? Or, hold it on your knee with fingers behind lower corners and thumbs for use on controls. I usually favour the latter.
May be a good idea to generate a range of options to cover most eventualities in future projects.
my original plan was borrowed from my spacewar program, where you laid the ipad down and worked from opposite sides. for asteroids, more often i hold it in one hand on my lap. too many buttons for thumb only, i think.
agreed that there may need to be options. after trying a few this morning (boring article coming soon) i've found nothing i really love. bigger buttons is the next release.
How about something like this?
interesting idea and implementation, use of tables. seems to be just about impossible to fire without turning. my main issue is that the original Asteroids did not have positive angular control, just constant rate of rotation. one of my experiments this morning used a different but equivalent implementation of the touch-hold idea to just trigger constant-rate turning, and i didn't find it very playable. some may disagree. thanks!
How about segmenting the leftmost part of the screen as a giant fire button (say touch.x<width*0.15 then fire). Remainder of screen use the rotation control provided anchor point starts to the left of the fire button. Should get round the turning when you want to fire.
Or here is a slightly different take. Again no constant rate of rotation and you can’t boost and fire at the same time, but I feel it has a pleasing fluidity (YMMV). Again very rough and was written several years ago - I’ve updated the sprite assets to remove the deprecation warning.
@RonJeffries Here's something you can try just for kicks. I added Gravity.x to control the rotation of the ship by tilting the iPad left or right. Just don’t press the Left or Right buttons or comment them out.
PS. Using tilt, the Fire button could be on one side and the Go button on the other.
@west very interesting. use of physics is creative. does have a nice feel. stardust is neat.
... what do the comments in draw mean about executed 3rd, 2nd, 1st?
@dave1707 interesting. i nearly like it. precise control is difficult, but definitely interesting.
ah. i guess i'm used to thinking in the forward direction, years of math and such. i get your point., interesting way of thinking of it.
@Ronjeffries - just loaded v26, nice touches control much better and sound effects really raise the temperature. Sound effects accelerate as asteroids destroyed but when the asteroids have disappeared the sound effects continue. Need a check for level complete. Also, can’t remember original, diary - book trip to YouTube, but are there a number of lives displayed before you are kicked out of space? Something like three ships at the top of the screen disappearing after each blammo!!! ?
@RonJeffries - woaah, just visited youtube. Atari vid, forgot about the alien spaceship. Mods for another day.
Yes new waves are needed, as are the large and small ships. I assume I'll do them in order. The lives are to be shown as a line of ships up by the score. And you win more ships every 10,000 points or something. I don't think I'll ever get there. And other details: missiles fire from the middle of the ship; ship kill radius is too small, and probably other things I've forgotten.
Yes, I do think the sound helps. The version I'll push in a couple of minutes has stereo. All the moving sounds have a stereo effect, which is kind of fun and about the level of complexity I could deal with on days like these.
I may not announce #27 on Twitter, in honor of people who have more important things on their mind, but it should be up within the next few minutes.
@RonJeffries I was playing around with ship controls and I came up with this. Slide your finger up or down (lower 3/4 of the screen) to rotate the ship. Tap Fire to fire missiles. Tap or hold Go for ship acceleration. Tap between Fire and Go to both fire a missile and accelerate. After playing awhile, I was able to zoom around the screen fairly easily and fast, shooting missiles. The buttons could be setup on both sides so it doesn’t matter which hand you want to control rotation and Fire/Go.
that's pretty nice, i'll play a bit and see how it feels!