Study Guides (380,000)
CA (150,000)
SFU (4,000)
IAT (70)
IAT 265 (10)
Final

IAT 265 Study Guide - Final Guide: 720P, Ellipse


Department
Interactive Arts & Tech
Course Code
IAT 265
Professor
Matt Lockyer
Study Guide
Final

Page:
of 5
Breakout Paint
static final int ROWS = 1;
static final boolean DEBUG = true;
// blocks
static final float blockWidth = 60;
static final float blockHeight = 20;
static final float blockSpacing = 10;
// each block has:
// xPos of center
float[] blocksX;
// yPos of center
float[] blocksY;
// hit or not
boolean[] blocksHit;
// paddle varables
// positions
float paddleX, paddleY;
// dimensions
float paddleWidth, paddleHeight, paddleSpacing;
// ball variables
float ballX, ballY, ballXVel, ballYVel;
float ballDiameter;
// flag determine if the games has started or is waiting to begin.
boolean gameStarted;
void setup() {
// 720p HD
//size(400, 400);
//size(displayHeight, displayWidth);
size(1280, 720);
//smooth();
// setup the ball;
ballXVel = 0;
ballYVel = 0;
ballDiameter = 15;
// setup the paddle
paddleWidth = 100;
paddleHeight = 20;
paddleSpacing = 10;
paddleX = width/2;
paddleY = height - paddleHeight - paddleSpacing;
// setup the ball's position
ballX = paddleX;
ballY = paddleY - paddleHeight;
gameStarted = false;
// get the number of blocks per row
int blocksPerRow = (int) (width / (blockWidth + blockSpacing));
float remainder = width - (blockWidth + blockSpacing) * blocksPerRow;
println("Number of Blocks: "+ blocksPerRow);
println("Left over: "+ remainder);
blocksX = new float[blocksPerRow];
blocksY = new float[blocksPerRow];
blocksHit = new boolean[blocksPerRow];
// create create rock of blocks
for (int i = 0; i < blocksPerRow; i++) {
blocksX[i] = blockSpacing + blockWidth/2 + (blockSpacing + blockWidth) * i;
blocksY[i] = blockHeight + blockSpacing;
blocksHit[i] = false;
}
}
void draw() {
background(255);
// draw the artistic background generated by the paddle hitting the balls
// draw the grid of blocks
for (int i = 0; i < blocksX.length; i++) {
if (!blocksHit[i] && detectCollision(ballX, ballY, blocksX[i], blocksY[i])) {
blocksHit[i] = true;
ballXVel *= -1;
ballYVel *= -1;
}
if (!blocksHit[i]) {
pushMatrix();
translate(blocksX[i], blocksY[i]);
stroke(127, 255, 232);
fill(128, 56);
rect(-blockWidth/2, -blockHeight/2, blockWidth, blockHeight);
popMatrix();
}
}
drawPaddle(paddleX, paddleY, paddleWidth, paddleHeight);
drawBall(ballX, ballY);
// keep the ball bouncing inside the window bounds
// measure the bounds from the center
if (abs(ballX - width/2) > width/2 - ballDiameter/2 ) {
ballXVel *= -1;
}
if (DEBUG && abs(ballY - height/2) > height/2 - ballDiameter ) {
ballYVel *= -1;
}
// handle the ball's collision with the paddle
if ( abs(paddleY - ballY) < ballDiameter /2 + paddleHeight/2 && abs(ballX - paddleX) <
ballDiameter /2 + paddleWidth/2 ) {
ballYVel *= -1; // change the direction of the ball's y direction
ballXVel += getMouseVelocity(mouseX, pmouseX); // update our ball's x velocity by the
mouse's velocity
}
if (mouseX < paddleWidth/2) {
paddleX = paddleWidth/2;
}
else if (mouseX > width - paddleWidth/2) {
paddleX = width - paddleWidth/2;
}
else {