🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Another try with HTDP 2nd Edition

Published January 08, 2012
Advertisement
http://www.ccs.neu.e...e/prologue.html


(define BOARDWIDTH 200)
(define BOARDHEIGHT 200)
(define STARTPOSITION 50)
(define BOARDBKGR "blue")
(define GAMEBOARD (empty-scene BOARDWIDTH BOARDHEIGHT BOARDBKGR))
(define ROCKET .)
(define UFO (overlay (circle 10 "solid" "red")
(rectangle 40 4 "solid" "green")))
(define FLATBED (rectangle 60 10 "outline" "black"))
(define (SPACESHIP option)
(cond
[(= option 1) ROCKET]
[(= option 2) UFO]))
(define SHOWNSHIP (SPACESHIP 1))
(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)
(cond
[(<= (distance t) SPACESHIP-BOTTOM)
(render-shownship STARTPOSITION (distance t))]
[(> (distance t) SPACESHIP-BOTTOM)
(render-shownship STARTPOSITION 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.

  1. 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.
  2. 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.
0 likes 1 comments

Comments

Alpha_ProgDes
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.
January 09, 2012 02:42 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement