Istvan Papp / Mbed 2 deprecated Brickbreaker

Dependencies:   NokiaLCD PS2 mbed

Fork of Pong by William Johnston

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers block.cpp Source File

block.cpp

00001 #include "mbed.h"
00002 #include "block.h"
00003 
00004 Block::Block()
00005 {
00006     int x=y=width=height=color=0;
00007 }
00008 
00009 Block::Block(int x, int y, int w, int h, int c)
00010     : x(x), y(y), width(w), height(h), color(c) {}
00011 
00012 /*
00013  * Member Function move:
00014  * Description: Colors in the previous block black
00015  *  and moves block to new position.
00016  */
00017 void Block::move(NokiaLCD &lcd, int increment)
00018 {
00019     draw(lcd, true);
00020     y += increment;
00021 }
00022 
00023 
00024 /*
00025  * Member Function moveCPU:
00026  * Description: Colors in the previous block black
00027  *  and moves block to new position.
00028  *  inc variable allows block to only move every
00029  *  other function call.
00030  */
00031 void Block::moveCPU(NokiaLCD &lcd, int _y)
00032 {
00033     static int inc = 1;
00034     draw(lcd, true);
00035     if(_y>y+height/2 && y+height<130) y += inc;
00036     else if(_y+5<y+height/2 && y>0) y -= inc;
00037     inc = (inc) ? 0 : 1;
00038 }
00039 
00040 void Block::draw(NokiaLCD &lcd, bool isBlack) const
00041 {
00042     lcd.fill(x, y, width, height, (isBlack) ? 0x000000 : color);
00043 }
00044 
00045 int Block::size() const
00046 {
00047     return width*height;
00048 }
00049 
00050 int Block::getWidth() const
00051 {
00052     return width;
00053 }
00054 
00055 int Block::getHeight() const
00056 {
00057     return height;
00058 }
00059 
00060 int Block::getX() const
00061 {
00062     return x;
00063 }
00064 
00065 int Block::getY() const
00066 {
00067     return y;
00068 }
00069