Skip to content

Commit

Permalink
use runtime-path for images directory
Browse files Browse the repository at this point in the history
  • Loading branch information
david-vanderson committed Aug 10, 2018
1 parent 0d52892 commit 596494d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 37 deletions.
8 changes: 4 additions & 4 deletions client.rkt
Expand Up @@ -1094,14 +1094,14 @@
(send dc set-brush b))
2 2) "black"))

(add-sprite!/value sd 'intro (read-bitmap "images/intro.png" 'png/alpha))
(add-sprite!/value sd 'intro (read-bitmap (build-path IMAGEDIR "intro.png") 'png/alpha))
)
(define textfont (load-font! sd #:size TEXTH #:face "Verdana" #:family 'modern))
(load-ships sd)
(load-ships! sd)
(plasma-setup-pre! sd)
(explosion-setup-pre! sd)
(add-sprite!/file sd 'missile (string-append "images/missile.png"))
(add-sprite!/file sd 'cannonball (string-append "images/asteroid_43.png"))
(add-sprite!/file sd 'missile (build-path IMAGEDIR "missile.png"))
(add-sprite!/file sd 'cannonball (build-path IMAGEDIR "asteroid_43.png"))

(define csd (compile-sprite-db sd #:padding 2))
;(save-csd! csd "csd" #:debug? #t)
Expand Down
5 changes: 4 additions & 1 deletion defs.rkt
@@ -1,11 +1,14 @@
#lang racket/base

(require racket/math)
(require racket/math
racket/runtime-path)

(provide (all-defined-out))

(define VERSION 1) ; client will bomb if version doesn't match server

(define-runtime-path IMAGEDIR "images")

(define DEBUG #f)
(define COMPRESS #t)
(define PORT 22381)
Expand Down
2 changes: 1 addition & 1 deletion plasma.rkt
Expand Up @@ -14,7 +14,7 @@
(define PLASMA_FADE 2.0) ; energy loss per second after PLASMA_LIFE

(define (plasma-setup-pre! sd)
(add-sprite!/file sd 'plasma (string-append "images/plasma.png")))
(add-sprite!/file sd 'plasma (build-path IMAGEDIR "plasma.png")))

(define PLASMA_SPRITE_IDX #f)
(define PLASMA_SPRITE_SIZE #f)
Expand Down
60 changes: 29 additions & 31 deletions ships.rkt
Expand Up @@ -51,43 +51,41 @@
(set! size 10.0)))
(values name (ship-info filename size #f '()))))


(define (engine-filename base i k (ext ".png"))
(string-append base "-e" (number->string i) (number->string k) ext))

(for (((name si) (in-hash ship-list)))
(define basename (string-append "images/" (ship-info-filename si)))
(define bm (read-bitmap (string-append basename ".png") 'png/alpha))
(set-ship-info-bm! si bm)
(when (not (ship-info-size si))
(set-ship-info-size! si (max (send bm get-width) (send bm get-height))))
(for ((i (in-naturals 1)))
#:break (not (file-exists? (engine-filename basename i 1)))
(set-ship-info-engine-bms! si
(append (ship-info-engine-bms si) (list (list))))
(for ((k (in-naturals 1)))
(define filename (engine-filename basename i k))
#:break (not (file-exists? filename))
(define bm (read-bitmap filename 'png/alpha))
(set-ship-info-engine-bms! si
(for/list ((bms (ship-info-engine-bms si))
(z (in-naturals 1)))
(if (equal? i z)
(append bms (list bm))
bms))))))

(define (load-ships sd)
(define (engine-path base i k (ext ".png"))
(build-path IMAGEDIR (engine-filename base i k ext)))


(define (load-ships! sd)
(for (((name si) (in-hash ship-list)))
(define sym (string->symbol name))
(add-sprite!/value sd sym (ship-info-bm si))
(define basename (ship-info-filename si))
(define bm (read-bitmap (build-path IMAGEDIR (string-append basename ".png")) 'png/alpha))
(add-sprite!/value sd sym bm)
(set-ship-info-bm! si sym)
(set-ship-info-engine-bms! si
(for/list ((engine-bms (ship-info-engine-bms si))
(i (in-naturals 1)))
(for/list ((bm engine-bms)
(k (in-naturals 1)))
(define sym (string->symbol (engine-filename name i k "")))
(add-sprite!/value sd sym bm)
sym)))))
(when (not (ship-info-size si))
(set-ship-info-size! si (max (send bm get-width) (send bm get-height))))

(for ((i (in-naturals 1)))
#:break (not (file-exists? (engine-path basename i 1)))
; i goes over different sized engine animations
(set-ship-info-engine-bms! si (append (ship-info-engine-bms si) (list (list))))
(for ((k (in-naturals 1)))
; k goes over the frames of a single animation
(define filename (engine-path basename i k))
#:break (not (file-exists? filename))
(define bm (read-bitmap filename 'png/alpha))
(define sym (string->symbol (engine-filename name i k "")))
(add-sprite!/value sd sym bm)
(set-ship-info-engine-bms! si
(for/list ((bms (ship-info-engine-bms si))
(z (in-naturals 1)))
(if (equal? i z)
(append bms (list sym))
bms)))))))


(define (make-spacesuit name ship)
Expand Down

0 comments on commit 596494d

Please sign in to comment.