File: ExplosionManager.hpp

package info (click to toggle)
blockattack 2.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,292 kB
  • sloc: cpp: 93,645; sh: 143; pascal: 111; xml: 82; makefile: 14
file content (109 lines) | stat: -rw-r--r-- 2,649 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
===========================================================================
blockattack - Block Attack - Rise of the Blocks
Copyright (C) 2005-2017 Poul Sander

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see http://www.gnu.org/licenses/

Source information and contacts persons can be found at
http://www.blockattack.net
===========================================================================
*/

#ifndef EXPLOSIONMANAGER_HPP
#define EXPLOSIONMANAGER_HPP

#include <array>

//a explosions, non moving
class AnExplosion {
private:
	int x = 0;
	int y = 0;
	Uint8 frameNumber = 0;
#define frameLength 80
	//How long an image in an animation should be showed
#define maxFrame 4
	//How many images there are in the animation
	unsigned long int placeTime = 0; //Then the explosion occored
public:
	bool inUse = false;

	AnExplosion() {
	}

	//constructor:
	AnExplosion(int X, int Y) {
		placeTime = SDL_GetTicks();
		x = X;
		y = Y;
		frameNumber=0;
	}  //constructor

	//true if animation has played and object should be removed from the screen
	bool removeMe() {
		frameNumber = (SDL_GetTicks()-placeTime)/frameLength;
		return (!(frameNumber<maxFrame));
	}

	int getX() {
		return (int)x;
	}

	int getY() {
		return (int)y;
	}

	int getFrame() {
		return frameNumber;
	}
};  //nExplosion

class ExplosionManager {
	static const int maxNumberOfExplosions = 6*12*2*2;
public:
	std::array<AnExplosion, maxNumberOfExplosions> explosionArray;

	ExplosionManager() {
	}

	int addExplosion(int x, int y) {
		size_t explosionNumber = 0;
		while ( explosionNumber<explosionArray.size() && explosionArray[explosionNumber].inUse) {
			explosionNumber++;
		}
		if (explosionNumber==explosionArray.size()) {
			return -1;
		}
		explosionArray[explosionNumber] = AnExplosion(x,y);
		explosionArray[explosionNumber].inUse = true;
		return 1;
	}  //addBall

	void update() {
		for (size_t i = 0; i<explosionArray.size(); i++) {

			if (explosionArray[i].inUse) {
				if (explosionArray[i].removeMe()) {
					explosionArray[i].inUse = false;
				}
			}
		}
	} //update


}; //explosionManager

#endif /* EXPLOSIONMANAGER_HPP */