Because some times, I just don't have anything better to do

Re-coding the cats

Interpreted BASIC, in a 25 year old computer, is not fast. That is a fact.

Trying to improve the animation speed and reduce flicker, I did something I have never tried before. A look-up table of sorts.

The idea is simple. Calculate all the points in the cat’s trajectory while it jumps, and store them in a matrix. Then, animate the jump reading the graphic’s position from that matrix instead of calculate it while drawing the animation.

But I found two not totally unexpected problems.

  1. The calculations took about 5 seconds. During that time, the game had an ugly pause in the action.
  2. I found out that most of the flicker is actually because of the time it takes for BASIC to draw the graphics in the screen. Having no delay between the command that deletes the cat’s old position, and the one that draws the new one did actually create a flicker that was in some aspects nastier than before.

So, back to the old code.

The good thing is that it was not hard to implement at all, and I’m sure I will find another chance to use it.

Advertisements

5 responses

  1. L. Curtis Boyle

    It’s too late (as far as the programming contest goes), but how did you animate the cats? Did you HPUT the cat image, then HPUT a blank image, and HPUT the cat image again in a new position? If so, one trick I used to use is to HGET a larger box around the graphic I was going to be moving (if you know it can only go in certain directions, only HGET extra space on the sides that it is moving away from), and then just do HPUT’s of the image itself (taking care not to move it more than the # of extra pixels you grabbed). Advantages: Faster animation, and cleans up after itself automatically. Disadvantage: If you need to HPUT the graphic right beside other graphics (on the side(s) that have the extra blank space), then you may need to HGET a 2nd version of just the graphic itself for that special case.

    28 April, 2013 at 00:30

    • I did that in some of my games. but not in this one.
      I’m actually drawing a filled box with the background color, updating the cat’s position, and then PUTting the cat.
      The game is not really finished yet. I have plans to add some background graphics and better sounds, so I will try that trick and see how it goes. I’ve got to see what happens when the cats are close to the walls.

      Oh, and thanks for playing and the feedback 🙂

      29 April, 2013 at 00:01

      • L. Curtis Boyle

        One thing you could change is the cat dropping routine (when you initially “launch” that cat. In that particular case, you have blank the old position out, play a sound, and then HPUT the new one. Move the sound to after the HPUT, and it will animate with far less flicker (tried that here on a copy of it).

        26 May, 2013 at 14:34

      • You are right!
        I don’t know why I missed that. I’ve just uploaded the corrected version.
        Thanks!

        1 June, 2013 at 23:56

  2. Hola Diego,

    Sobre el tema del parpadeo (flickering), es posible que se solucione dibujando todo lo que tengas que dibujar en un buffer secundario del tamaño de la pantalla, y cuando está listo el buffer, volcarlo de un solo golpe al buffer de video. No sé si esto es necesario en la máquina con la que estás trabajando pero recuerdo que con una 286/386 en modo VGA 320×200 era la forma que había para que no parpadeara. Si uno dibujaba directo al buffer de video, pasaba lo del parpadeo.

    Un saludo, y suerte, Hernán!

    5 June, 2013 at 08:25

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s