Jump to content

  • Log In with Google      Sign In   
  • Create Account

Beginnings of the Wayward Programmer

Another try with HTDP 2nd Edition

Posted by , in Scheme 08 January 2012 - - - - - - · 1,484 views


(define BOARDWIDTH 200)
(define BOARDHEIGHT 200)
(define BOARDBKGR "blue")
(define ROCKET .)
(define UFO (overlay (circle 10 "solid" "red")
				   (rectangle 40 4 "solid" "green")))
(define FLATBED (rectangle 60 10 "outline" "black"))
(define (SPACESHIP option)
	[(= option 1) ROCKET]
	[(= option 2) UFO]))
(define V 10) ;Velocity
(define A 1)  ;Acceleration
(define (distance t)  ;t = Time
  (- (* V t) (* 1/2 A (sqr t))))
(define SPACESHIP-BOTTOM (- BOARDHEIGHT (/ (image-height SHOWNSHIP) 2)))
(define (render-shownship x y)
  (place-image SHOWNSHIP x y GAMEBOARD))
(define (create-rocket-scene.v7 t)
	[(<= (distance t) SPACESHIP-BOTTOM)
	 (render-shownship STARTPOSITION (distance t))]
	[(> (distance t) SPACESHIP-BOTTOM)

This code is based off of Chapter 1 of HTDP. I've gotten this far and it wasn't as bad as last time. And it's been 5 years (I can't believe it) since I've touched this language. The only issues I have really are two things.
  • I couldn't find a way to do one of the suggestions. Which was: How would change the program so that the rocket lands on a flat rock bed that is 10 pixels higher than the bottom of the scene? Don’t forget to change the scenery, too. When I tried adding another function call to render-shownship, I kept getting an error.
  • The spaceship goes down to the bottom of the screen, then accelerates up the screen. I'm a bit lost on why that is.

Outside of those two things. I'm quite happy with my progress. I've thankfully gotten over the prefix issue as well, lol.

Recent Comments