\input texinfo @c -*-texinfo-*- @c %**start of header @setfilename chickadee.info @settitle The Chickadee Game Toolkit @c %**end of header @copying Copyright @copyright{} 2017-2020 David Thompson @email{davet@@gnu.org} @quotation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License''. A copy of the license is also available from the Free Software Foundation Web site at @url{http://www.gnu.org/licenses/fdl.html}. @end quotation @dircategory The Algorithmic Language Scheme @direntry * Chickadee: (chickadee). Game programming toolkit for Guile. @end direntry The document was typeset with @uref{http://www.texinfo.org/, GNU Texinfo}. @end copying @titlepage @title Chickadee 0.1 @subtitle Using the Chickadee game toolkit @author David Thompson @page @vskip 0pt plus 1filll @insertcopying @end titlepage @c Output the table of the contents at the beginning. @contents @ifnottex @node Top @top Chickadee @insertcopying @end ifnottex @c Generate the nodes for this menu with `C-c C-u C-m'. @menu * Installation:: Installing Chickadee. * Getting Started:: Writing your first Chickadee program. * Command Line Interface:: Run Chickadee programs from the terminal. * API Reference:: Chickadee API reference. * Copying This Manual:: The GNU Free Documentation License and you! * Index:: @end menu @c Update all node entries with `C-c C-u C-n'. @c Insert new nodes with `C-c C-c n'. @node Installation @chapter Installation Chickadee is available for download from its website at @url{dthompson.us/projects/chickadee.html}. This section describes the software requirements of Chickadee, as well as how to install it. The build procedure for Chickadee is the same as for GNU software packages, and is not covered here. Please see the files @file{README} and @file{INSTALL} for additional details. @menu * Requirements:: Software needed to build and run Chickadee. @end menu @node Requirements @section Requirements Chickadee depends on the following packages: @itemize @item @url{https://gnu.org/software/guile, GNU Guile}, version 3.0.0 or later; @item @url{https://gnu.org/software/guile-opengl, GNU guile-opengl}, version 0.1 or later. @item @url{https://dthompson.us/pages/software/guile-sdl2.html, guile-sdl2}, version 0.7.0 or later; @item libfreetype @item libmpg123 @item libopenal @item libreadline @item libvorbisfile @end itemize @node Getting Started @chapter Getting Started One of the simplest programs we can make with Chickadee is rendering the text ``Hello, world'' on screen. Here's what that looks like: @example (define (draw alpha) (draw-text "Hello, world!" (vec2 64.0 240.0))) @end example The @code{draw} procedure is called frequently to draw the game scene. For the sake of simplicity, we will ignore the @code{alpha} variable in this tutorial. To run this program, we'll use the @command{chickadee play} command: @example chickadee play hello.scm @end example This is a good start, but it's boring. Let's make the text move! @example (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)))) @end example The @code{vec2} type is used to store 2D coordinates (@pxref{Vectors}.) A variable named @code{position} contains the position where the text should be rendered. A new hook called @code{update} has been added to handle the animation. This hook is called frequently to update the state of the game. The variable @code{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. @example (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)))) @end example This final example uses Chickadee's scripting features (@pxref{Scripting}) to bounce the text between the edges of the window indefinitely using the handy @code{tween} procedure. The only thing the @code{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! @node Command Line Interface @chapter Command Line Interface While Chickadee is a library at heart, it also comes with a command line utility to make it easier to get started. @menu * Invoking chickadee play:: Run Chickadee programs @end menu @node Invoking chickadee play @section Invoking @command{chickadee play} The @command{chickadee play} command is used to open a window and run the Chickadee game contained within a Scheme source file. @example chickadee play the-legend-of-emacs.scm @end example In this file, special procedures may be defined to handle various events from the game loop: @itemize @item load-game @item quit-game @item draw @item update @item key-press @item key-release @item text-input @item mouse-press @item mouse-release @item mouse-move @item mouse-wheel @item controller-add @item controller-remove @item controller-press @item controller-release @item controller-move @end itemize See @ref{The Game Loop} for complete information on all of these hooks, such as the arguments that each procedure receives. In additional to evaluating the specified source file, the directory containing that file is added to Guile's load path so that games can easily be divided into many different files. Furthermore, that directory is entered prior to evaluating the file so that data files (images, sounds, etc.) can be loaded relative to the main source file, regardless of what the current directory was when @command{chickadee play} was invoked. Many aspects of the initial game window and environment can be controlled via the following options: @table @code @item --title=@var{title} @itemx -t @var{title} Set the window title to @var{title}. @item --width=@var{width} @itemx -w @var{width} Set the window width to @var{width} pixels. @item --height=@var{height} @itemx -h @var{height} Set the window height to @var{height} pixels. @item --fullscreen @itemx -f Open window in fullscreen mode. @item --resizable @itemx -r Make window resizable. @item --update-hz=@var{n} @itemx -u @var{n} Update the game @var{n} times per second. @item --repl Launch a REPL in the terminal. This will allow the game environment to debugged and modified without having to stop and restart the game after each change. @item --repl-server[=@var{port}] Launch a REPL server on port @var{port}, or 37146 by default. Especially useful when paired with the @url{https://www.nongnu.org/geiser/, Geiser} extension for Emacs. @end table @node API Reference @chapter API Reference @include api.texi @node Copying This Manual @appendix Copying This Manual @menu * GNU Free Documentation License:: License for copying this manual. @end menu @c Get fdl.texi from http://www.gnu.org/licenses/fdl.html @node GNU Free Documentation License @section GNU Free Documentation License @include fdl.texi @node Index @unnumbered Index @syncodeindex tp fn @syncodeindex vr fn @printindex fn @bye @c chickadee.texi ends here