-
Notifications
You must be signed in to change notification settings - Fork 2
Sprites in Motion
Alban edited this page Aug 15, 2020
·
32 revisions
Lets start with a static scene; the hero at the bottom of the screen.
The invaders are in a line at the top.
(clear-image 0.0 0.0 0.0 1.0)
(load-sprites "images/bg1.jpg" 0)
(load-sprites "images/h1.png" 1)
(load-sprites "images/D-17.png" 20)
(draw-sprite 0 0.0 10.0)
(draw-sprite 1 400.0 460.0)
(for x from 120.0 to 700.0 step 88.0
(draw-scaled-rotated-sprite
20 x 20.0 0.0 0.65) )
(show 1)
That is essentially a picture; there is nothing animated.
We certainly need the hero ship to move from left to right when the player presses a key.
Arranging things into functions helps.
(define load-all-sprites
(lambda ()
(load-sprites "images/bg1.jpg" 0)
(load-sprites "images/h1.png" 1)
(load-sprites "images/D-17.png" 20)))
(define clear-scene
(lambda ()
(clear-image 0.0 0.0 0.0 1.0)
(draw-sprite 0 0.0 10.0))
(define draw-invaders
(lambda (x y)
(for x-pos from x1 to 700.0 step 88.0
(draw-scaled-rotated-sprite
20 x-pos y 0.0 0.65))))
(define draw-hero
(lambda (x)
(draw-sprite 1 x 460.0)))
The same scene is now drawn using the more meaningful functions.
(load-all-sprites)
(clear-scene)
(draw-invaders 120.0 20.0)
(draw-hero 400.0)