Yudong Xiao
/
pokemon
This is test version of Pokemongo game. ELEC 2645 final project.
pokeball/Pokeball.cpp@0:819c2d6a69ac, 2021-04-15 (annotated)
- Committer:
- shalwego
- Date:
- Thu Apr 15 15:35:12 2021 +0000
- Revision:
- 0:819c2d6a69ac
Issue about music playing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shalwego | 0:819c2d6a69ac | 1 | #include "Pokeball.h" |
shalwego | 0:819c2d6a69ac | 2 | |
shalwego | 0:819c2d6a69ac | 3 | void Pokeball::init(int x, int y, int radius){ |
shalwego | 0:819c2d6a69ac | 4 | _x = x; |
shalwego | 0:819c2d6a69ac | 5 | _y = y; |
shalwego | 0:819c2d6a69ac | 6 | _radius = radius; |
shalwego | 0:819c2d6a69ac | 7 | _speed = 1;//default speed |
shalwego | 0:819c2d6a69ac | 8 | |
shalwego | 0:819c2d6a69ac | 9 | |
shalwego | 0:819c2d6a69ac | 10 | } |
shalwego | 0:819c2d6a69ac | 11 | |
shalwego | 0:819c2d6a69ac | 12 | void Pokeball::draw(N5110 &lcd) { |
shalwego | 0:819c2d6a69ac | 13 | //printf("Ball: Draw\n"); |
shalwego | 0:819c2d6a69ac | 14 | lcd.drawCircle(_x, _y, _radius, FILL_BLACK); |
shalwego | 0:819c2d6a69ac | 15 | } |
shalwego | 0:819c2d6a69ac | 16 | |
shalwego | 0:819c2d6a69ac | 17 | void Pokeball::update(UserInput input){ |
shalwego | 0:819c2d6a69ac | 18 | _speed = 4; |
shalwego | 0:819c2d6a69ac | 19 | switch(input.d){ |
shalwego | 0:819c2d6a69ac | 20 | case N: _y -= _speed; break; |
shalwego | 0:819c2d6a69ac | 21 | case NE: _y -= _speed; _x += _speed; break; |
shalwego | 0:819c2d6a69ac | 22 | case E: _x += _speed; break; |
shalwego | 0:819c2d6a69ac | 23 | case SE: _y += _speed; _x += _speed; break; |
shalwego | 0:819c2d6a69ac | 24 | case S: _y += _speed; break; |
shalwego | 0:819c2d6a69ac | 25 | case SW: _y += _speed; _x -= _speed; break; |
shalwego | 0:819c2d6a69ac | 26 | case W: _x -= _speed; break; |
shalwego | 0:819c2d6a69ac | 27 | case NW: _y -= _speed; _x -= _speed; break; |
shalwego | 0:819c2d6a69ac | 28 | dafault: break; |
shalwego | 0:819c2d6a69ac | 29 | } |
shalwego | 0:819c2d6a69ac | 30 | |
shalwego | 0:819c2d6a69ac | 31 | if (_y - _radius < 1) _y = _radius + 1; |
shalwego | 0:819c2d6a69ac | 32 | if (_x - _radius < 1) _x = _radius + 1; |
shalwego | 0:819c2d6a69ac | 33 | if (_x + _radius > WIDTH - 1) _x = WIDTH - _radius - 1; |
shalwego | 0:819c2d6a69ac | 34 | if (_y + _radius > HEIGHT - 1) _y = HEIGHT - _radius - 1; |
shalwego | 0:819c2d6a69ac | 35 | } |
shalwego | 0:819c2d6a69ac | 36 | |
shalwego | 0:819c2d6a69ac | 37 | void Pokeball::update_vol(){ |
shalwego | 0:819c2d6a69ac | 38 | _radius += 2; |
shalwego | 0:819c2d6a69ac | 39 | } |
shalwego | 0:819c2d6a69ac | 40 | |
shalwego | 0:819c2d6a69ac | 41 | void Pokeball::pokemon_caught(){ |
shalwego | 0:819c2d6a69ac | 42 | _x = 30; |
shalwego | 0:819c2d6a69ac | 43 | _y = 20 ; |
shalwego | 0:819c2d6a69ac | 44 | } |
shalwego | 0:819c2d6a69ac | 45 | |
shalwego | 0:819c2d6a69ac | 46 | Position2D Pokeball::get_pos() { return {_x,_y}; } |
shalwego | 0:819c2d6a69ac | 47 | |
shalwego | 0:819c2d6a69ac | 48 | int Pokeball::get_radius() { return _radius; } |