Browse Source

Move test object to g_enemy

Marrub 1 year ago
parent
commit
996bb982ba
3 changed files with 80 additions and 48 deletions
  1. 67
    0
      src/g_enemy.c
  2. 12
    0
      src/g_enemy.h
  3. 1
    48
      src/main.c

+ 67
- 0
src/g_enemy.c View File

@@ -0,0 +1,67 @@
1
+// Copyright © 2017 Project Golan, all rights reserved.
2
+// See COPYING for more information.
3
+#include "g_enemy.h"
4
+
5
+#include "m_math.h"
6
+
7
+// Static Functions ----------------------------------------------------------|
8
+
9
+//
10
+// G_TestObj_explode
11
+//
12
+static void G_TestObj_explode(fixed x, fixed y)
13
+{
14
+   DGE_ParticleSys ps = {DGE_ParticleSys_Create(0, 128)};
15
+
16
+   DGE_Particle prt = {
17
+      .life  = 30,
18
+      .size  = {20, 20},
19
+      .color = {1ulr, 1ulr, 0ulr, 1ulr}, {1ulr, 1ulr, 0ulr, 0ulr}, 0.05};
20
+
21
+   for(int i = 0; i < 7; i++)
22
+   {
23
+      prt.vel.x = M_Random_Float(-2, 2);
24
+      prt.vel.y = M_Random_Float(-2, 2);
25
+      prt.pos.x = M_Random_Float(-4, 4);
26
+      prt.pos.y = M_Random_Float(-4, 4);
27
+      DGE_ParticleSys_Add(ps.id, prt);
28
+   }
29
+
30
+   ps.x = x;
31
+   ps.y = y;
32
+
33
+   ps.sprite = DGE_Texture_Get(s"ent/explosion1");
34
+   DGE_Task_Sleep(0, 10); ps.sprite = DGE_Texture_Get(s"ent/explosion2");
35
+   DGE_Task_Sleep(0, 10); ps.sprite = DGE_Texture_Get(s"ent/explosion3");
36
+   DGE_Task_Sleep(0, 20); DGE_Thinker_Unlink(ps.id);
37
+}
38
+
39
+// Extern Functions ----------------------------------------------------------|
40
+
41
+//
42
+// G_TestObj_Think
43
+//
44
+DGE_Callback
45
+void G_TestObj_Think(G_enttype const *ty, unsigned id)
46
+{
47
+   G_entity th = {id};
48
+   fixed sx = th.x;
49
+
50
+   DGE_Object_RefAdd(id);
51
+
52
+   for(dword ticks = 0; th.health > 0; ticks++)
53
+   {
54
+      th.x = sx + cos(ticks / 7.0) * 23;
55
+      th.y = th.y + 2.6;
56
+
57
+      DGE_Task_Sleep(0, 1);
58
+   }
59
+
60
+   fixed x = th.x, y = th.y;
61
+
62
+   DGE_Object_RefSub(id);
63
+
64
+   G_TestObj_explode(x, y);
65
+}
66
+
67
+// EOF

+ 12
- 0
src/g_enemy.h View File

@@ -0,0 +1,12 @@
1
+// Copyright © 2017 Project Golan, all rights reserved.
2
+// See COPYING for more information.
3
+#ifndef g_enemy_h
4
+#define g_enemy_h
5
+
6
+#include "g_object.h"
7
+
8
+// Extern Functions ----------------------------------------------------------|
9
+
10
+DGE_Callback void G_TestObj_Think(G_enttype const *ty, unsigned id);
11
+
12
+#endif

+ 1
- 48
src/main.c View File

@@ -3,7 +3,7 @@
3 3
 #include "g_stage.h"
4 4
 #include "g_object.h"
5 5
 #include "g_player.h"
6
-#include "m_math.h"
6
+#include "g_enemy.h"
7 7
 
8 8
 #include <Doominati.h>
9 9
 
@@ -11,53 +11,6 @@
11 11
 
12 12
 // Extern Functions ----------------------------------------------------------|
13 13
 
14
-//
15
-// G_TestObj_Think
16
-//
17
-DGE_Callback
18
-void G_TestObj_Think(G_enttype const *ty, unsigned id)
19
-{
20
-   G_entity th = {id};
21
-
22
-   DGE_Object_RefAdd(id);
23
-
24
-   while(th.health > 0)
25
-      DGE_Task_Sleep(0, 1);
26
-
27
-   fixed x = th.x, y = th.y;
28
-
29
-   DGE_Object_RefSub(id);
30
-
31
-   DGE_ParticleSys ps = {DGE_ParticleSys_Create(0, 128)};
32
-
33
-   ps.sprite = DGE_Texture_Get(s"ent/explosion1");
34
-   ps.x = x;
35
-   ps.y = y;
36
-
37
-   DGE_Particle prt = {
38
-      .life  = 30,
39
-      .size  = {20, 20},
40
-      .color = {1ulr, 1ulr, 0ulr, 1ulr}, {1ulr, 1ulr, 0ulr, 0ulr}, 0.05};
41
-
42
-   for(int i = 0; i < 7; i++)
43
-   {
44
-      prt.vel.x = M_Random_Float(-2, 2);
45
-      prt.vel.y = M_Random_Float(-2, 2);
46
-      prt.pos.x = M_Random_Float(-4, 4);
47
-      prt.pos.y = M_Random_Float(-4, 4);
48
-      DGE_ParticleSys_Add(ps.id, prt);
49
-   }
50
-
51
-   DGE_Task_Sleep(0, 10);
52
-   ps.sprite = DGE_Texture_Get(s"ent/explosion2");
53
-
54
-   DGE_Task_Sleep(0, 10);
55
-   ps.sprite = DGE_Texture_Get(s"ent/explosion3");
56
-
57
-   DGE_Task_Sleep(0, 20);
58
-   DGE_Thinker_Unlink(ps.id);
59
-}
60
-
61 14
 //
62 15
 // GInit
63 16
 //

Loading…
Cancel
Save