;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname Game) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) (require "Teachpacks/bootstrap-teachpack.rkt") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 0. Game title: Write the title of your game here (define TITLE "My Game") (define TITLE-COLOR "white") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Graphics - danger, target, projectile and player images (define BACKGROUND (rectangle 640 480 "solid" "black")) (define DANGER (triangle 30 "solid" "red")) (define TARGET (circle 20 "solid" "green")) (define PLAYER (rectangle 30 30 "solid" "blue")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 1. Making the Danger and the Target Move ; update-danger: Number -> Number ; given the danger's x-coordinate, output the NEXT x (define (update-danger x) x) ; update-target : Number -> Number ; given the target's x-coordinate, output the NEXT x (define (update-target x) x) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 2. Making the Danger and the Target Come Back Again: ;; Are they still onscreen? ; protect-left? : Number -> Boolean ; is the character protected on the left side of the screen? (define (protect-left? x) true) ; protect-right? : Number -> Boolean ; is the character protected on the right side of the screen? (define (protect-right? x) true) ; onscreen? : Number Number -> Boolean ; Determines if the coordinates are within 100 pixels of the screen (define (onscreen? x) true) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 3. Get our Player moving! ; update-player : Number String -> Number ; given the player's y-coordinate and a direction, output the NEXT y (define (update-player y key) y) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 4. Collisions: When the player is close enough to the Target ;; or the Danger, then something should happen! ;; We need to know what "close enough" means, and we need to ;; know how far apart things are. ;; If *distances-color* is not "", then the game will show ;; a triangle between the player and each character. ;; That triangle will be labelled with line-length on the legs, ;; and with distance on the hypotenuse. (define *distances-color* "") ; line-length : Number Number -> Number ; the distance between two points on a number line ;(EXAMPLE (line-length 20 10) 10) ;(EXAMPLE (line-length 10 20) 10) (define (line-length a b) 0) ; distance : Number Number Number Number -> Number ; We have the player's position (px, py), ; and a character's position (cx, cy). ; How far apart are they? (define (distance px py cx cy) 0) ; collide? : Number Number Number Number -> Boolean ; We have (px, py) and (cx, cy). Are they close enough for a collision? (define (collide? px py cx cy) false) ; a final secret: (define mystery (radial-star 5 5 3 "solid" "silver")) (define (update-mystery x) x) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; PROVIDED CODE ;; defines a game level, using all the images and functions ;; defined above. (define game_level (make-game TITLE TITLE-COLOR BACKGROUND DANGER update-danger TARGET update-target PLAYER update-player mystery update-mystery *distances-color* line-length distance collide? onscreen?)) ;; starts the game, using game_level (play game_level)