Initial publish
Dependencies: mbed
Fork of el17dg by
game/sprite.h@40:e3bbda7444fa, 2019-05-07 (annotated)
- Committer:
- Noximilien
- Date:
- Tue May 07 15:22:35 2019 +0000
- Revision:
- 40:e3bbda7444fa
- Parent:
- 37:6a2bf4488022
The Final, Submission Version. I have read and agreed to the academic integrity. SID:201160286
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Noximilien | 37:6a2bf4488022 | 1 | #ifndef SPRITE_H |
Noximilien | 37:6a2bf4488022 | 2 | #define SPRITE_H |
Noximilien | 37:6a2bf4488022 | 3 | |
Noximilien | 37:6a2bf4488022 | 4 | #include "collision_lib.h" |
Noximilien | 37:6a2bf4488022 | 5 | #include "main.h" |
Noximilien | 37:6a2bf4488022 | 6 | |
Noximilien | 37:6a2bf4488022 | 7 | /** @struct Sprite |
Noximilien | 37:6a2bf4488022 | 8 | * @brief A function to put a sprite and its data in one variable. |
Noximilien | 37:6a2bf4488022 | 9 | * @details A struct that alows to create an object containing a sprite, its width and height. |
Noximilien | 37:6a2bf4488022 | 10 | * It is used with another function located in main.h. |
Noximilien | 37:6a2bf4488022 | 11 | * @var Sprire::width . |
Noximilien | 37:6a2bf4488022 | 12 | * Member 'width' contains witdh of the sprite. |
Noximilien | 37:6a2bf4488022 | 13 | * @var Sprire::height. |
Noximilien | 37:6a2bf4488022 | 14 | * Member 'height' contains height of the sprite. |
Noximilien | 37:6a2bf4488022 | 15 | * @var Sprire::data. |
Noximilien | 37:6a2bf4488022 | 16 | * Member 'data' contains the array of 1s and 0s of the sprite. |
Noximilien | 37:6a2bf4488022 | 17 | */ |
Noximilien | 37:6a2bf4488022 | 18 | struct Sprite { |
Noximilien | 37:6a2bf4488022 | 19 | /*@{*/ |
Noximilien | 37:6a2bf4488022 | 20 | Sprite(int _width, int _height, const int* _data) : width(_width), height(_height), data(_data) {} |
Noximilien | 37:6a2bf4488022 | 21 | int width; /**< The width of the sprite*/ |
Noximilien | 37:6a2bf4488022 | 22 | int height; /**< The height of the sprite*/ |
Noximilien | 37:6a2bf4488022 | 23 | const int* data; /**< The array of 1s and 0s of the sprite.*/ |
Noximilien | 37:6a2bf4488022 | 24 | }; |
Noximilien | 37:6a2bf4488022 | 25 | |
Noximilien | 37:6a2bf4488022 | 26 | /** |
Noximilien | 37:6a2bf4488022 | 27 | * @brief A simplified function to draw sprites. |
Noximilien | 37:6a2bf4488022 | 28 | * @details This is a specific function I made to simplify drawing the sprites. |
Noximilien | 37:6a2bf4488022 | 29 | * It only works with spawn() function in gameobject.h. |
Noximilien | 37:6a2bf4488022 | 30 | * The parameters for this function are given in the models.cpp for the |
Noximilien | 37:6a2bf4488022 | 31 | * sprites. |
Noximilien | 37:6a2bf4488022 | 32 | */ |
Noximilien | 37:6a2bf4488022 | 33 | static void drawSprite(Point pos, const Sprite& sprite) { |
Noximilien | 37:6a2bf4488022 | 34 | lcd.drawSprite(pos.x, pos.y, sprite.height, sprite.width, (int*)sprite.data); |
Noximilien | 37:6a2bf4488022 | 35 | } |
Noximilien | 37:6a2bf4488022 | 36 | |
Noximilien | 37:6a2bf4488022 | 37 | /** |
Noximilien | 37:6a2bf4488022 | 38 | * @brief A simplified function to draw sprites. But this draw black pixels on top of white pixels. |
Noximilien | 37:6a2bf4488022 | 39 | * @details This is an exactly the same function as before, but for the drawing |
Noximilien | 37:6a2bf4488022 | 40 | * sprite function that draws the black pixels on top the white pixels when the |
Noximilien | 37:6a2bf4488022 | 41 | * sprites overlap. |
Noximilien | 37:6a2bf4488022 | 42 | */ |
Noximilien | 37:6a2bf4488022 | 43 | static void drawSpriteOnTop(Point pos, const Sprite& sprite) { |
Noximilien | 37:6a2bf4488022 | 44 | lcd.drawSpriteOnTop(pos.x, pos.y, sprite.height, sprite.width, (int*)sprite.data); |
Noximilien | 37:6a2bf4488022 | 45 | } |
Noximilien | 37:6a2bf4488022 | 46 | |
Noximilien | 37:6a2bf4488022 | 47 | #endif |