/[corman-sdl]/corman-sdl/examples/random-rectangles_5.lisp
ViewVC logotype

Contents of /corman-sdl/examples/random-rectangles_5.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Fri Jul 2 09:25:31 2004 UTC (9 years, 9 months ago) by lcrook
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +8 -7 lines
*** empty log message ***
1 ;;; A random rectangle example.
2 ;;; Blits rectangles of random size to random positions on the screen
3 ;;; Original work: "The Simple Direct Media Layer", Ernest S. Pazera
4 ;;; ( http://www.gamedev.net/reference/programming/features/sdl2/page5.asp )
5 ;;; Conversion by Luke J Crook, luke@balooga.com
6 ;;; Version 0.1, 08 June, 2003
7 ;;; Version 0.2, 01 February, 2004
8 ;;; Version 0.4, 02 April, 2004
9
10 (require :mp)
11 (require 'sdl)
12 (require 'sdl-util)
13 (in-package :win)
14
15 (defun random-rects ()
16 (let (
17 (width 640) (height 480) (screen-flags (list sdl:SDL_SWSURFACE))
18 (rectangle (sdl:new-rect)))
19
20 ;Initialize Systems
21 ;(documentation 'sdl:with-init 'function) for a description of how to use it.
22 ;sdl:with-init will initialize the SDL library and
23 ;automatically call sdl:SDL_Quit upon exit (or if something goes wrong in the body).
24 (sdl:with-init (sdl:SDL_INIT_VIDEO)
25
26 ;Create the display window
27 ;Use (sdl:display-surface) to retrieve the surface created by (sdl:set-videomode)
28 (unless (sdl:set-videomode width height :flags screen-flags)
29 (fformat "FAILED: set-videomode, cannot set the video mode")
30 (return))
31
32 ;Main SDL loop / Message Pump
33 ;(documentation 'sdl:with-events 'function) for a description of how to use it.
34 (sdl:with-events
35 (:quit t)
36 (:keydown (state scancode key mod unicode)
37 (when (= key sdl:SDLK_ESCAPE)
38 (sdl:push-quitevent)))
39 (:idle
40 ;Set up the random rectangle
41 (ct:with-c-struct (x rectangle sdl:sdl_rect)
42 (setf
43 sdl::x (random width)
44 sdl::y (random height)
45 sdl::w (random (- width sdl::x))
46 sdl::h (random (- height sdl::y))))
47
48 ;'Render' the rectangle to the display by:
49 ;Filling the display with a random color,
50 ;using the [x,y,w,h] of the rectangle as a template
51 (sdl:fill-display :r (random 256) :g (random 256) :b (random 256) :template rectangle)
52
53 ;Use sdl:flip or sdl:update-display to update the screen.
54 ; Here, sdl:flip updates the entire display whereas
55 ; sdl:update-display updates only that portion of the display that has been modified.
56 ; sdl:update-display is therefore much faster.
57
58 ;(sdl:Flip)
59
60 (sdl:update-display :template rectangle)))
61
62 ;sdl:init-success will check to see if sdl:with-init was initialized correctly.
63 (unless (sdl:init-success)
64 (fformat "ERROR: sdl:with-init FAILED to initialize")))))
65
66 ;;; Run the example using...
67 ;;; (setf rects (mp:process-run-function "random-rects" #'random-rects))
68 ;;; (mp:proc)
69
70 ;;; Build the exe using...
71 ;;; (SAVE-APPLICATION "random-rects.exe" 'random-rects :static t)

  ViewVC Help
Powered by ViewVC 1.1.5