Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example program: Bat and ball (OO-style) #133

Open
maryrosecook opened this issue Dec 15, 2015 · 0 comments
Open

Example program: Bat and ball (OO-style) #133

maryrosecook opened this issue Dec 15, 2015 · 0 comments

Comments

@maryrosecook
Copy link
Owner

ball: make-circle(50 50 20)
ball: set(ball "x-speed" 0)
ball: set(ball "y-speed" 0)

gravity: 0.5

forever {
  bat: make-rectangle(mouse-x mouse-y 100 10)

  if are-overlapping(bat ball) {
    bat-ball-difference: subtract(get(ball "x") get(bat "x"))
    ball: set(ball "x-speed" divide(bat-ball-difference 10))  
    ball: set(ball "y-speed" opposite(get(ball "y-speed")))
  } else {
    ball: set(ball "y-speed" add(gravity get(ball "y-speed")))
  }

  ball: set(ball "x" add(get(ball "x") get(ball "x-speed")))
  ball: set(ball "y" add(get(ball "y") get(ball "y-speed")))

  clear-screen()
  draw(ball)
  draw(bat)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant