Brickbreaker

Dependencies:   NokiaLCD PS2 mbed

Fork of Pong by William Johnston

Committer:
ipapp3
Date:
Mon Apr 29 18:17:51 2013 +0000
Revision:
4:f3ac45fa2196
Parent:
3:e1328f84b107
final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ipapp3 3:e1328f84b107 1 #include "mbed.h"
ipapp3 3:e1328f84b107 2 #include "block.h"
ipapp3 3:e1328f84b107 3
ipapp3 3:e1328f84b107 4 Block::Block()
ipapp3 3:e1328f84b107 5 {
ipapp3 3:e1328f84b107 6 int x=y=width=height=color=0;
ipapp3 3:e1328f84b107 7 }
ipapp3 3:e1328f84b107 8
ipapp3 3:e1328f84b107 9 Block::Block(int x, int y, int w, int h, int c)
ipapp3 3:e1328f84b107 10 : x(x), y(y), width(w), height(h), color(c) {}
ipapp3 3:e1328f84b107 11
ipapp3 3:e1328f84b107 12 /*
ipapp3 3:e1328f84b107 13 * Member Function move:
ipapp3 3:e1328f84b107 14 * Description: Colors in the previous block black
ipapp3 3:e1328f84b107 15 * and moves block to new position.
ipapp3 3:e1328f84b107 16 */
ipapp3 3:e1328f84b107 17 void Block::move(NokiaLCD &lcd, int increment)
ipapp3 3:e1328f84b107 18 {
ipapp3 3:e1328f84b107 19 draw(lcd, true);
ipapp3 3:e1328f84b107 20 y += increment;
ipapp3 3:e1328f84b107 21 }
ipapp3 3:e1328f84b107 22
ipapp3 3:e1328f84b107 23
ipapp3 3:e1328f84b107 24 /*
ipapp3 3:e1328f84b107 25 * Member Function moveCPU:
ipapp3 3:e1328f84b107 26 * Description: Colors in the previous block black
ipapp3 3:e1328f84b107 27 * and moves block to new position.
ipapp3 3:e1328f84b107 28 * inc variable allows block to only move every
ipapp3 3:e1328f84b107 29 * other function call.
ipapp3 3:e1328f84b107 30 */
ipapp3 3:e1328f84b107 31 void Block::moveCPU(NokiaLCD &lcd, int _y)
ipapp3 3:e1328f84b107 32 {
ipapp3 3:e1328f84b107 33 static int inc = 1;
ipapp3 3:e1328f84b107 34 draw(lcd, true);
ipapp3 3:e1328f84b107 35 if(_y>y+height/2 && y+height<130) y += inc;
ipapp3 3:e1328f84b107 36 else if(_y+5<y+height/2 && y>0) y -= inc;
ipapp3 3:e1328f84b107 37 inc = (inc) ? 0 : 1;
ipapp3 3:e1328f84b107 38 }
ipapp3 3:e1328f84b107 39
ipapp3 3:e1328f84b107 40 void Block::draw(NokiaLCD &lcd, bool isBlack) const
ipapp3 3:e1328f84b107 41 {
ipapp3 3:e1328f84b107 42 lcd.fill(x, y, width, height, (isBlack) ? 0x000000 : color);
ipapp3 3:e1328f84b107 43 }
ipapp3 3:e1328f84b107 44
ipapp3 3:e1328f84b107 45 int Block::size() const
ipapp3 3:e1328f84b107 46 {
ipapp3 3:e1328f84b107 47 return width*height;
ipapp3 3:e1328f84b107 48 }
ipapp3 3:e1328f84b107 49
ipapp3 3:e1328f84b107 50 int Block::getWidth() const
ipapp3 3:e1328f84b107 51 {
ipapp3 3:e1328f84b107 52 return width;
ipapp3 3:e1328f84b107 53 }
ipapp3 3:e1328f84b107 54
ipapp3 3:e1328f84b107 55 int Block::getHeight() const
ipapp3 3:e1328f84b107 56 {
ipapp3 3:e1328f84b107 57 return height;
ipapp3 3:e1328f84b107 58 }
ipapp3 3:e1328f84b107 59
ipapp3 3:e1328f84b107 60 int Block::getX() const
ipapp3 3:e1328f84b107 61 {
ipapp3 3:e1328f84b107 62 return x;
ipapp3 3:e1328f84b107 63 }
ipapp3 3:e1328f84b107 64
ipapp3 3:e1328f84b107 65 int Block::getY() const
ipapp3 3:e1328f84b107 66 {
ipapp3 3:e1328f84b107 67 return y;
ipapp3 3:e1328f84b107 68 }
ipapp3 3:e1328f84b107 69