Simple Pong game on NokiaLCD with PS2

Dependencies:   mbed PS2 NokiaLCD

Committer:
wjohnsto
Date:
Mon Feb 28 00:22:23 2011 +0000
Revision:
2:d1031c73e187
Parent:
1:3cc8b1413557

        

Who changed what in which revision?

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