Skip to content

Commit

Permalink
Added hide-mouse, show-mouse, and defender example.
Browse files Browse the repository at this point in the history
  • Loading branch information
massung committed Feb 13, 2020
1 parent 6bbd6f3 commit 95f34c3
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 40 deletions.
1 change: 1 addition & 0 deletions draw.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All rights reserved.

;; ----------------------------------------------------

(require "input.rkt")
(require "video.rkt")
(require "palette.rkt")
(require "font.rkt")
Expand Down
77 changes: 40 additions & 37 deletions examples/defender.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(define city-sprite '(#x20 #x68 #xed #xff #xff))
(define destroyed-sprite '(#x00 #x00 #x00 #x91 #xd3))
(define silo-sprite '(#x40 #x40 #x40 #xe0 #xa0))
(define redicule-sprite '(#x20 #x20 #xf8 #x20 #x20))
(define redicule-sprite '(#x20 #x20 #xd8 #x20 #x20))
(define target-sprite '(#x88 #x50 #x20 #x50 #x88))

;; ----------------------------------------------------
Expand Down Expand Up @@ -398,46 +398,49 @@

;; ----------------------------------------------------

(define (new-game)
(setup)

(λ ()
(cls)

; new wave?
(when (and (null? enemy-missiles)
(null? enemy-explosions)
(null? player-missiles)
(null? player-explosions))
(if (zero? (cities-left))
(game-over)
(next-wave)))

; world
(draw-ground)
(draw-cities)
(draw-silos)
(draw-missiles)
(draw-explosions)
(draw-score)

; player
(color 7)
(draw (- (mouse-x) 2) (- (mouse-y) 2) redicule-sprite)
(define (game-loop)
(cls)

; new wave?
(when (and (null? enemy-missiles)
(null? enemy-explosions)
(null? player-missiles)
(null? player-explosions))
(if (zero? (cities-left))
(game-over)
(next-wave)))

; world
(draw-ground)
(draw-cities)
(draw-silos)
(draw-missiles)
(draw-explosions)
(draw-score)

; player
(color 7)
(draw (- (mouse-x) 2) (- (mouse-y) 2) redicule-sprite)

; update
(advance-missiles)
(advance-explosions)
; update
(advance-missiles)
(advance-explosions)

; controls
(when (and (launch-btn) (not (null? enemy-missiles)))
(launch-player-missile))

; controls
(when (and (launch-btn) (not (null? enemy-missiles)))
(launch-player-missile))
; quit game?
(when (btn-quit)
(quit)))

; quit game?
(when (btn-quit)
(quit))))
;; ----------------------------------------------------

(define (new-game)
(hide-mouse)
(setup))

;; ----------------------------------------------------

(define (play)
(run (new-game) 160 128 #:title "R-cade: Defender"))
(run game-loop 160 128 #:init new-game #:title "R-cade: Defender"))
2 changes: 1 addition & 1 deletion game.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ All rights reserved.
(when w
(sfRenderWindow_close w)))
#:at-exit? #t)])

; optionally allow for an init function
(when init
(init))
Expand Down
2 changes: 1 addition & 1 deletion input.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ All rights reserved.
(btn-select)
(btn-quit)
(btn-z)
(btn-x)))
(btn-x)))

;; ----------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ All rights reserved.
btn-mouse
mouse-x
mouse-y
hide-mouse
show-mouse

; draw
cls
Expand Down
10 changes: 9 additions & 1 deletion scribblings/r-cade.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The @racket[game-loop] parameter is a function you provide, which will be called

The @racket[width] and @racket[height] parameters define the size of video memory (not the size of the window!).

The @racket[init] procedure - if provided - is called before the @racket[game-loop] starts.
The @racket[init] procedure - if provided - is called before the @racket[game-loop] starts. If you have initialization or setup code that requires R-cade state be initialized, this is where you can safely do it.

The @racket[scale-factor] parameter will determine the initial size of the window. The default will let auto pick a scale factor that is appropriate given the size of the display.

Expand Down Expand Up @@ -144,6 +144,14 @@ This function isn't really used much outside of @racket[wait].
@defproc[(mouse-y) exact-nonnegative-integer?]{Returns the Y pixel (in VRAM) that the mouse is over. @tt{0} is the top edge.}


@;; ----------------------------------------------------
@defproc[(hide-mouse) void?]{Hides the mouse cursor while over the window.}


@;; ----------------------------------------------------
@defproc[(show-mouse) void?]{Shows the mouse cursor while over the window.}


@;; ----------------------------------------------------
@section{Action Bindings}

Expand Down
12 changes: 12 additions & 0 deletions video.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All rights reserved.
|#

(require csfml)
(require racket/match)

;; ----------------------------------------------------

Expand All @@ -35,6 +36,16 @@ All rights reserved.

;; ----------------------------------------------------

(define (hide-mouse)
(sfRenderWindow_setMouseCursorVisible (window) #f))

;; ----------------------------------------------------

(define (show-mouse)
(sfRenderWindow_setMouseCursorVisible (window) #t))

;; ----------------------------------------------------

(define (resize event)
(let ([view (sfRenderWindow_getView (window))]

Expand Down Expand Up @@ -86,4 +97,5 @@ All rights reserved.
; redraw the window
(sfRenderWindow_clear (window) bg)
(sfRenderWindow_drawSprite (window) (sprite) (render-state))

(sfRenderWindow_display (window)))

0 comments on commit 95f34c3

Please sign in to comment.