Action games and demos (Chapter 9)

classic Classic list List threaded Threaded
17 messages Options
gav
Reply | Threaded
Open this post in threaded view
|

Action games and demos (Chapter 9)

gav
I was so taken by the game project of Chapter 9 that I created several applications that fit the criteria. i.e. pure Jack using the TECS compiler and VMEmulator with the built-in implementations of OS functions (for speed).

My goal was to exploit the provided architecture to produce high performance, visually interesting graphical output.

Youtube videos:
GASteroids (asteroids-like) game
Boing Ball and Sinus Scroller demo
Real-time Plasma and Rotozoom demo

I am happy to discuss the techniques I used if people are interested.
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

Dano
Nice job! I would love to see the source code of Boing Ball :)
gav
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

gav
Although I am not precious about the source code, it would appear contrary to the spirit of the course to release it. The reason I started this thread was to discuss how these effects are achieved, and give others an incentive to experiment.

The Boing Ball demo was actually the easiest of the lot to do. While looking for inspiration in low-end computer hardware demos, I came across this one for the Sinclair ZX81. (Note the bouncing ball effect at 1:30) :
http://www.youtube.com/watch?v=sKj6TaADFWo

The change in direction of the ball's rotation on rebounding was the give away on how to achieve this effect cheaply. The original Amiga Boing Ball demo (Seek to 0:30 here: http://www.youtube.com/watch?v=-ga41edXw3A) used palette cycling to give the impression of rotation, we don't have that option on the Hack machine. I had already done significant experimentation with bitmap animations on Hack (I should round up the looping clips I have and post them to youtube sometime). The solution was to blit a sequence of pre-shifted bitmaps to screen giving the illusion of rotation AND horizontal movement. On rebounding, the sequence is simply reversed, changing the direction of rotation and horizontal motion.

Pre-calculation of expensive arithmetic is key to high performance animation. Copying a 16-bit word (16 consecutive pixels) to screen memory is cheap, calculating a bit shift for the next animation frame would be very expensive. I started with eight frames of the Boing Ball rotating, rendered with Blender:
First Boing Ball frame of eight in sequence.
The frames were scaled, cropped, quantised to two colours, shifted by two pixels, and padded to an image that was a multiple of 16 pixels in width (using Gimp). This GIF shows the eight frames played back in sequence. Note that each frame is the same size, overlaid on the previous, in the same location! Only the contents of each frame gives the illusion of motion:
Eight Boing Ball frames played back in sequence.
Each frame was saved out, and converted into a Jack object via a Python script.

When playing back, the eight frames are blitted to the same location in screen memory. On completion of the eighth frame, the memory location is incremented by one word, and the sequence is repeated. The sequence was designed with enough background coloured border to ensure that the consecutive blitted frame would erase the trail of the previous, so no flickering occurs from blanking (at least for horizontal motion).

The vertical motion of the ball is from a pre-calculated sine table. There is also some blanking required to erase the remainder of the previous frame above (or below) the current one.

Separately I was working on the Sinus Scroller, and later combined the two when I found that they both had enough CPU headroom. I can cover the Sinus Scroller another time if people are interested.

Cheers.
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

Dano
Fair enough, I don't need to see the source code if there is detailed explanation like this :) Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

DapperMan
In reply to this post by gav
Hey so i am working on sort of shooter game, like your asteroids game, and im able to get my player object to move and shoot, and im able to get an "enemy" object to move on the screen as well, however when i try to implement both my player and enemy objects, the movements all of a sudden extremely slow down. How did you get your asteroid objects and your player objects to move so smoothly and fast at the same time?
gav
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

gav
Congratulations on getting your objects moving and shooting, I think that's probably the hardest part!

DapperMan wrote
How did you get your asteroid objects and your player objects to move so smoothly and fast at the same time?
I optimised the code to make the most out of what the machine did well and minimise what it did poorly.

That answer probably doesn't help you resolve your own performance problems, but you didn't offer any details of your own analysis into the problem. You need to look at your code and work out some way to profile it, identifying the areas that are "slow".

So here's some questions that you could ask yourself that might help:

- What do I mean by slow ? (Without qualification this could mean anything)

- Am I getting enough frames per second (fps) ? (approximately 10 or more would be good)

- Are the calculations or the rendering taking the longest amount of time ? (Minimise/trivialise one or the other to work it out)

- Am I performing calculations during rendering, or while the previous frame is being displayed ?

- Have I minimised the time between blanking the old frame/objects and rendering the new ?

- Could my calculations be faster with a pre-calculated look up table ?

- What's the fastest rendering method ? (Built in maths and drawing routines are faster than writing your own)

And the final one:

- Did I leave a sleep in there somewhere ? (You probably want one to control the overall game speed, any more and you're doing animation all wrong)

I hope that helps you get the answers you are looking for.
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

tungsten
In reply to this post by gav
gav wrote
Although I am not precious about the source code, it would appear contrary to the spirit of the course to release it. The reason I started this thread was to discuss how these effects are achieved, and give others an incentive to experiment.
Would you be able to release the binary for the plasma demo?
I'm making a custom version of the Hack computer (deviates from the course) and I'm curious if it would be able to run your demo at a reasonable rate (if at all).
The binary wouldn't be enough to reverse engineer the source code... maybe it would be but for the amount of time it would take I think writing your own code would prove to be a more worthwhile endeavour...
If posting the binary on this public forum is too much, would you be willing to private email me?

Kindest regards
gav
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

gav
tungsten wrote
Would you be able to release the binary for the plasma demo?
It's been a couple of years since I did these and they haven't generated much discussion. I think it's time that I release the source code for these.

I will upload them to github once I add some licensing information.
gav
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

gav
Source code for the Plasma and Rotozoom demo is now on github here:
https://github.com/gav-/Nand2Tetris-Games_and_Demos

I will post the source for others as well at some point.

Please let us know how you go with your emulator.
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

tungsten
Thanks for sharing!
I will post back in a bit on how it goes!
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

tungsten
In reply to this post by gav
I checked out the repo. Seems I won't be able to test the demo just yet.

I have only implemented the first half of the course. As such my emulator only runs binaries or assembly. So I guess this is extra motivation to get working on that VM translator.

=D
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

ybakos
tungsten, you can use the provided VMEmulator to run the programs.
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

tungsten
ybakos, indeed. And it worked flawlessly.
Though, I want to see if it will work on a variation of the Hack hardware I coded in another language.
gav
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

gav
In reply to this post by gav
Source code for the Sinus Text Scroller portion of the "Boing Ball and Sinus Scroller demo" has been uploaded to github here:

https://github.com/gav-/Nand2Tetris-Games_and_Demos
gav
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

gav
Source code for the Bouncing Boing Ball portion of the "Boing Ball and Sinus Scroller demo" has been uploaded to github here:

https://github.com/gav-/Nand2Tetris-Games_and_Demos
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

Peridoot
Hey gav! Is there any chance of you uploading the  GASteroids source code in git hub? I'm very curious to see how it works.
Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Action games and demos (Chapter 9)

Lozminda
In reply to this post by gav
I know this is a long time after, but those are really great !
Lozminda