File: gun_saber.cpp

package info (click to toggle)
rafkill 1.2.2-4
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,268 kB
  • ctags: 5,074
  • sloc: cpp: 13,508; makefile: 64; sh: 14
file content (138 lines) | stat: -rw-r--r-- 2,856 bytes parent folder | download | duplicates (12)
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
#include "gun_saber.h"
#include "trigtable.h"
#include "gunobj.h"
#include "hulls/hull_weapon_saber.h"
#include "weapons/weapon_beam.h"
#include "spaceobj.h"
#include "ebox.h"
#include <vector>

using namespace std;

static const int MAX_GLOW_SHADE = 15;

saber_point::saber_point() {
	distance = 0;
}

WeaponSaber::WeaponSaber( int z, int d, int smp, int al ):
WeaponObject( d, "Saber Gun", 285000, al, z, 0 ),
rising( 0 ) {

	shade = new int[ MAX_GLOW_SHADE ];
	min_color_r = 80;
	min_color_g = 80;
	shooting = false;

}


WeaponObject * WeaponSaber::copy() {
	return new WeaponSaber( strength, dir, smp, alignment );
}


WeaponSaber::~WeaponSaber() {
	delete[] shade;
}


void WeaponSaber::MakeShot(int x, int y, vector< SpaceObject * > * Ammo, const vector< SpaceObject * > * fight ) {

	shot_counter = 0;

	if ( shooting ) {

		fat += 2;
		if ( fat >= rising / 3 ) {
			shooting = false;
			rising = 0;
		}

		int ff = rising/3 - abs(fat) + 1;
		Ammo->push_back( new Beam(x,y-240,0,0,1, new Saber_WHull(ff/2,ff*2,480), alignment ) );

		return;

	}

	if ( rising < 200 )
		rising++;

}


void WeaponSaber::Idle( int x, int y, vector< SpaceObject * > * Ammo, const vector< SpaceObject * > * fight ) {
	if ( shooting ) {

		fat += 2;
		if ( fat >= rising / 3 ) {
			shooting = false;
			rising = 0;
		}

		int ff = rising/3 - abs(fat) + 1;
		Ammo->push_back( new Beam(x,y-240,0,0,1, new Saber_WHull(ff/2,ff*2,480), alignment ) );

		return;

	}

	if ( rising == 0 ) return;
	min_color_r = 80;
	min_color_g = 80;

	shooting = true;
	fat = 1;

}


void WeaponSaber::Draw( const Bitmap & less, int x, int y) {

	if ( rising == 0 ) return;

	int ry = y - 25;

	for ( int q = 0; q < MAX_GLOW_SHADE; q++ ){
		shade[q] = Bitmap::addColor( shade[q], Bitmap::makeColor( 6, 6, 7 ) );
	}

	min_color_r++;
	min_color_g++;

	if ( min_color_r > 255 ) min_color_r = 255;
	if ( min_color_g > 255 ) min_color_g = 255;

	Util::blend_palette( shade, MAX_GLOW_SHADE, Bitmap::makeColor(250,250,0), Bitmap::makeColor(min_color_r, min_color_g, 0 ) );

	//circlefill( less, x, ry, rising/30 + 3, makecol( 255, 250, 0 ) );
	for ( int q = MAX_GLOW_SHADE-1; q >= 0; q-- ){
		less.circleFill( x, ry, (int)((double)q*(double)rising/100.0), shade[q] );
	}

	int g = Util::rnd( MAX_GLOW );
	if ( glow[ g ].distance <= 0 ) {
		glow[ g ].distance = Util::rnd( 9 ) + (double)rising/3.0;
		glow[ g ].ang = Util::rnd( 360 );
	}

	for ( int q = 0; q < MAX_GLOW; q++ ){
		if ( glow[q].distance > 0 ) {

			int rad = (int)( 20.0 / (fabs(glow[q].distance)+1) + 1 );

			if ( rad > 4 ) rad = 4;

			int cx = (int)(x+Tcos(glow[q].ang)*glow[q].distance);
			int cy = (int)(ry+Tsine(glow[q].ang)*glow[q].distance);
			int color = Bitmap::makeColor( (int)(250-glow[q].distance*3),(int)(250-glow[q].distance*3), 0);

			less.circleFill( cx, cy, rad, color );

			glow[q].distance -= 1.8;

		}
	}

}