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
82da8a1c sago007 2015-12-19 18:00 26
#define	SAGOSPRITE_HPP
82da8a1c sago007 2015-12-19 18:00 27
82da8a1c sago007 2015-12-19 18:00 28
#include "SagoDataHolder.hpp"
82da8a1c sago007 2015-12-19 18:00 29
82da8a1c sago007 2015-12-19 18:00 30
namespace sago {
82da8a1c sago007 2015-12-19 18:00 31
2d137b45 sago007 2018-04-02 13:59 32
class SagoSprite final {
82da8a1c sago007 2015-12-19 18:00 33
public:
c6bde3e3 sago007 2015-12-22 16:56 34
	SagoSprite();
82da8a1c sago007 2015-12-19 18:00 35
	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 36
82da8a1c sago007 2015-12-19 18:00 37
	/**
82da8a1c sago007 2015-12-19 18:00 38
	 * Draws the sprite to a given render window
47fef8e8 sago007 2016-11-24 21:37 39
	 * @param target The render window to draw on
47fef8e8 sago007 2016-11-24 21:37 40
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
47fef8e8 sago007 2016-11-24 21:37 41
	 * @param x Place to draw the sprite
47fef8e8 sago007 2016-11-24 21:37 42
	 * @param y Place to draw the sprite
47fef8e8 sago007 2016-11-24 21:37 43
	 */
c6bde3e3 sago007 2015-12-22 16:56 44
	void Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y) const;
00ebd0ea sago007 2020-09-15 17:28 45
82da8a1c sago007 2015-12-19 18:00 46
	/**
82da8a1c sago007 2015-12-19 18:00 47
	 * Draws part of the sprite to a given render window
47fef8e8 sago007 2016-11-24 21:37 48
	 * @param target The render window to draw on
47fef8e8 sago007 2016-11-24 21:37 49
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
47fef8e8 sago007 2016-11-24 21:37 50
	 * @param x Place to draw the sprite
47fef8e8 sago007 2016-11-24 21:37 51
	 * @param y Place to draw the sprite
47fef8e8 sago007 2016-11-24 21:37 52
	 * @param part the part of the sprite that should be drawn. 
47fef8e8 sago007 2016-11-24 21:37 53
	 */
c6bde3e3 sago007 2015-12-22 16:56 54
	void Draw(SDL_Renderer* target, Sint32 frameTime, int x, int y, const SDL_Rect& part) const;
00ebd0ea sago007 2020-09-15 17:28 55
c6bde3e3 sago007 2015-12-22 16:56 56
	/**
c6bde3e3 sago007 2015-12-22 16:56 57
	 * Draws the wprite to the given renderer but makes sure to not draw outside th bounds given
c6bde3e3 sago007 2015-12-22 16:56 58
	 * @param target The render window to draw on
c6bde3e3 sago007 2015-12-22 16:56 59
	 * @param frameTime The time in milliseonds since gamestart. Used to determen the place in the animation
c6bde3e3 sago007 2015-12-22 16:56 60
	 * @param x Place to draw the sprite
c6bde3e3 sago007 2015-12-22 16:56 61
	 * @param y Place to draw the sprite
c6bde3e3 sago007 2015-12-22 16:56 62
	 * @param bounds A recagular area that we must not draw outside.
c6bde3e3 sago007 2015-12-22 16:56 63
	 */
00ebd0ea sago007 2020-09-15 17:28 64
	void DrawBounded(SDL_Renderer* target, Sint32 frameTime, int x, int y, const SDL_Rect& bounds) const;
00ebd0ea sago007 2020-09-15 17:28 65
	
00ebd0ea sago007 2020-09-15 17:28 66
	/**
55ea55dd sago007 2018-03-24 16:07 67
	 * Draws the sprite to a given render window
55ea55dd sago007 2018-03-24 16:07 68
	 * @param target The render window to draw on
55ea55dd sago007 2018-03-24 16:07 69
	 * @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 70
	 * @param x Place to draw the sprite
55ea55dd sago007 2018-03-24 16:07 71
	 * @param y Place to draw the sprite
55ea55dd sago007 2018-03-24 16:07 72
	 */
55ea55dd sago007 2018-03-24 16:07 73
	void DrawProgressive(SDL_Renderer* target, float progress, int x, int y) const;
68313e95 sago007 2016-09-28 16:52 74
	void DrawScaled(SDL_Renderer* target, Sint32 frameTime, int x, int y, int w, int h) const;
00ebd0ea sago007 2020-09-15 17:28 75
	
82da8a1c sago007 2015-12-19 18:00 76
	/**
82da8a1c sago007 2015-12-19 18:00 77
	 * 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
47fef8e8 sago007 2016-11-24 21:37 78
	 * @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 79
	 */
82da8a1c sago007 2015-12-19 18:00 80
	void SetOrigin(const SDL_Rect& newOrigin);
c6bde3e3 sago007 2015-12-22 16:56 81
	SagoSprite(const SagoSprite& base);
47fef8e8 sago007 2016-11-24 21:37 82
	SagoSprite& operator=(const SagoSprite& base);
1d2e2129 sago007 2015-12-23 15:41 83
	int GetWidth() const;
1d2e2129 sago007 2015-12-23 15:41 84
	int GetHeight() const;
2d137b45 sago007 2018-04-02 13:59 85
	~SagoSprite();
82da8a1c sago007 2015-12-19 18:00 86
private:
82da8a1c sago007 2015-12-19 18:00 87
	struct SagoSpriteData;
82da8a1c sago007 2015-12-19 18:00 88
	SagoSpriteData *data;
82da8a1c sago007 2015-12-19 18:00 89
};
82da8a1c sago007 2015-12-19 18:00 90
82da8a1c sago007 2015-12-19 18:00 91
}
82da8a1c sago007 2015-12-19 18:00 92
82da8a1c sago007 2015-12-19 18:00 93
#endif	/* SAGOSPRITE_HPP */
82da8a1c sago007 2015-12-19 18:00 94
1970-01-01 00:00 95