0486f87b295fcf7a075b4ecc68bf881eda809f40
[rocksndiamonds.git] / src / game_em / init.c
1 /* 2000-01-06 06:43:39
2  *
3  * set everything up and close everything down
4  */
5
6 #include "main_em.h"
7
8
9 Bitmap *screenBitmap;
10
11 struct GlobalInfo_EM global_em_info;
12 struct GameInfo_EM game_em;
13
14 void InitGfxBuffers_EM(void)
15 {
16   ReCreateBitmap(&screenBitmap, MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY);
17
18   global_em_info.screenbuffer = screenBitmap;
19 }
20
21 void game_init_random(void)
22 {
23   game_em.random = 1684108901;  /* what a nice seed */
24 }
25
26 void game_init_cave_buffers(void)
27 {
28   int x, y;
29
30   for (x = 0; x < CAVE_BUFFER_WIDTH; x++)
31   {
32     for (y = 0; y < CAVE_BUFFER_HEIGHT; y++)
33     {
34       lev.cavebuf[x][y] = Zborder;
35       lev.nextbuf[x][y] = Zborder;
36       lev.drawbuf[x][y] = Zborder;
37       lev.boombuf[x][y] = Xblank;
38     }
39
40     lev.cavecol[x] = lev.cavebuf[x];
41     lev.nextcol[x] = lev.nextbuf[x];
42     lev.drawcol[x] = lev.drawbuf[x];
43     lev.boomcol[x] = lev.boombuf[x];
44   }
45
46   lev.cave = lev.cavecol;
47   lev.next = lev.nextcol;
48   lev.draw = lev.drawcol;
49   lev.boom = lev.boomcol;
50 }
51
52 void em_open_all(void)
53 {
54   InitGraphicInfo_EM();
55
56   game_init_random();
57   game_init_cave_buffers();
58 }
59
60 void em_close_all(void)
61 {
62 }
63
64 void play_element_sound(int x, int y, int sample, int element)
65 {
66   PlayLevelSound_EM(CAVE_POS_X(x), CAVE_POS_Y(y), element, sample);
67 }
68
69 void play_sound(int x, int y, int sample)
70 {
71   play_element_sound(x, y, sample, -1);
72 }
73
74 int correctLevelPosX_EM(int lx)
75 {
76   lx -= lev.left;
77
78   return lx;
79 }
80
81 int correctLevelPosY_EM(int ly)
82 {
83   ly -= lev.top;
84
85   return ly;
86 }
87
88 unsigned int InitEngineRandom_EM(int seed)
89 {
90   if (seed == NEW_RANDOMIZE)
91   {
92     int simple_rnd = GetSimpleRandom(1000);
93     int i;
94
95     for (i = 0; i < simple_rnd || game_em.random == NEW_RANDOMIZE; i++)
96       game_em.random = game_em.random * 129 + 1;
97
98     seed = game_em.random;
99   }
100
101   game_em.random = seed;
102
103   return (unsigned int)seed;
104 }