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