![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
All there but errors need fixing
Tetromino/Tetromino.cpp@4:7ddd287a5d28, 2020-05-31 (annotated)
- Committer:
- el18rs
- Date:
- Sun May 31 17:01:53 2020 +0000
- Revision:
- 4:7ddd287a5d28
- Parent:
- 3:522c6f850e91
Includes most parts but still has errors that need fixing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el18rs | 3:522c6f850e91 | 1 | #include "Tetromino.h" |
el18rs | 3:522c6f850e91 | 2 | |
el18rs | 4:7ddd287a5d28 | 3 | int tetromino[3][4][4] = { |
el18rs | 4:7ddd287a5d28 | 4 | { |
el18rs | 4:7ddd287a5d28 | 5 | {1,1,1,1}, |
el18rs | 4:7ddd287a5d28 | 6 | {1,1,1,1}, |
el18rs | 4:7ddd287a5d28 | 7 | {1,1,1,1}, |
el18rs | 4:7ddd287a5d28 | 8 | {1,1,1,1} |
el18rs | 4:7ddd287a5d28 | 9 | }, { |
el18rs | 4:7ddd287a5d28 | 10 | {1,1,1,1}, |
el18rs | 4:7ddd287a5d28 | 11 | {1,1,1,1}, |
el18rs | 4:7ddd287a5d28 | 12 | {1,1,1,1}, |
el18rs | 4:7ddd287a5d28 | 13 | {1,1,1,1} |
el18rs | 4:7ddd287a5d28 | 14 | }, { |
el18rs | 4:7ddd287a5d28 | 15 | {1,1,1,1}, |
el18rs | 4:7ddd287a5d28 | 16 | {1,1,1,1}, |
el18rs | 4:7ddd287a5d28 | 17 | {1,1,1,1}, |
el18rs | 4:7ddd287a5d28 | 18 | {1,1,1,1} |
el18rs | 4:7ddd287a5d28 | 19 | } |
el18rs | 3:522c6f850e91 | 20 | }; |
el18rs | 3:522c6f850e91 | 21 | |
el18rs | 3:522c6f850e91 | 22 | Tetromino::Tetromino() |
el18rs | 3:522c6f850e91 | 23 | { |
el18rs | 3:522c6f850e91 | 24 | |
el18rs | 3:522c6f850e91 | 25 | } |
el18rs | 3:522c6f850e91 | 26 | |
el18rs | 3:522c6f850e91 | 27 | Tetromino::~Tetromino() |
el18rs | 3:522c6f850e91 | 28 | { |
el18rs | 3:522c6f850e91 | 29 | |
el18rs | 3:522c6f850e91 | 30 | } |
el18rs | 3:522c6f850e91 | 31 | |
el18rs | 4:7ddd287a5d28 | 32 | void Tetromino::init(int number, int x, int y, int speed) |
el18rs | 3:522c6f850e91 | 33 | { |
el18rs | 3:522c6f850e91 | 34 | _x = x; |
el18rs | 4:7ddd287a5d28 | 35 | _y = y; |
el18rs | 4:7ddd287a5d28 | 36 | _speed = speed; |
el18rs | 4:7ddd287a5d28 | 37 | _number = blockArray[blocknumber]; |
el18rs | 3:522c6f850e91 | 38 | |
el18rs | 3:522c6f850e91 | 39 | |
el18rs | 4:7ddd287a5d28 | 40 | _speed = 1; |
el18rs | 4:7ddd287a5d28 | 41 | _x = WIDTH/2 - 2; |
el18rs | 4:7ddd287a5d28 | 42 | _y = HEIGHT; |
el18rs | 4:7ddd287a5d28 | 43 | |
el18rs | 4:7ddd287a5d28 | 44 | _velocity.x = speed; |
el18rs | 4:7ddd287a5d28 | 45 | _velocity.y = speed; |
el18rs | 3:522c6f850e91 | 46 | } |
el18rs | 3:522c6f850e91 | 47 | |
el18rs | 3:522c6f850e91 | 48 | void Tetromino::update(Direction d, float mag) |
el18rs | 3:522c6f850e91 | 49 | { |
el18rs | 3:522c6f850e91 | 50 | _speed = int(mag*10.0f); |
el18rs | 3:522c6f850e91 | 51 | |
el18rs | 3:522c6f850e91 | 52 | if (d == CENTRE) { |
el18rs | 3:522c6f850e91 | 53 | _y+=_speed; |
el18rs | 3:522c6f850e91 | 54 | } else if (d == S) { |
el18rs | 3:522c6f850e91 | 55 | _y+=_speed*2; |
el18rs | 3:522c6f850e91 | 56 | } else if (d == E) { |
el18rs | 3:522c6f850e91 | 57 | _x+=_speed; |
el18rs | 3:522c6f850e91 | 58 | } else if (d == W) { |
el18rs | 3:522c6f850e91 | 59 | _x-=_speed; |
el18rs | 3:522c6f850e91 | 60 | } |
el18rs | 3:522c6f850e91 | 61 | |
el18rs | 3:522c6f850e91 | 62 | if (_x < 1) { |
el18rs | 3:522c6f850e91 | 63 | _x = 1; |
el18rs | 3:522c6f850e91 | 64 | } |
el18rs | 4:7ddd287a5d28 | 65 | if (_x > WIDTH - 3) { |
el18rs | 4:7ddd287a5d28 | 66 | _x = WIDTH - 3; |
el18rs | 3:522c6f850e91 | 67 | } |
el18rs | 3:522c6f850e91 | 68 | } |
el18rs | 4:7ddd287a5d28 | 69 | |
el18rs | 4:7ddd287a5d28 | 70 | |
el18rs | 3:522c6f850e91 | 71 | Vector2D Tetromino::get_pos() { |
el18rs | 3:522c6f850e91 | 72 | Vector2D p = {_x,_y}; |
el18rs | 3:522c6f850e91 | 73 | return p; |
el18rs | 3:522c6f850e91 | 74 | } |