1 /* xsoldier, a shoot 'em up game with "not shooting" bonus
2 * Copyright (C) 1997 Yuusuke HASHIMOTO <s945750@educ.info.kanagawa-u.ac.jp>
3 * Copyright (C) 2002 Oohara Yuuma <oohara@libra.interq.or.jp>
4 *
5 * This is a copyleft program. See the file LICENSE for details.
6 */
7 /* $Id: common.c,v 1.4 2002/04/29 03:38:41 oohara Exp $ */
8
9 /*
10 #include <X11/Xlib.h>
11 #include <X11/xpm.h>
12 */
13 /* abs */
14 #include <stdlib.h>
15
16 #include "image.h"
17 #include "xsoldier.h"
18 #include "common.h"
19 #include "callback.h"
20 #include "extern.h"
21 #include "sin.h"
22
NewBomb(int x,int y)23 void NewBomb(int x, int y)
24 {
25 int i;
26
27 if (manage->EnemyNum >= manage->EnemyMax)
28 return;
29
30 for (i=1; i<manage->EnemyMax; i++)
31 {
32 if (manage->enemy[i]->Data.used == False)
33 {
34 manage->Bomb.Data.X = x;
35 manage->Bomb.Data.Y = y;
36
37 manage->enemy[i]->Data = manage->Bomb.Data;
38 manage->enemy[i]->Grp = manage->Bomb.Grp;
39 manage->enemy[i]->Action = BombAct;
40 manage->enemy[i]->Realize = DrawImage;
41 manage->enemy[i]->Hit = NullHit;
42
43 manage->EnemyNum++;
44 return;
45 }
46 }
47 }
48
NewLargeBomb(int x,int y)49 void NewLargeBomb(int x, int y)
50 {
51 int i;
52
53 if (manage->EnemyNum >= manage->EnemyMax)
54 return;
55
56 for (i=1; i<manage->EnemyMax; i++)
57 {
58 if (manage->enemy[i]->Data.used == False)
59 {
60 manage->LargeBomb.Data.X = x;
61 manage->LargeBomb.Data.Y = y;
62
63 manage->enemy[i]->Data = manage->LargeBomb.Data;
64 manage->enemy[i]->Grp = manage->LargeBomb.Grp;
65 manage->enemy[i]->Action = BombAct;
66 manage->enemy[i]->Realize = DrawImage;
67 manage->enemy[i]->Hit = NullHit;
68
69 manage->EnemyNum++;
70 return;
71 }
72 }
73 }
74
BombAct(ObjData * my)75 DelAtt BombAct(ObjData *my)
76 {
77 my->image = my->Cnt[0];
78 my->Cnt[0]++;
79 if (my->Cnt[0] > 5)
80 return NullDel;
81 return NoneDel;
82 }
83
GetDirection(int mx,int my,int sx,int sy)84 int GetDirection(int mx, int my, int sx, int sy)
85 {
86 static double hi;
87 static int uw;
88 static int uh;
89 static int h;
90 static int w;
91
92 uw = abs(sx-mx);
93 uh = abs(sy-my);
94 h = sy-my;
95 w = sx-mx;
96
97 if (!uw) return (uh>0)?4:0;
98 if (!uh) return (uw>0)?2:6;
99
100 hi = (double)uh/uw;
101 if (hi < 0.42)
102 return (w > 0) ? 2: 6;
103 else if (hi > 2.42)
104 return (h > 0) ? 4: 0;
105 else
106 {
107 return (w>0)?((h>0)?3:1):((h>0)?5:7);
108 /***
109 if (w > 0 && h > 0) return 3;
110 if (w > 0 && h < 0) return 1;
111 if (w < 0 && h > 0) return 5;
112 if (w < 0 && h < 0) return 7;
113 ***/
114 }
115 }
116