![]() |
![]() |
|
home—lectures—recipe—exams—hws—D2L—breeze (snow day)
Part A, Problems 1,2: due Oct 14 (Tue) 23:59 and (section 01:) hardcopy the following class for
those two only.
Part B, the remainder: due Oct.18 (Sat(!))19 (Sun.) 23:59.
Your name and the assignment-number must be in a comment at the start of the file, and your hardcopy must be stapled. All functions/data must include the appropriate steps1 of the-design-recipe—the design recipe: final version. In particular, test cases alone might be worth half the credit for a function. Unless otherwise indicated, two test cases will suffice for most problems, if they are testing different situations.
Unless otherwise indicated, all problems are to be written in Racket.
(check-expect (count-bigs 7 empty) 0) (check-expect (count-bigs 7 (cons 5 empty)) 0) (check-expect (count-bigs 7 (cons 7 empty)) 0) (check-expect (count-bigs 7 (cons 9 empty)) 1) (check-expect (count-bigs 7 (cons 3 (cons 7 empty))) 0) (check-expect (count-bigs 7 (cons 9 (cons 7 empty))) 1) (check-expect (count-bigs 7 (cons 3 (cons 9 empty))) 1) (check-expect (count-bigs 7 (cons 8 (cons 9 empty))) 2) (check-expect (count-bigs 7 (cons 3 (cons 7 (cons 8 (cons 2 empty))))) 1) |
(check-expect (map-sqr empty) empty) (check-expect (map-sqr (cons 7 empty)) (cons 49 empty)) (check-expect (map-sqr (cons 9 (cons 7 empty))) (cons 81 (cons 49 empty))) |
You will not need to turn in hardcopy of things before the dividing-line if they were in your hw04 solution or in the posted hw04 solution2. Any changes you make (e.g. updating the world examples to have a list-of-bricks) will be moved below the dividing line. You do not need to include part A (problems 1,2) in your part B hardcopy.
Right now, you can go ahead and move
all the
hint: When creating the expected-output for you test case, feel free to calldraw-brick . This will help remind you how we drew multiple items onto a single image, back in hw04 #4c and #4e.
(5pts)
Modify your
You'll need to
make updates to your examples of world-structs,
along with
Getting fully-realistic bouncing off the sides would be rather involved; we'll settle for an approximate version To get full credit, you only need:
hack:If you want, you might considering the left- and right-edges to each be very wide rectangular regions; this lets us useoverlap? to determine reflections, similar to how we'll do it for bricks.
You may represent a
Possible tweak:Some breakout implementation give the ball an “imperfect” reflection off the paddle — perhaps due to some “spin” imparted by a paddle moving while it hits the ball4. Adding such a small,
random tweak to the direction has the gameplay advantage that it can get the ball out of any “rut” where it is bouncing around in a perfect diamond, if the world's dimensions happen to allow that.No extra-credit awarded for doing this, beyond the satisfaction of superior gameplay.
At this point you should be able to call
If you wish, you may provide a
Extra credit:
I'll award a small amount of extra-credit for improved bouncing, but you must
first get the approximate version above working.
To improve the physics (though it still won't be perfect5),
I recommend:
detect hitting the right- or left-edge of a paddle by checking
if the ball
All the above should have their tests, as well as signatures and (brief) purpose statements. Only after all tests pass, you can check that the following works:
(require 2htdp/universe) (big-bang some-initial-world [on-key world-handle-key] [on-tick update-world] [to-draw draw-world]) |
1 Your final program doesn't need to include any "transitional" results from the template: For example, you don't need the stubbed-out version of a function from step 5. However, you should still have passed through this phase. ↩
2 Your hw05 may use any/all of the hw04-soln.rkt; of course, cite any code you use like this (including a URL), just as would do for any purpose, hw or not. ↩
3
Alternately, you can leave
4 Maybe a ball should have, in addition to its location and speed, a spin which affects how it gets reflected! ↩
And even truer bouncing would require detecting whether just the circle overlaps a rectangle, and and even what the first, exact point of contact would be.
For a more full-fledged physics simulator, you'd take a ball and any polygon (allowing diagonal sides), and determine the point-of-impact, and the direction it bounces. And for even more accuracy, you would need to account for multiple bounces against several bricks/surfaces, which involves first looking for overlap with the nearest brick, determining that bounce (if any), and then repeat for each brick in order of nearness. If there is a bounce off one object, you need to account for that bounce and how much travel-time was “used up”, and then look for later bounces that only use the remaining travel-time.
So to truly do bouncing correctly, we'd really like three inputs: where the ball is, where it “wants” to move to, and the rectangle we might bounce off of.
↩home—lectures—recipe—exams—hws—D2L—breeze (snow day)
©2014, Ian Barland, Radford University Last modified 2014.Nov.29 (Sat) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |