git repos / blockattack-game

blame: source/code/sago/SagoSprite.hpp

normal view · raw

82da8a1c sago007 2015-12-19 18:00 1
/*
47fef8e8 sago007 2016-11-24 21:37 2
Copyright (c) 2015 Poul Sander
82da8a1c sago007 2015-12-19 18:00 3
47fef8e8 sago007 2016-11-24 21:37 4
Permission is hereby granted, free of charge, to any person
47fef8e8 sago007 2016-11-24 21:37 5
obtaining a copy of this software and associated documentation files
47fef8e8 sago007 2016-11-24 21:37 6
(the "Software"), to deal in the Software without restriction,
47fef8e8 sago007 2016-11-24 21:37 7
including without limitation the rights to use, copy, modify, merge,
47fef8e8 sago007 2016-11-24 21:37 8
publish, distribute, sublicense, and/or sell copies of the Software,
47fef8e8 sago007 2016-11-24 21:37 9
and to permit persons to whom the Software is furnished to do so,
47fef8e8 sago007 2016-11-24 21:37 10
subject to the following conditions:
82da8a1c sago007 2015-12-19 18:00 11
47fef8e8 sago007 2016-11-24 21:37 12
The above copyright notice and this permission notice shall be
47fef8e8 sago007 2016-11-24 21:37 13
included in all copies or substantial portions of the Software.
82da8a1c sago007 2015-12-19 18:00 14
47fef8e8 sago007 2016-11-24 21:37 15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
47fef8e8 sago007 2016-11-24 21:37 16
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47fef8e8 sago007 2016-11-24 21:37 17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
47fef8e8 sago007 2016-11-24 21:37 18
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
47fef8e8 sago007 2016-11-24 21:37 19
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
47fef8e8 sago007 2016-11-24 21:37 20
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
47fef8e8 sago007 2016-11-24 21:37 21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
47fef8e8 sago007 2016-11-24 21:37 22
SOFTWARE.
82da8a1c sago007 2015-12-19 18:00 23
*/
82da8a1c sago007 2015-12-19 18:00 24
82da8a1c sago007 2015-12-19 18:00 25
#ifndef SAGOSPRITE_HPP
e94af580 sago007 2020-12-30 17:45 26
#define SAGOSPRITE_HPP
82da8a1c sago007 2015-12-19 18:00 27
82da8a1c sago007 2015-12-19 18:00 28
#include "SagoDataHolder.hpp"
62b87fe3 Poul Sander 2025-03-04 20:16 29
#include "SagoLogicalResize.hpp"
82da8a1c sago007 2015-12-19 18:00 30
82da8a1c sago007 2015-12-19 18:00 31
namespace sago {
82da8a1c sago007 2015-12-19 18:00 32
2d137b45 sago007 2018-04-02 13:59 33
class SagoSprite final {
82da8a1c sago007 2015-12-19 18:00 34
public:
c6bde3e3 sago007 2015-12-22 16:56 35
	SagoSprite();
e94af580 sago007 2020-12-30 17:45 36
	SagoSprite(const SagoDataHolder& texHolder, const std::string& texture,const SDL_Rect& initImage,const int animationFrames, const int animationFrameLength);
00ebd0ea sago007 2020-09-15 17:28 37
82da8a1c sago007 2015-12-19 18:00 38
	/**
82da8a1c sago007 2015-12-19 18:00 39
	 * Draws the sprite to a given render window
47fef8e8 sago007 2016-11-24 21:37 40
	 * @param target The render window to draw on
47fef8e8 sago007 2016-11-24 21:37 41
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
47fef8e8 sago007 2016-11-24 21:37 42
	 * @param x Place to draw the sprite
47fef8e8 sago007 2016-11-24 21:37 43
	 * @param y Place to draw the sprite
47fef8e8 sago007 2016-11-24 21:37 44
	 */
62b87fe3 Poul Sander 2025-03-04 20:16 45
	void Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y, SagoLogicalResize* resize = nullptr) const;
00ebd0ea sago007 2020-09-15 17:28 46
82da8a1c sago007 2015-12-19 18:00 47
	/**
84b6e374 sago007 2020-09-15 18:13 48
	 * Draws the sprite to a given render window
84b6e374 sago007 2020-09-15 18:13 49
	 * @param target The render window to draw on
84b6e374 sago007 2020-09-15 18:13 50
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
84b6e374 sago007 2020-09-15 18:13 51
	 * @param x Place to draw the sprite
84b6e374 sago007 2020-09-15 18:13 52
	 * @param y Place to draw the sprite
84b6e374 sago007 2020-09-15 18:13 53
	 * @param angleRadian Angle to rotate the sprite around origin before drawing
84b6e374 sago007 2020-09-15 18:13 54
	 */
62b87fe3 Poul Sander 2025-03-04 20:16 55
	void DrawRotated(SDL_Renderer* target, Sint32 frameTime, int x, int y, const double angleRadian, SagoLogicalResize* resize = nullptr) const;
84b6e374 sago007 2020-09-15 18:13 56
84b6e374 sago007 2020-09-15 18:13 57
	/**
82da8a1c sago007 2015-12-19 18:00 58
	 * Draws part of the sprite to a given render window
47fef8e8 sago007 2016-11-24 21:37 59
	 * @param target The render window to draw on
47fef8e8 sago007 2016-11-24 21:37 60
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
47fef8e8 sago007 2016-11-24 21:37 61
	 * @param x Place to draw the sprite
47fef8e8 sago007 2016-11-24 21:37 62
	 * @param y Place to draw the sprite
e94af580 sago007 2020-12-30 17:45 63
	 * @param part the part of the sprite that should be drawn.
47fef8e8 sago007 2016-11-24 21:37 64
	 */
62b87fe3 Poul Sander 2025-03-04 20:16 65
	void Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y, const SDL_Rect& part, SagoLogicalResize* resize = nullptr) const;
00ebd0ea sago007 2020-09-15 17:28 66
c6bde3e3 sago007 2015-12-22 16:56 67
	/**
c6bde3e3 sago007 2015-12-22 16:56 68
	 * Draws the wprite to the given renderer but makes sure to not draw outside th bounds given
c6bde3e3 sago007 2015-12-22 16:56 69
	 * @param target The render window to draw on
c6bde3e3 sago007 2015-12-22 16:56 70
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
c6bde3e3 sago007 2015-12-22 16:56 71
	 * @param x Place to draw the sprite
c6bde3e3 sago007 2015-12-22 16:56 72
	 * @param y Place to draw the sprite
c6bde3e3 sago007 2015-12-22 16:56 73
	 * @param bounds A recagular area that we must not draw outside.
c6bde3e3 sago007 2015-12-22 16:56 74
	 */
62b87fe3 Poul Sander 2025-03-04 20:16 75
	void DrawBounded(SDL_Renderer* target, Sint32 frameTime, int x, int y, const SDL_Rect& bounds, SagoLogicalResize* resize = nullptr) const;
e94af580 sago007 2020-12-30 17:45 76
00ebd0ea sago007 2020-09-15 17:28 77
	/**
55ea55dd sago007 2018-03-24 16:07 78
	 * Draws the sprite to a given render window
55ea55dd sago007 2018-03-24 16:07 79
	 * @param target The render window to draw on
55ea55dd sago007 2018-03-24 16:07 80
	 * @param progress A float with value from 0.0f to 1.0f. Tells how far in the animation that we got
55ea55dd sago007 2018-03-24 16:07 81
	 * @param x Place to draw the sprite
55ea55dd sago007 2018-03-24 16:07 82
	 * @param y Place to draw the sprite
55ea55dd sago007 2018-03-24 16:07 83
	 */
62b87fe3 Poul Sander 2025-03-04 20:16 84
	void DrawProgressive(SDL_Renderer* target, float progress, int x, int y, SagoLogicalResize* resize = nullptr) const;
84b6e374 sago007 2020-09-15 18:13 85
62b87fe3 Poul Sander 2025-03-04 20:16 86
	void DrawScaled(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h, SagoLogicalResize* resize = nullptr) const;
84b6e374 sago007 2020-09-15 18:13 87
	void DrawScaledAndRotated(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h,
62b87fe3 Poul Sander 2025-03-04 20:16 88
	                          const double angleRadian, const SDL_Point* center, const SDL_RendererFlip flip, SagoLogicalResize* resize = nullptr) const;
84b6e374 sago007 2020-09-15 18:13 89
82da8a1c sago007 2015-12-19 18:00 90
	/**
82da8a1c sago007 2015-12-19 18:00 91
	 * Set a different origin. Normally it is the top left cornor. But in some cases you might want to center the origin or tranform it for other reasons
e94af580 sago007 2020-12-30 17:45 92
	 * @param newOrigin the coordinates that should be the new origin. Call with {0,0} to reset to default
47fef8e8 sago007 2016-11-24 21:37 93
	 */
82da8a1c sago007 2015-12-19 18:00 94
	void SetOrigin(const SDL_Rect& newOrigin);
59365d69 Poul Sander 2025-05-25 12:06 95
	SagoSprite(const SagoSprite& base) = default;
59365d69 Poul Sander 2025-05-25 12:06 96
	SagoSprite& operator=(const SagoSprite& base) = default;
1d2e2129 sago007 2015-12-23 15:41 97
	int GetWidth() const;
1d2e2129 sago007 2015-12-23 15:41 98
	int GetHeight() const;
59365d69 Poul Sander 2025-05-25 12:06 99
	~SagoSprite() = default;
59365d69 Poul Sander 2025-05-25 12:06 100
59365d69 Poul Sander 2025-05-25 12:06 101
	TextureHandler tex;
59365d69 Poul Sander 2025-05-25 12:06 102
	SDL_Rect imgCord = {};
59365d69 Poul Sander 2025-05-25 12:06 103
	SDL_Rect origin = {};
59365d69 Poul Sander 2025-05-25 12:06 104
	int aniFrames = 0;
59365d69 Poul Sander 2025-05-25 12:06 105
	int aniFrameTime = 0;
82da8a1c sago007 2015-12-19 18:00 106
};
82da8a1c sago007 2015-12-19 18:00 107
82da8a1c sago007 2015-12-19 18:00 108
}
82da8a1c sago007 2015-12-19 18:00 109
e94af580 sago007 2020-12-30 17:45 110
#endif  /* SAGOSPRITE_HPP */
82da8a1c sago007 2015-12-19 18:00 111
1970-01-01 00:00 112