File: blast.d

package info (click to toggle)
projectl 1.001.dfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,720 kB
  • ctags: 5
  • sloc: xml: 57; makefile: 32
file content (177 lines) | stat: -rw-r--r-- 3,809 bytes parent folder | download | duplicates (3)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
module br.blast;

private import std.math;
private import opengl;
private import util.log;

public class Blast{
	public real x,y;
	public real width ,height;
	public real scale;
	public int count;
	public int span;
	public real R ,G ,B;
	public double alpha;
	private bool _exists;
	
	public this(real x,real y,real width ,real height ,int span ,real R ,real G ,real B ,real alpha){
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.span = span;
		this.scale = 1.0;
		this.count = 0;
		this.R = R; this.G = G; this.B = B;
		this.alpha = alpha;
		this._exists = true;
		blastManager.add(this);
	}
	
	
	public void run(){
//		Log_write("dddd");
		
		if(span - 30 <= count){
			alpha *= 0.9;
			if(span <= count)vanish();
		}else scale *= 1.1;
		count ++;
	}
	
	public void draw(){
//		Log_write("vvvv");
		glPushMatrix();
		glEnable(GL_BLEND);
		
		glTranslatef(x ,y ,-800);
		
		glBegin(GL_POLYGON);
		
		glColor4f(R ,G ,B ,alpha);
		for(int i=0;i<32;i++){
			glVertex3f(scale * width * cos(cast(real)i / 32.0 * PI * 2.0) ,scale * height * sin(cast(real)i / 32.0 * PI * 2.0) ,0.0);
		}
		//glVertex3f(width ,height ,0.0);
		glEnd();
		
		glDisable(GL_BLEND);
		glPopMatrix();
	}
	
	public bool exists(){
		return _exists;
	}
	public void vanish(){
		_exists = false;
	}
}
public class Blast2:Blast{
	double baseAlpha;
	public this(real x,real y,real width ,real height ,int span ,real R ,real G ,real B ,real alpha){
		super(x ,y ,width ,height ,span ,R ,G ,B ,alpha);
		this.baseAlpha = alpha;
	}
	public override void run(){
		if(span - 120 <= count){
			alpha *= 0.98;
			if(span <= count)vanish();
		}else{
			scale *= 1.1;
			alpha = baseAlpha * (1.0 - cast(double)(span - 120 - count) / cast(double)(span - 120));
		}
		count ++;
		
	}
}
public class SmallBlast:Blast{
	private real targetScale;
	private real dScale;
	public this(real x,real y,real width ,real height ,real targetScale ,int span ,real R ,real G ,real B ,real alpha){
		super(x ,y ,width ,height ,span ,R ,G ,B ,alpha);
		this.targetScale = targetScale;
		this.dScale = (this.targetScale - this.scale) / (span * 2/ 3);
	}
	public override void run(){
		if(span * 2 / 3<= count){
			scale = targetScale;
			alpha *= 0.9;
			if(span <= count)vanish();
		}else scale += dScale;
		count ++;
	}
}
public BlastManager blastManager;
public class BlastManager{
		public:
	Blast[] blasts;
	//List!(Parts) parts;
	protected:
	//List!(int) van = new List!(int)();
  int blastIdx = 0;
	const int maxBlast;
	public this() {
		maxBlast = 16;
		blasts.length = maxBlast;
		//parts = new List!(Parts)();
		blastIdx = 0;
	}

  public this(int n) {
		maxBlast = n;
		blasts.length = maxBlast;
		//parts = new List!(Parts)();
		blastIdx = 0;
  }

	public bool add(Blast a){
		for(int i = 0;i < blasts.length;i ++){
			if(blasts[blastIdx] is null || !blasts[blastIdx].exists()){
				blasts[blastIdx] = a;
				return true;
			}
			blastIdx ++;
			if(blasts.length <= blastIdx)blastIdx = 0;
		}
		return false;
		//if(maxParts <= parts.size)return false;
		//parts.push_back(p);
		
	}
	public void run() {
		
		for (int i = 0;i < blasts.length;i ++){
			Blast an = blasts[i];
      if (an !is null && an.exists){
				
        an.run();
				if(an.exists == false)an = null;
      }else{
				//van.push_back(i);
      }
    }
		
		
  }
  public void draw() {
		
		for (int i = 0;i < blasts.length;i ++){
			Blast an = blasts[i];
			if (an !is null && an.exists){
				an.draw();
			}
		}
  }


  public void clear() {
		foreach(ref Blast a;blasts){
			if(a !is null && a.exists){
				a.vanish();
			}
		}
   	//parts.length = 0;
    blastIdx = 0;
  }
}