One of the simplest programs we can make with Chickadee is rendering the text “Hello, world” on screen. Here’s what that looks like:
(define (draw alpha) (draw-text "Hello, world!" (vec2 64.0 240.0)))
draw procedure is called frequently to draw the game scene.
For the sake of simplicity, we will ignore the
in this tutorial.
To run this program, we’ll use the
chickadee play command:
chickadee play hello.scm
This is a good start, but it’s boring. Let’s make the text move!
(define position (vec2 0.0 240.0)) (define (draw alpha) (draw-text "Hello, world!" position)) (define (update dt) (set-vec2-x! position (+ (vec2-x position) (* 100.0 dt))))
vec2 type is used to store 2D coordinates
(see Vectors.) A variable named
position contains the
position where the text should be rendered. A new hook called
update has been added to handle the animation. This hook is
called frequently to update the state of the game. The variable
dt (short for “delta-time”) contains the amount of time that
has passed since the last update, in seconds. Putting it all
together, this update procedure is incrementing the x coordinate of
the position by 100 pixels per second.
This is neat, but after a few seconds the text moves off the screen completely, never to be seen again. It would be better if the text bounced back and forth against the sides of the window.
(define position (vec2 0.0 240.0)) (define (draw alpha) (draw-text "Hello, world!" position)) (define (update dt) (update-agenda dt)) (define (update-x x) (set-vec2-x! position x)) (let ((start 0.0) (end 536.0) (duration 4.0)) (script (while #t (tween duration start end update-x) (tween duration end start update-x))))
This final example uses Chickadee’s scripting features
(see Scripting) to bounce the text between the edges of the window
indefinitely using the handy
tween procedure. The only thing
update procedure needs to do now is advance the clock of
the “agenda” (the thing that runs scripts.) The script takes care
of the rest.
This quick tutorial has hopefully given you a taste of what you can do with Chickadee. The rest of this manual gets into all of the details that were glossed over, and much more. Try rendering a sprite, playing a sound effect, or handling keyboard input. But most importantly: Have fun!