1 ;; DO NOT PUT ANYTHING PERSONALLY IDENTIFYING BEYOND YOUR CWL IN THIS FILE.
2 ;; YOUR CWLs WILL BE SUFFICIENT TO IDENTIFY YOU AND, IF YOU HAVE ONE, YOUR
3 ;; PARTNER.
4 (require 2htdp/universe)
5 (require 2htdp/image)
6 (require spd/tags)
7
8 (@assignment pset-05);Do not edit or remove this tag
9 (@cwl sumi1008) ;Replace ??? with your cwl,
10 ;; ;second ??? is replaced with partner cwl if you have one
11
12 ;; Bounce any number of balls around the screen.
13
14
15 ;;
16 ;; In this problem set you are given our official solution to problem
17 ;; set 4 (with a few additional things added) as a starting point.
18 ;; We have given you some more constants, a helper function called
19 ;; touch-paddle? which you may use, and a new data defintion called Game.
20 ;; You need to revise the program so that:
21 ;; - the game includes a paddle that moves back and forth across the
22 ;; bottom of the screen
23 ;; - the paddle is controlled by the left and right arrow keys
24 ;; - when a ball hits the paddle it disappears
m
25 ;; - as before the mouse can be used to add balls to the game
er as
26 ;;
27 ;; As stated above, we have given you a new data definition called Game.
co
28 ;; You MUST revise the program so that it uses Game as the world state.
eH w
29 ;; You MUST NOT change the Game data definition in anyway (though you are
o.
30 ;; allowed to add more Game constants).
31 ;;
rs e
32 ;; We suggest you work in three distinct phases, making sure your program
ou urc
33 ;; works correctly at the end of each phase before going on to the next.
34 ;; - change the program's world state to Game
35 ;; - provide left/right arrow key control over the paddle
36 ;; - make it so that when a ball hits the paddle it disappears
o
37 ;;
aC s
38 ;; In each of these phases you should follow the design recipes! Re-work
vi y re
39 ;; the domain analysis for changing and constant information, update the
40 ;; data definitions, revise the main function, and so on. Make sure that
41 ;; your tags are correct and that all your tests work correctly before you
42 ;; proceed to the next phase.
43 ;;
ed d
44 ;; NOTE: Your on-tick function MUST be designed as a composition of two other
ar stu
45 ;; functions called game-with-next-balls and game-with-caught-balls.
46 ;;
47 ;; Note that we are giving you significant help in the starter file.
48 ;; You absolutely MUST USE OUR STARTER AS THE BASIS FOR YOUR WORK.
is
49 ;;
50 ;; We recommend that you begin by printing this file and planning out what
Th
51 ;; needs to change, what needs to be added, and what will be unchanged.
52 ;;
53 (@problem 1)
54 (@htdw ListOfBall)
55
sh
, 68 (define TOP BALL-RADIUS)
69 (define BOT (- HEIGHT BALL-RADIUS 1))
70 (define LEF BALL-RADIUS)
71 (define RIG (- WIDTH BALL-RADIUS 1))
72
73 (define BALL (circle BALL-RADIUS "solid" "white"))
74
75 (define MTS (rectangle WIDTH HEIGHT "solid" "green"))
76
77
78 ;; ===========================================================================
79 ;; ===========================================================================
80 ;; Data definitions:
81
82 (@htdd Ball)
83 (define-struct ball (x y dx dy))
84 ;; Ball is (make-ball Number Number Number Number)
85 ;; interp. (make-ball x y dx dy) is ball
86 ;; - position x, y in screen coordinates
87 ;; - velocity dx, dy in pixels/tick
88 ;; CONSTRAINT: x is in [LEF, RIG]; y is in [TOP, BOT]
89 (define B1 (make-ball (/ WIDTH 2) (/ HEIGHT 2) 4 -3))
90
91 (@dd-template-rules compound)
m
92
er as
93 (define (fn-for-ball b)
94 (... (ball-x b)
co
95 (ball-y b)
eH w
96 (ball-dx b)
o.
97 (ball-dy b)))
98
99 (@htdd ListOfBall) rs e
ou urc
100 ;; ListOfBall is one of:
101 ;; - empty
102 ;; - (cons Ball ListOfBall)
103 ;; interp. a list of balls
o
104 (define LOB1 empty)
aC s
105 (define LOB2 (cons B1 empty))
vi y re
106
107 (@dd-template-rules one-of
108 atomic-distinct
109 compound
110 ref
ed d
118
119
120 (@htdd Game)
121 (define-struct game (balls paddle))
122 ;; Game is (make-game ListOfBall Number)
sh
123 ;; interp. the current state of a game, with all the balls in play,
124 ;; as well as the x-position of the paddle in screen coordinates
125 (define G0 (make-game empty (/ WIDTH 2)))
126 (define G1 (make-game (cons B1 empty) (/ WIDTH 2)))
127
128 (@dd-template-rules compound ref)
129
130 (define (fn-for-game g)
131 (... (fn-for-lob (game-balls g))
132 (game-paddle g)))
133This study source was downloaded by 100000805705997 from CourseHero.com on 10-14-2021 20:26:46 GMT -05:00
134
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller solutions. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $2.99. You're not tied to anything after your purchase.