Library for 3.2'' uLcd Picaso Display4D system Picaso Serial Environment Command Set web: http://www.4dsystems.com.au/product/20/67/Processors_Graphics/PICASO/
Sprite.cpp@1:a74e42cf52b2, 2015-04-05 (annotated)
- Committer:
- adelino
- Date:
- Sun Apr 05 13:54:48 2015 +0000
- Revision:
- 1:a74e42cf52b2
PicasoLib version 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
adelino | 1:a74e42cf52b2 | 1 | #include "Sprite.h" |
adelino | 1:a74e42cf52b2 | 2 | |
adelino | 1:a74e42cf52b2 | 3 | Sprite::Sprite(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,UINT16 _w,UINT16 _h,Color _color): |
adelino | 1:a74e42cf52b2 | 4 | Widget(mScreen,_id,_x,_y,_w,_h,_color) |
adelino | 1:a74e42cf52b2 | 5 | { |
adelino | 1:a74e42cf52b2 | 6 | |
adelino | 1:a74e42cf52b2 | 7 | myIsUpdateAutomatic=true; |
adelino | 1:a74e42cf52b2 | 8 | |
adelino | 1:a74e42cf52b2 | 9 | myXMoveMin=myScreen->getXpos(); |
adelino | 1:a74e42cf52b2 | 10 | myYMoveMin=myScreen->getYpos(); |
adelino | 1:a74e42cf52b2 | 11 | |
adelino | 1:a74e42cf52b2 | 12 | myXMoveMax=myXMoveMin+myScreen->getWidth(); |
adelino | 1:a74e42cf52b2 | 13 | myYMoveMax= myYMoveMin+myScreen->getHeight(); |
adelino | 1:a74e42cf52b2 | 14 | |
adelino | 1:a74e42cf52b2 | 15 | mySpeedX=0.0; |
adelino | 1:a74e42cf52b2 | 16 | mySpeedY=0.0; |
adelino | 1:a74e42cf52b2 | 17 | } |
adelino | 1:a74e42cf52b2 | 18 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 19 | Sprite::~Sprite(void) |
adelino | 1:a74e42cf52b2 | 20 | { |
adelino | 1:a74e42cf52b2 | 21 | } |
adelino | 1:a74e42cf52b2 | 22 | |
adelino | 1:a74e42cf52b2 | 23 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 24 | void Sprite::setUpdateAutomatic(bool _state) |
adelino | 1:a74e42cf52b2 | 25 | { |
adelino | 1:a74e42cf52b2 | 26 | myIsUpdateAutomatic=_state; |
adelino | 1:a74e42cf52b2 | 27 | } |
adelino | 1:a74e42cf52b2 | 28 | //--------------------------------------- |
adelino | 1:a74e42cf52b2 | 29 | bool Sprite::getUpdateAutomatic(void) const |
adelino | 1:a74e42cf52b2 | 30 | { |
adelino | 1:a74e42cf52b2 | 31 | return this->myIsUpdateAutomatic; |
adelino | 1:a74e42cf52b2 | 32 | } |
adelino | 1:a74e42cf52b2 | 33 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 34 | bool Sprite::overlapWith(Sprite* pObj) |
adelino | 1:a74e42cf52b2 | 35 | { |
adelino | 1:a74e42cf52b2 | 36 | return overlap(this,pObj); |
adelino | 1:a74e42cf52b2 | 37 | } |
adelino | 1:a74e42cf52b2 | 38 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 39 | bool Sprite::overlap(Sprite* pObj1,Sprite* pObj2) |
adelino | 1:a74e42cf52b2 | 40 | { |
adelino | 1:a74e42cf52b2 | 41 | UINT16 x1=pObj1->getXposition(); |
adelino | 1:a74e42cf52b2 | 42 | UINT16 x2=pObj2->getXposition(); |
adelino | 1:a74e42cf52b2 | 43 | |
adelino | 1:a74e42cf52b2 | 44 | UINT16 y1=pObj1->getYposition(); |
adelino | 1:a74e42cf52b2 | 45 | UINT16 y2=pObj2->getYposition(); |
adelino | 1:a74e42cf52b2 | 46 | |
adelino | 1:a74e42cf52b2 | 47 | UINT16 xa=pObj1->getXposition()+pObj1->getWidth(); |
adelino | 1:a74e42cf52b2 | 48 | UINT16 xb=pObj2->getXposition()+pObj2->getWidth(); |
adelino | 1:a74e42cf52b2 | 49 | |
adelino | 1:a74e42cf52b2 | 50 | UINT16 ya=pObj1->getYposition()+pObj1->getHeight(); |
adelino | 1:a74e42cf52b2 | 51 | UINT16 yb=pObj2->getYposition()+pObj2->getHeight(); |
adelino | 1:a74e42cf52b2 | 52 | |
adelino | 1:a74e42cf52b2 | 53 | // |
adelino | 1:a74e42cf52b2 | 54 | if(x1 <xb && xa>x2 && y1<yb && ya>y2) { |
adelino | 1:a74e42cf52b2 | 55 | |
adelino | 1:a74e42cf52b2 | 56 | return true; |
adelino | 1:a74e42cf52b2 | 57 | } else { |
adelino | 1:a74e42cf52b2 | 58 | return false; |
adelino | 1:a74e42cf52b2 | 59 | } |
adelino | 1:a74e42cf52b2 | 60 | |
adelino | 1:a74e42cf52b2 | 61 | } |
adelino | 1:a74e42cf52b2 | 62 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 63 | void Sprite::elementUpdate(void) |
adelino | 1:a74e42cf52b2 | 64 | { |
adelino | 1:a74e42cf52b2 | 65 | switch(myState) { |
adelino | 1:a74e42cf52b2 | 66 | // |
adelino | 1:a74e42cf52b2 | 67 | case BUMP_DOWN: |
adelino | 1:a74e42cf52b2 | 68 | setInvertSpeedY(); |
adelino | 1:a74e42cf52b2 | 69 | myState=STATE_ON; |
adelino | 1:a74e42cf52b2 | 70 | break; |
adelino | 1:a74e42cf52b2 | 71 | // |
adelino | 1:a74e42cf52b2 | 72 | case BUMP_LEFT: |
adelino | 1:a74e42cf52b2 | 73 | setInvertSpeedX(); |
adelino | 1:a74e42cf52b2 | 74 | myState=STATE_ON; |
adelino | 1:a74e42cf52b2 | 75 | break; |
adelino | 1:a74e42cf52b2 | 76 | // |
adelino | 1:a74e42cf52b2 | 77 | case BUMP_RIGHT: |
adelino | 1:a74e42cf52b2 | 78 | setInvertSpeedX(); |
adelino | 1:a74e42cf52b2 | 79 | myState=STATE_ON; |
adelino | 1:a74e42cf52b2 | 80 | break; |
adelino | 1:a74e42cf52b2 | 81 | // |
adelino | 1:a74e42cf52b2 | 82 | case BUMP_UP: |
adelino | 1:a74e42cf52b2 | 83 | setInvertSpeedY(); |
adelino | 1:a74e42cf52b2 | 84 | myState=STATE_ON; |
adelino | 1:a74e42cf52b2 | 85 | break; |
adelino | 1:a74e42cf52b2 | 86 | // |
adelino | 1:a74e42cf52b2 | 87 | case STATE_OFF: |
adelino | 1:a74e42cf52b2 | 88 | break; |
adelino | 1:a74e42cf52b2 | 89 | // |
adelino | 1:a74e42cf52b2 | 90 | default: |
adelino | 1:a74e42cf52b2 | 91 | break; |
adelino | 1:a74e42cf52b2 | 92 | } |
adelino | 1:a74e42cf52b2 | 93 | // |
adelino | 1:a74e42cf52b2 | 94 | } |
adelino | 1:a74e42cf52b2 | 95 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 96 | void Sprite::draw(void) |
adelino | 1:a74e42cf52b2 | 97 | { |
adelino | 1:a74e42cf52b2 | 98 | //to do |
adelino | 1:a74e42cf52b2 | 99 | } |
adelino | 1:a74e42cf52b2 | 100 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 101 | float Sprite::getSpeedX(void) const |
adelino | 1:a74e42cf52b2 | 102 | { |
adelino | 1:a74e42cf52b2 | 103 | return this->mySpeedX; |
adelino | 1:a74e42cf52b2 | 104 | } |
adelino | 1:a74e42cf52b2 | 105 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 106 | float Sprite::getSpeedY(void) const |
adelino | 1:a74e42cf52b2 | 107 | { |
adelino | 1:a74e42cf52b2 | 108 | return this->mySpeedY; |
adelino | 1:a74e42cf52b2 | 109 | } |
adelino | 1:a74e42cf52b2 | 110 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 111 | void Sprite::setInvertSpeedX(void) |
adelino | 1:a74e42cf52b2 | 112 | { |
adelino | 1:a74e42cf52b2 | 113 | mySpeedX=-(this->mySpeedX); |
adelino | 1:a74e42cf52b2 | 114 | } |
adelino | 1:a74e42cf52b2 | 115 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 116 | void Sprite::setInvertSpeedY(void) |
adelino | 1:a74e42cf52b2 | 117 | { |
adelino | 1:a74e42cf52b2 | 118 | mySpeedY=-(this->mySpeedY); |
adelino | 1:a74e42cf52b2 | 119 | } |
adelino | 1:a74e42cf52b2 | 120 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 121 | void Sprite::setSpeedX(float _speedX) |
adelino | 1:a74e42cf52b2 | 122 | { |
adelino | 1:a74e42cf52b2 | 123 | mySpeedX=_speedX; |
adelino | 1:a74e42cf52b2 | 124 | } |
adelino | 1:a74e42cf52b2 | 125 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 126 | void Sprite::setSpeedY(float _speedY) |
adelino | 1:a74e42cf52b2 | 127 | { |
adelino | 1:a74e42cf52b2 | 128 | mySpeedY=_speedY; |
adelino | 1:a74e42cf52b2 | 129 | } |
adelino | 1:a74e42cf52b2 | 130 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 131 | void Sprite::setSpeedXY(float _speedX,float _speedY) |
adelino | 1:a74e42cf52b2 | 132 | { |
adelino | 1:a74e42cf52b2 | 133 | mySpeedX=_speedX; |
adelino | 1:a74e42cf52b2 | 134 | mySpeedY=_speedY; |
adelino | 1:a74e42cf52b2 | 135 | } |
adelino | 1:a74e42cf52b2 | 136 | |
adelino | 1:a74e42cf52b2 | 137 |