Jump to content

Recent Comments

- - - - -

Another try with HTDP 2nd Edition

4: Adsense


(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.

Jan 08 2012 08:42 PM
Well after going on Stack Overflow I found my answer. Also got a good reminder about how this not C#/VB.net. No mutations, no side-effects. Writing expressions in Scheme is somewhat simiilar to writing string expressions in C++, C#, and VB.Net. From my understanding, strings in those languages are immutable. So if you change part of the string or assign a different string, you're actually calling a brand new string variable everytime.

Note: GameDev.net moderates comments.