CMPT 166 Lecture Notes - Lecture 28: Ellipse

59 views8 pages

Document Summary

In previous notes we introduced the sprite class to help simplify creating animated objects: class sprite { float x; float y; float dx; float dy; With it we could write code like this: color ballcolor = color(255, 165, 0); // hit the left edge? if (ball. x - radius <= 0) { ball. dx = -ball. dx; ball. x = radius; // hit the right edge? if (ball. x + radius >= 499) { ball. dx = -ball. dx; ball. x = 499 - radius; // hit the top edge? if (ball. y - radius <= 0) { ball. dy = -ball. dy; radius += 5; ball. y = radius; // hit the bottom edge? if (ball. y + radius >= 499) { ball. dy = -ball. dy; ball. y = 499 - radius; Using the sprite class makes it easier to declare x, y, dx, and dy, and also makes the source code a little easier to read. But we still have to do a lot of typing.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents