From 0ddda2aebe78a943216246a26c86ccad37612338 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 23 Oct 2015 13:08:20 -0400 Subject: [PATCH] Delegate many of the low-level I/O tasks to prospect-gl --- examples/platformer/game.rkt | 60 ++++++------------------------------ 1 file changed, 9 insertions(+), 51 deletions(-) diff --git a/examples/platformer/game.rkt b/examples/platformer/game.rkt index 9e7d845..720862c 100644 --- a/examples/platformer/game.rkt +++ b/examples/platformer/game.rkt @@ -1,19 +1,18 @@ #lang prospect -(require racket - "./geometry.rkt" - "./periodic_timer.rkt") - +(require racket/set) +(require racket/match) (require prospect/drivers/timer) (require plot/utils) ;; for vector utilities +(require prospect-gl/2d) #| Layers: -- External Events - key press/release (interrupts from the outside world) - timer events (as per system timer driver) +- External I/O + as arranged by prospect-gl/2d + including keyboard events, interface to rendering, and frame timing - Ground corresponds to computer itself @@ -39,55 +38,14 @@ A Point is a (vector Number Number) ## Ground Layer Protocols - - Rendering - - assertion: Sprite + - Scene Management - assertion: ScrollOffset - - assertion: ScreenSize - - role: Renderer - Responds to FrameDescription by drawing the current set of Sprites, - adjusted via the current ScrollOffset, in a window sized by ScreenSize. - - - Keyboard State - - message: KeyStateChangeEvent (external event) - - assertion: KeyDown - - role: KeyboardIntegrator - Receives KeyStateChangeEvent from outer space, summing them to - maintain collections of KeyDown assertions. - - - Timer - (standard system driver & protocol) - - - Frame Counting - - message: FrameDescription - - role: FrameCounter - Arranges for, and responds to, system timer events, issuing - FrameDescriptions at regular intervals (a constant compiled-in - frames-per-second value). - -A Sprite is a (sprite (Nat -> Pict) Number Number Nat) -where sprite-renderer produces a pict, given a frame number - sprite-x is the X coordinate in world coordinates for sprite's top-left - sprite-y is the Y coordinate in world coordinates for sprite's top-left - sprite-layer is the layer number for the sprite, more negative for closer - to the camera. + - role: SceneManager + Displays the scene backdrop and adjusts display coordinates via ScrollOffset. A ScrollOffset is a (scroll-offset Vec), indicating the vector to *subtract* from world coordinates to get device coordinates. -The coordinate systems: - World coordinates = the large virtual canvas, origin at top-left, - x increases right and y increases down - Device coordinates = the window's coordinates, mapped to world coords - via scroll offset & clipping - In both, layer numbers are more positive further away from the camera. - -A KeyDown is a (key-down KeyEvent), an assertion indicating that the -named key is currently being held down. - -A FrameDescription is a (frame Nat), a message (!) -indicating a boundary between frames; that is, that frame number frame-number -is just about to begin. - ## Game Layer Protocols - Scoring