Question: drracket coding of bouncing ball, below code the ball does not move, pls help to advise #lang racket ( require 2 htdp / image )
drracket coding of bouncing ball, below code the ball does not move, pls help to advise
#lang racket
require htdpimage
require htdpuniverse
define WIDTH
define HEIGHT
define BALLRADIUS
define TOP BALLRADIUS
define BOT HEIGHT BALLRADIUS
define LEF BALLRADIUS
define RIG WIDTH BALLRADIUS
definestruct ball x y dx dy
TOP
BOT
LEF
RIG
define BALL circle BALLRADIUS "solid" "white"
define MTS rectangle WIDTH HEIGHT "solid" "green"
define Bmakeball WIDTH HEIGHT
;check if ball near edges
define touchtop? b
bally bballdy b TOP
define touchbot? b
bally bballdy b BOT
define touchrig? b
ballx bballdx b RIG
define touchlef? b
ballx bballdx b BOT
; Bounce the ball off the edges
define bouncetop bmakeball ballx b TOP balldx bballdy b
define bouncebot bmakeball ballx b BOT balldx bballdy b
define bouncelef bmakeball LEF bally bballdx bballdy b
define bouncerig bmakeball RIG bally bballdx bballdy b
; Move the ball
define glide bmakeball ballx bballdx bbally bballdy bballdx bballdy b
; Handle mouse click to create a new ball
define handlemouse b x y event
cond equal event "buttondown"makeball x y random random
else B
define renderball b
placeimage circle BALLRADIUS 'solid 'whiteballx bbally bemptyscene WIDTH HEIGHT 'green
; Determine the next state of the ball based on its position
define nextball b
cond
or touchtop? btouchbot? bmakeball ballx bbally bballdx bballdy b
or touchlef? btouchrig? bmakeball ballx bbally bballdx bballdy b
else makeball ballx bballdx bbally bballdy bballdx bballdy b
;Main program start here
bigbang makeball WIDTH HEIGHT
ontick nextball
ondraw renderball
onmouse handlemouse
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
