1 /* This file is part of Alienwave, a game by Alessandro Pira */
2 
3 #include "shield.h"
4 #include "blit.h"
5 #include "aliens.h"
6 #include "xzarna.h"
7 #include "defs.h"
8 
9 shield scudo;
10 // "scudo" is the italian word for shield
11 
12 extern int x_ofs;
13 extern int y_ofs;
14 extern alien all_aliens[NUM_ALIENS];
15 
init_shields()16 void init_shields()
17 {
18 	scudo.x = -5;
19 	scudo.state = SHIELD_MIN; // Down and recharging
20 	scudo.blit = blit_shield;
21 	scudo.clear = clear_shield;
22 }
23 
open_shields(int x,int y)24 void open_shields(int x, int y)
25 {
26 	if ( (scudo.state>0) && (scudo.x<-1) )
27 	{
28 		scudo.x = x;
29 		scudo.y = y;
30 	}
31 }
32 
blit_shields()33 void blit_shields()
34 {
35 	if (scudo.x >= -1)
36 	{
37 		scudo.blit(scudo.x+x_ofs,scudo.y+y_ofs,(scudo.state/SHIELD_STEP)+1);
38 	}
39 	else if (scudo.state>0) blit_shield_charge(x_ofs,y_ofs,scudo.state/(SHIELD_MAX/20));
40 }
41 
clear_shields()42 void clear_shields()
43 {
44 	if (scudo.x >= -1)
45 	{
46 		scudo.clear(scudo.x+x_ofs,scudo.y+y_ofs);
47 	}
48 	clear_shield_charge(x_ofs,y_ofs);
49 }
50 
move_shields()51 void move_shields()
52 {
53 	if (scudo.x<-1)
54 	{
55 		if (scudo.state<SHIELD_MAX)
56 			scudo.state++;
57 	}
58 	else // The shield is on
59 	{
60 		scudo.state--;
61 		if (scudo.state>0)
62 		{
63 			int i,rel_x,rel_y;
64 			/* collision check */
65 			for (i=0;i<NUM_ALIENS;i++)
66 			{
67 				rel_x=scudo.x-all_aliens[i].x;
68 				rel_y=scudo.y-all_aliens[i].y;
69 				if ( (rel_y>=0) && (rel_y<MAX_HEIGHT) &&
70 				     (rel_x > -9) && (rel_x < 8) )
71 				{
72 					int shift;
73 					if (rel_x >= -1) shift=0x1FF>>(rel_x+1);
74 					else shift=0x1FF<<(-(rel_x+1));
75 					if ((all_aliens[i].collide[rel_y] & shift) != 0 )
76 					{
77 						blow_alien(i);
78 					}
79 				}
80 			}
81 			for (i=0;i<9;i++)
82 				collide_queen(scudo.x+i,scudo.y,COL_SHIELD);
83 		}
84 		else
85 		{
86 			scudo.state = SHIELD_MIN;
87 			scudo.x = -5;
88 		}
89 	}
90 }
91 
92