![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
All there but errors need fixing
Tetromino/Tetromino.cpp@3:522c6f850e91, 2020-05-24 (annotated)
- Committer:
- el18rs
- Date:
- Sun May 24 11:18:33 2020 +0000
- Revision:
- 3:522c6f850e91
- Child:
- 4:7ddd287a5d28
Game engine added
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 | 3:522c6f850e91 | 3 | const int ISprite[4][4] = { |
el18rs | 3:522c6f850e91 | 4 | {0,0,1,0,}, |
el18rs | 3:522c6f850e91 | 5 | {0,0,1,0,}, |
el18rs | 3:522c6f850e91 | 6 | {0,0,1,0,}, |
el18rs | 3:522c6f850e91 | 7 | {0,0,1,0,}, |
el18rs | 3:522c6f850e91 | 8 | }; |
el18rs | 3:522c6f850e91 | 9 | |
el18rs | 3:522c6f850e91 | 10 | const int L0Sprite[4][4] = { |
el18rs | 3:522c6f850e91 | 11 | {0,1,0,0,}, |
el18rs | 3:522c6f850e91 | 12 | {0,1,0,0,}, |
el18rs | 3:522c6f850e91 | 13 | {0,1,1,0,}, |
el18rs | 3:522c6f850e91 | 14 | {0,0,0,0,}, |
el18rs | 3:522c6f850e91 | 15 | }; |
el18rs | 3:522c6f850e91 | 16 | |
el18rs | 3:522c6f850e91 | 17 | const int Z0Sprite[4][4] = { |
el18rs | 3:522c6f850e91 | 18 | {0,1,0,0,}, |
el18rs | 3:522c6f850e91 | 19 | {0,1,1,0,}, |
el18rs | 3:522c6f850e91 | 20 | {0,0,1,0,}, |
el18rs | 3:522c6f850e91 | 21 | {0,0,0,0,}, |
el18rs | 3:522c6f850e91 | 22 | }; |
el18rs | 3:522c6f850e91 | 23 | |
el18rs | 3:522c6f850e91 | 24 | const int OSprite[4][4] = { |
el18rs | 3:522c6f850e91 | 25 | {0,0,0,0,}, |
el18rs | 3:522c6f850e91 | 26 | {0,1,1,0,}, |
el18rs | 3:522c6f850e91 | 27 | {0,1,1,0,}, |
el18rs | 3:522c6f850e91 | 28 | {0,0,0,0,}, |
el18rs | 3:522c6f850e91 | 29 | }; |
el18rs | 3:522c6f850e91 | 30 | |
el18rs | 3:522c6f850e91 | 31 | const int TSprite[4][4] = { |
el18rs | 3:522c6f850e91 | 32 | {0,1,0,0,}, |
el18rs | 3:522c6f850e91 | 33 | {0,1,1,0,}, |
el18rs | 3:522c6f850e91 | 34 | {0,1,0,0,}, |
el18rs | 3:522c6f850e91 | 35 | {0,0,0,0,}, |
el18rs | 3:522c6f850e91 | 36 | }; |
el18rs | 3:522c6f850e91 | 37 | |
el18rs | 3:522c6f850e91 | 38 | const int L1Sprite[4][4] = { |
el18rs | 3:522c6f850e91 | 39 | {0,0,1,0,}, |
el18rs | 3:522c6f850e91 | 40 | {0,0,1,0,}, |
el18rs | 3:522c6f850e91 | 41 | {0,1,1,0,}, |
el18rs | 3:522c6f850e91 | 42 | {0,0,0,0,}, |
el18rs | 3:522c6f850e91 | 43 | }; |
el18rs | 3:522c6f850e91 | 44 | |
el18rs | 3:522c6f850e91 | 45 | const int Z1Sprite[4][4] = { |
el18rs | 3:522c6f850e91 | 46 | {0,0,1,0,}, |
el18rs | 3:522c6f850e91 | 47 | {0,1,1,0,}, |
el18rs | 3:522c6f850e91 | 48 | {0,1,0,0,}, |
el18rs | 3:522c6f850e91 | 49 | {0,0,0,0,}, |
el18rs | 3:522c6f850e91 | 50 | }; |
el18rs | 3:522c6f850e91 | 51 | |
el18rs | 3:522c6f850e91 | 52 | Tetromino::Tetromino() |
el18rs | 3:522c6f850e91 | 53 | { |
el18rs | 3:522c6f850e91 | 54 | |
el18rs | 3:522c6f850e91 | 55 | } |
el18rs | 3:522c6f850e91 | 56 | |
el18rs | 3:522c6f850e91 | 57 | Tetromino::~Tetromino() |
el18rs | 3:522c6f850e91 | 58 | { |
el18rs | 3:522c6f850e91 | 59 | |
el18rs | 3:522c6f850e91 | 60 | } |
el18rs | 3:522c6f850e91 | 61 | |
el18rs | 3:522c6f850e91 | 62 | void Tetromino::init(int x, int height, int width) |
el18rs | 3:522c6f850e91 | 63 | { |
el18rs | 3:522c6f850e91 | 64 | _x = x; |
el18rs | 3:522c6f850e91 | 65 | _y = HEIGHT/2 - height/2; |
el18rs | 3:522c6f850e91 | 66 | _height = height; |
el18rs | 3:522c6f850e91 | 67 | _width = width; |
el18rs | 3:522c6f850e91 | 68 | _speed = 1; |
el18rs | 3:522c6f850e91 | 69 | |
el18rs | 3:522c6f850e91 | 70 | } |
el18rs | 3:522c6f850e91 | 71 | |
el18rs | 3:522c6f850e91 | 72 | |
el18rs | 3:522c6f850e91 | 73 | |
el18rs | 3:522c6f850e91 | 74 | void Tetromino::draw(N5110 &lcd, int x) |
el18rs | 3:522c6f850e91 | 75 | { |
el18rs | 3:522c6f850e91 | 76 | int shape = rand() % 6; |
el18rs | 3:522c6f850e91 | 77 | |
el18rs | 3:522c6f850e91 | 78 | if (shape == 0) { |
el18rs | 3:522c6f850e91 | 79 | lcd.drawSprite(_x, _y, 4, 4, (int*)ISprite); /*_shape_type = 0;*/ |
el18rs | 3:522c6f850e91 | 80 | } else if (shape == 1) { |
el18rs | 3:522c6f850e91 | 81 | lcd.drawSprite(_x, _y, 4, 4, (int*)L0Sprite); /*_shape_type = 1;*/ |
el18rs | 3:522c6f850e91 | 82 | } else if (shape == 2) { |
el18rs | 3:522c6f850e91 | 83 | lcd.drawSprite(_x, _y, 4, 4, (int*)Z0Sprite); /*_shape_type = 2;*/ |
el18rs | 3:522c6f850e91 | 84 | } else if (shape == 3) { |
el18rs | 3:522c6f850e91 | 85 | lcd.drawSprite(_x, _y, 4, 4, (int*)OSprite); /*_shape_type = 3;*/ |
el18rs | 3:522c6f850e91 | 86 | } else if (shape == 4) { |
el18rs | 3:522c6f850e91 | 87 | lcd.drawSprite(_x, _y, 4, 4, (int*)TSprite); /*_shape_type = 4;*/ |
el18rs | 3:522c6f850e91 | 88 | } else if (shape == 5) { |
el18rs | 3:522c6f850e91 | 89 | lcd.drawSprite(_x, _y, 4, 4, (int*)L1Sprite); /*_shape_type = 5;*/ |
el18rs | 3:522c6f850e91 | 90 | } else if (shape == 6) { |
el18rs | 3:522c6f850e91 | 91 | lcd.drawSprite(_x, _y, 4, 4, (int*)Z1Sprite); /*_shape_type = 6;*/ |
el18rs | 3:522c6f850e91 | 92 | } |
el18rs | 3:522c6f850e91 | 93 | // return _shape_type; |
el18rs | 3:522c6f850e91 | 94 | } |
el18rs | 3:522c6f850e91 | 95 | |
el18rs | 3:522c6f850e91 | 96 | |
el18rs | 3:522c6f850e91 | 97 | |
el18rs | 3:522c6f850e91 | 98 | |
el18rs | 3:522c6f850e91 | 99 | |
el18rs | 3:522c6f850e91 | 100 | void Tetromino::update(Direction d, float mag) |
el18rs | 3:522c6f850e91 | 101 | { |
el18rs | 3:522c6f850e91 | 102 | _speed = int(mag*10.0f); |
el18rs | 3:522c6f850e91 | 103 | |
el18rs | 3:522c6f850e91 | 104 | if (d == CENTRE) { |
el18rs | 3:522c6f850e91 | 105 | _y+=_speed; |
el18rs | 3:522c6f850e91 | 106 | } else if (d == S) { |
el18rs | 3:522c6f850e91 | 107 | _y+=_speed*2; |
el18rs | 3:522c6f850e91 | 108 | } else if (d == E) { |
el18rs | 3:522c6f850e91 | 109 | _x+=_speed; |
el18rs | 3:522c6f850e91 | 110 | } else if (d == W) { |
el18rs | 3:522c6f850e91 | 111 | _x-=_speed; |
el18rs | 3:522c6f850e91 | 112 | } |
el18rs | 3:522c6f850e91 | 113 | |
el18rs | 3:522c6f850e91 | 114 | if (_x < 1) { |
el18rs | 3:522c6f850e91 | 115 | _x = 1; |
el18rs | 3:522c6f850e91 | 116 | } |
el18rs | 3:522c6f850e91 | 117 | if (_x > WIDTH - _width - 1) { |
el18rs | 3:522c6f850e91 | 118 | _x = WIDTH - _width - 1; |
el18rs | 3:522c6f850e91 | 119 | } |
el18rs | 3:522c6f850e91 | 120 | } |
el18rs | 3:522c6f850e91 | 121 | Vector2D Tetromino::get_pos() { |
el18rs | 3:522c6f850e91 | 122 | Vector2D p = {_x,_y}; |
el18rs | 3:522c6f850e91 | 123 | return p; |
el18rs | 3:522c6f850e91 | 124 | } |