From 733b69847aee2e5df44d007c7f8c817e066fde2f Mon Sep 17 00:00:00 2001 From: Gene Pasquet Date: Sat, 18 May 2024 11:20:16 +0100 Subject: Draw the road --- .gitignore | 49 ++++ cars_racer.png | Bin 21598 -> 0 bytes cars_racer.svg | 848 --------------------------------------------------------- red_racer.png | Bin 4924 -> 0 bytes road.png | Bin 0 -> 2114 bytes turbo.scm | 46 +++- vehicles.png | Bin 0 -> 28850 bytes 7 files changed, 89 insertions(+), 854 deletions(-) create mode 100644 .gitignore delete mode 100644 cars_racer.png delete mode 100644 cars_racer.svg delete mode 100644 red_racer.png create mode 100644 road.png create mode 100644 vehicles.png diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a4cbb7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,49 @@ +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + +# network security +/network-security.data +*.kra \ No newline at end of file diff --git a/cars_racer.png b/cars_racer.png deleted file mode 100644 index 71f81c8..0000000 Binary files a/cars_racer.png and /dev/null differ diff --git a/cars_racer.svg b/cars_racer.svg deleted file mode 100644 index d1b3e56..0000000 --- a/cars_racer.svg +++ /dev/null @@ -1,848 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/red_racer.png b/red_racer.png deleted file mode 100644 index 040f983..0000000 Binary files a/red_racer.png and /dev/null differ diff --git a/road.png b/road.png new file mode 100644 index 0000000..90f0446 Binary files /dev/null and b/road.png differ diff --git a/turbo.scm b/turbo.scm index 32661b5..783160f 100644 --- a/turbo.scm +++ b/turbo.scm @@ -2,14 +2,48 @@ (chickadee) (chickadee graphics viewport)) -(define red-car (load-image "red_racer.png")) +(define lane-height 65) +(define lane-length 200) +(define road (load-tileset "road.png" lane-length lane-height)) +(define road-top (texture-atlas-ref road 2)) +(define road-bottom (texture-atlas-ref road 0)) +(define road-lane (texture-atlas-ref road 1)) -(define car-pos-y 0.0) +(define (draw-lanes startx starty num-lanes) + (if (> num-lanes 0) + (begin + (draw-sprite road-lane (vec2 startx starty)) + (draw-lanes startx (+ lane-height starty) (- num-lanes 1))))) + +(define (draw-road-section startx starty num-lanes) + (draw-sprite road-bottom (vec2 startx starty)) + (draw-lanes startx (+ lane-height starty) (- num-lanes 2)) + (draw-sprite road-top (vec2 startx (+ starty (* lane-height (- num-lanes 1)))))) + +(define (draw-road startx starty num-lanes) + (if (< startx (window-width (current-window))) + (begin + (draw-road-section startx starty num-lanes) + (draw-road (+ startx lane-length) starty num-lanes)))) + +(define vehicles (load-tileset "vehicles.png" 100 45)) +(define the-car (texture-atlas-ref vehicles 0)) +(define car-ref 0) + +(define car-pos-x 0.0) (define car-speed 4.0) (define (draw alpha) - (draw-sprite red-car (vec2 0 car-pos-y)) + ; Draw the road + (draw-road 0 90 5) + + + (draw-sprite (texture-atlas-ref vehicles car-ref) (vec2 car-pos-x 100)) (draw-text "Turbo racers!" (vec2 260.0 240.0)) - (set! car-pos-y (+ car-speed car-pos-y)) - (if (> car-pos-y (window-height (current-window))) - (set! car-pos-y 0.0))) + (set! car-pos-x (+ car-speed car-pos-x)) + (if (> car-pos-x (window-width (current-window))) + (begin + (set! car-pos-x 0.0) + (if (= car-ref 8) + (set! car-ref 0) + (set! car-ref (+ 1 car-ref)))))) diff --git a/vehicles.png b/vehicles.png new file mode 100644 index 0000000..ddbd197 Binary files /dev/null and b/vehicles.png differ -- cgit v1.2.3