home—lectures—exams—hws—breeze (snow day)
hw04
assembling asteroids
let the game begin
Grading note-to-self:
-
The bouncing-ball example was too enticing for people -- they ditched
the ship fields used in hw03-soln, and replaced them with the fields from the example!
They then pasted in code from the example,
and just gave up on modifying it rather than thinking through what needed to be done
from scratch.
-
I should weight the drawing functions @50%, if I'm not requiring test cases.
(I felt like I was giving too much credit/weight for those, and
not enough for the move- and helper functions, per line of code.)
For the local section:
Due Sep.28 (Wed)29 (Thu)32 (Sun)1 23:59 (D2L; bring hardcopy next class)
Your name and the assignment-number
must be in a comment at the start of the file.
Implement the functions below.
Following those requirements is a discussion of ways our game can differ from the original game.
All non-drawing functions require at least two test cases!
(Point-values are subject to slight tweaking.)
- (3pts)
Write a function draw-ship which takes in a ship and an image (the screen / background),
and returns a new image which contains [a picture of] the ship overlayed on the given background.
See the racket documentation for helpful image-drawing functions.
(Either search directly,
or take a function you know about (like circle), put the caret over it,
and hit F1 to call up the documentation.)
- (3pts)
Write draw-astr : astr, image -> image.
- (3pts)
Write draw-astrs : (list-of astr), image -> image.
- (3pts)
Design a world structure, to represent the entire asteroids game.
Construct some examples.
- (6pts)
Write move-world : world -> world and draw-world : world -> image.
- (3pts)
Have your code call big-bang,
providing it on-tick and on-draw handlers.
You can look over the file
big-bang-example.rkt dicussed in class,
for a medium-length example of using big-bang (followed by a short example).
And/or,
racket-lang.org's splash page “Start Quickly” examples
include a balloon-inflating example.
- (9pts)
Implement controls:
Rotate the ship when the user presses the right or left arrows,
and apply thrust when the user presses the up-arrow.
(As in the classic game, applying thrust will accelerate the ship
but only in the direction it's facing.)
You'll of course want a helper functions accelerate-ship
and rotate-ship, along with test cases for those functions.
-
We will approximate collision-detection by treating all our objects
(ships, asteroids, and later bullets) as circles2.
Half the points are for test cases.
- (3pts)
Write overlap?, which takes info about two circles
(two (x,y) centers and two radii),
and returns whether they overlap.
- (3pts)
Write collide-ship-astr?, which takes in a ship and an asteroid,
and returns whether or not they are colliding.
(You can approximate collision by whether their "bounding circles" overlap.)
- (3pts)
Write collide-ship-astrs?, which takes in a ship and a list of asteroids,
and returns whether or not the ship collides with any of them.
- (1pt)
Provide a stop-when handler to big-bang.
All that remains is adding bullets and effects of their collisons!
You can think about, and perhaps start coding, those functions3.
We're looking for a asteroids-like game,
but we don't need to implement every feature of the original.
In particular, it's acceptable to punt on the following issues.
-
Objects can be drawn quite differently from the original.
(Keep it simple at first; you can always make it look fancier later.)
-
No need to draw the "acceleration" flame for the ship,
or even to keep track of whether the accelerate key is being held — for
simplicity, I suggest having the accelerate key merely impart one “kick”
of acceleration.4
-
You don't have to have a friction term, to slow the ship.
(There's no friction in space! … though it does make the game more playable.)
-
Asteroids can behave differently than the game proper, as long as it's reasonable.
-
No sounds required
(though you are certainly welcome to
call play-sound if you like).
Please, no copyrighted sounds.
If you know of a website that has some free-to-use sounds
(e.g. under a creative commons license),
please post on the discussion boards.
Or, record your own!
-
We don't need to keep track of a score.
-
We'll defer bullets for a while.
-
No marauding UFOs.
Post/ask on discussion boards if you have other questions/suggestions.
The ultimate point of the exercise is to
- be proficient at list-processing functions
(including maps, filters, and folds, which we'll talk about later);
-
Have a solid understanding of how one can write a program functionally,
without ever assigning to a variable;
-
better understand model-view-controller;
-
Rid the ether of dangerous, life-threatening asteroids.
Opportunities are rife for extra-credit, by adding additional features.
Don't do this until you get the above functionality working, though!
1Sep.32 being a non-normalized representation for Oct.02 ↩
2
If you prefer to use rectangles for bounding-boxes, see me for advice.
If you want to use some other collision-detection approach, I encourage you to run it by me first.
↩
3
One can use strutures with inheritance, although you have to abandon the student languages for that.
#lang racket
;; Be sure to have selected 'Language > Determine language from source'
#lang racket
(define-struct foo (a b) #:transparent)
(define-struct (goo foo) (c d e) #:transparent)
(define f (make-foo 98 99))
(define g (make-goo 1 2 3 4 5))
(foo-a f) ; 98
(foo-a g) ; 1
(goo-c g) ; 3
|
↩4
If you did want to go the extra mile and
handle both key-release events (in addition to key-press events),
it would presumably requires adding state to the ship representing whether or not
it is currently in the middle of acceleration.
↩
home—lectures—exams—hws—breeze (snow day)