-
Notifications
You must be signed in to change notification settings - Fork 0
/
laser.c
130 lines (117 loc) · 2.83 KB
/
laser.c
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
/*
* $Id: laser.c 264 2005-11-06 17:43:44Z mrbrown $
*
* Copyright 2003 Kenta Cho. All rights reserved.
*/
/**
* Handle players laser.
*
* @version $Revision: 264 $
*/
#include "SDL.h"
#include "genmcr.h"
#include "screen.h"
#include "vector.h"
#include "degutil.h"
#include "laser.h"
#include "ship.h"
#include "frag.h"
#include "boss_mtd.h"
#define LASER_MAX 64
#define LASER_SPEED 4096
#define LASER_WIDTH 4800
#define LASER_WIDTH_ADD 480
Laser laser[LASER_MAX];
static int laserWidth, laserCnt;
void initLasers() {
int i;
for ( i=0 ; i<LASER_MAX ; i++ ) {
laser[i].cnt = NOT_EXIST;
}
laserWidth = laserCnt = 0;
}
#define LASER_COLOR_SPEED 12
static int laserIdx = LASER_MAX;
static int laserColor = 0;
static int laserAdded = 0;
void addLaser() {
int i;
for ( i=0 ; i<LASER_MAX ; i++ ) {
laserIdx--; if ( laserIdx < 0 ) laserIdx = LASER_MAX-1;
if ( laser[laserIdx].cnt == NOT_EXIST ) break;
}
if ( i >= LASER_MAX ) return;
laser[laserIdx].y = LASER_SPEED;
laser[laserIdx].color = laserColor;
laserColor -= LASER_COLOR_SPEED; laserColor &= 255;
laser[laserIdx].cnt = 0;
laserWidth += LASER_WIDTH_ADD;
if ( laserWidth > LASER_WIDTH ) laserWidth = LASER_WIDTH;
laserAdded = 1;
}
void moveLasers() {
int i;
Laser *ls;
int ry;
int huy, hdy;
if ( !laserAdded ) {
laserWidth -= LASER_WIDTH_ADD;
if ( laserWidth < 0 ) {
laserWidth = 0;
for ( i=0 ; i<LASER_MAX ; i++ ) {
laser[i].cnt = NOT_EXIST;
}
return;
}
} else {
laserAdded = 0;
}
hdy = checkHitDownside(ship.pos.x);
huy = checkHitUpside();
for ( i=0 ; i<LASER_MAX ; i++ ) {
if ( laser[i].cnt == NOT_EXIST ) continue;
else if ( laser[i].cnt == -1 ) {
laser[i].cnt = NOT_EXIST;
continue;
}
ls = &(laser[i]);
ls->y -= LASER_SPEED;
ry = ship.pos.y + ls->y;
if ( huy < ry && ry < hdy ) {
damageBossLaser(ls->cnt);
if ( (laserCnt&3) == 0 ) {
addLaserFrag(ship.pos.x, -ship.pos.y-ls->y, LASER_WIDTH);
}
ls->cnt = -1;
continue;
}
if ( ry < -FIELD_HEIGHT_8/2 ) {
ls->cnt = NOT_EXIST;
continue;
}
ls->cnt++;
}
laserCnt++;
}
#define LASER_SCREEN_HEIGHT (LASER_SPEED/FIELD_SCREEN_RATIO)
void drawLasers() {
float x, y;
int i;
Laser *ls;
int t;
for ( i=0 ; i<LASER_MAX ; i++ ) {
if ( laser[i].cnt == NOT_EXIST ) continue;
ls = &(laser[i]);
x = (float)ship.pos.x / FIELD_SCREEN_RATIO;
y = -(float)(ship.pos.y+ls->y) / FIELD_SCREEN_RATIO;
if ( ls->cnt > 1 ) t = 1;
else if ( ls->cnt == 1 ) t = 0;
else t = 2;
drawLaser(x, y, (float)laserWidth/FIELD_SCREEN_RATIO, LASER_SCREEN_HEIGHT,
ls->color,
(ls->color+LASER_COLOR_SPEED)&255,
(ls->color+LASER_COLOR_SPEED*2)&255,
(ls->color+LASER_COLOR_SPEED*3)&255,
laserCnt, t);
}
}