summaryrefslogtreecommitdiff
path: root/Wolf3D.c
blob: 22f790fd5131180f2ba3fb927feca8397f0e7841 (plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* wird zum Waffenwechsel werden.
"Türen kann man nur öffnen" - was willst du sonst damit machen? Aufessen?
*/

#include "key.h"
#include "global.h"
#include "syscalls.h"
#include "hardware.h"
#include "mapgen.h"
#include "ki.h"
#include "engine.h"
#include "sprites.h"

#include "stdio.h"

void main(void)
{
	char FPS[9];
	char LIVE[13];
	static int oldtime;
	static int maintimer = 0;

	if(RTC_Elapsed_ms(maintimer, 100))
	{
		maintimer = RTC_GetTicks();
		
		if(player.health <= 50)
		{
			if(contrast > 10 || contrast < -10)
			{
				contradd *= -1;
			}
			contrast += contradd;
			set_contrast(168 + contrast);
		}
		
		if(statustimer++ == 100)
		{
			statustimer = 0;
			status = NULL;
		}
		
		if(BacklightIsOn() && statustimer % 5 == 0)
		{
			BacklightOff();
		}
	}
	
	move();
	if(output != 0)
	{
		unsigned int time;
		oldtime = RTC_GetTicks();
		clear_vram();
		cast();
		
		drawgun();
		
		if(output == 2)
		{
			if(player.gunpos > 3 || player.gunpos < -3)
			{
				if(player.gunpos > 3)
				player.gunpos = 3;
				
				gundir *= -1;
			}
			player.gunpos += gundir;
		}	
		
		sprintf(&FPS, "fps:%2.2f", 1 / fps);
		PrintMini(0, 0, &FPS, MINI_OR);
		
		sprintf(&LIVE, "health:%4d", player.health);
		PrintMini(80, 0, &LIVE, MINI_OR);
		
		if(status != NULL)PrintMini(0, 58, status, MINI_OR);
		
		display_vram();
		if(player.health <= 0)
		{
			exit = TRUE;
		}
		output = 0;
		
		fps = (((RTC_GetTicks() * 15.625 - oldtime * 15.625)) / 1000);
	}
}

int AddIn_main(int isAppli, unsigned short OptionNum)
{
	int c;
	vram = Disp_GetVRAMPtr();
	
	if(getCalc() == UNKNOWN)
	{
		clear_vram();
		locate(1,1);
		Print("Unknown hardware");
		locate(1,2);
		Print("detected.");
		locate(1,3);
		Print("All direct hardware");
		locate(1,4);
		Print("functions will be");
		locate(1,5);
		Print("disabled!");
		locate(1,7);
		Print("Press any key");
		locate(1,8);
		Print("to start the game");
		GetKey(&c);
	}
	
	APP_EnableRestart();

	table();
	seedrandom();
	
	if(ENEMYCNT)
	{
		sprites = (struct st_sprite *) malloc(ENEMYCNT * sizeof(struct st_sprite));
		if(sprites == NULL)error();
	}
	
	spritecnt = ENEMYCNT;
	
	for(c = 0; c < spritecnt; c++)
	{
		kisetpos(&sprites[c].x, &sprites[c].y);
		sprites[c].texture.ptr = &enemy;
		sprites[c].texture.width = 16;
		sprites[c].texture.height = 32;
		sprites[c].type = TYPE_ENEMY;
		sprites[c].effect = 50;
	}
	
	maze();
	
	player.x = 1.5;
	player.y = 1.5;
	player.dirX = -1;
	player.dirY = 0;
	player.planeX = 0;
	player.planeY = 0.66;
	player.weapon = GUN;
	player.gunpos = 0;
	player.health = 500;
	contrast = 0;
	
	Timer_Install(8, &timer, KISPEED);
	Timer_Start(8);
	
	exit = FALSE;
	
	while(exit == FALSE)
	{
		main();
		if((int)player.x == MAPSIZE - 1 && (int)player.y == MAPSIZE - 1)break;
	}
	
	Timer_Uninstall(8);
	set_contrast(168);
	
	if(player.health > 0 && exit == FALSE)
	{
		clear_vram();
	
		locate(1, 1);
		Print("You found the exit!");
		
		display_vram();
		Sleep(1000);
	}
	free(sprites);
	
	Keyboard_ClrBuffer();
}

#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
int InitializeSystem(int isAppli, unsigned short OptionNum)
{return INIT_ADDIN_APPLICATION(isAppli, OptionNum);}
#pragma section