This revision makes some deep changes to the carcode structure, which includes rendering and event handling, this in order to accommodate later features such as scripting.
Current state, sound works, the car moves as with original code, there is now a working tracer line.
Rendering
Initialization, mainloop and event dispatching are now handled by the CarcodeApp class, this creates the main window surface and an instance of Arena which handles rendering.
I rewrote the arena code, we now use two surfaces, one for the background (unused still) and other for the tracer, the rendering loop goes more or less like this:
- Clean the background
- Draw all entities of the arena, not including the car
- Draw the tracer surface
- Draw the car
The arena code handles the tracer too, it first gets the current position of the car, then tells the car to self update and draw, then we get the new position, we do a few checks in order to not draw lines across the screen when the car passes from side to side, and the just draw a line from original position to new one.
Event Handling
The new CarcodeApp class handles all initialization and event handling work, we use a dictionary of Key Codes and Functions to handle keyboard input, just like old Arena code, but we use the function add_key to hook new functions.
No hay comentarios:
Publicar un comentario