1 /************************************************************************/
2 /************************************************************************/
3 /*																		*/
4 /*						System independent routines						*/
5 /*																		*/
6 /*																		*/
7 /************************************************************************/
8 /************************************************************************/
9 
10 #include "aklabeth.hpp"						/* Our prototypes */
11 #include "sdw.hxx"
12 
13 using namespace SDLWrapper;
14 
15 int CharHeight = 16;						/* Height of one character */
16 int CharWidth = 16;							/* Width of one character */
17 int TextLines = 22;							/* Number of chars in visible line */
18 int TextLeft,xc,yc;
19 int TextOrigin;
20 int Red,Green,Blue;
21 Surface *MainSurface;
22 
23 /************************************************************************/
24 /*																		*/
25 /*				Initialise all internal graphics routines				*/
26 /*																		*/
27 /************************************************************************/
28 
HWInitialise(void)29 void HWInitialise(void)
30 {
31 	MainSurface = new Surface(DEFAULT_SCX,DEFAULT_SCY);
32 	TextLeft = DEFAULT_SCX-CharWidth*TextLines;
33 	TextOrigin = 224;
34 	xc = TextLeft;yc = TextOrigin;
35 }
36 
37 /************************************************************************/
38 /*																		*/
39 /*							Refresh Status Area							*/
40 /*																		*/
41 /************************************************************************/
42 
HWStatus(double Food,int HP,int Gold)43 void HWStatus(double Food,int HP,int Gold)
44 {
45 	char Temp[32];
46 	MainSurface->SetColour(0,0,0);
47 	MainSurface->FillRect(TextLeft,0,DEFAULT_SCX,TextOrigin-1);
48 	MainSurface->SetColour(0,255,255);
49 	sprintf(Temp,"%.1f",Food);
50 	MainSurface->String(TextLeft+16,32,TextLeft+16+32*strlen(Temp),32+32,Temp);
51 	sprintf(Temp,"%u",HP);
52 	MainSurface->String(TextLeft+16,96,TextLeft+16+32*strlen(Temp),96+32,Temp);
53 	sprintf(Temp,"%u",Gold);
54 	MainSurface->String(TextLeft+16,160,TextLeft+16+32*strlen(Temp),160+32,Temp);
55 
56 	MainSurface->SetColour(255,0,0);
57 	MainSurface->String(TextLeft,8,TextLeft+64,24,"Food");
58 	MainSurface->String(TextLeft,72,TextLeft+16*9,88,"Hit Points");
59 	MainSurface->String(TextLeft,136,TextLeft+64,152,"Gold");
60 
61 // /*	char Temp[32];
62 // 	setfillstyle(SOLID_FILL,BLACK);    		/* Set up colours */
63 // 	setcolor(LIGHTCYAN);
64 // 	settextstyle(SMALL_FONT,HORIZ_DIR,6);
65 // 	bar(xText+110,22,xMax-4,yScroll-4);		/* Erase old status values */
66 // 	sprintf(Temp,"%.1f",Food);				/* Fill in the new ones */
67 // 	outtextxy(xText+110,22,Temp);
68 // 	sprintf(Temp,"%u",HP);
69 // 	outtextxy(xText+110,37,Temp);
70 // 	sprintf(Temp,"%u",Gold);
71 // 	outtextxy(xText+110,52,Temp);
72 // 	HWColour(CurrentColour);				/* Set the current colour */*/
73 }
74 
75 /************************************************************************/
76 /*																		*/
77 /*				Terminate all internal graphics routines				*/
78 /*																		*/
79 /************************************************************************/
80 
HWTerminate(void)81 void HWTerminate(void)
82 {
83 }
84 
85 /************************************************************************/
86 /*																		*/
87 /*				Output text to the scrolling text area					*/
88 /*																		*/
89 /************************************************************************/
90 
HWChar(int ch)91 void HWChar(int ch)
92 {
93 	Rect src(TextLeft,TextOrigin+CharHeight,DEFAULT_SCX,DEFAULT_SCY);
94 	if (ch >= ' ')
95 	{
96 		MainSurface->SetColour(0,255,0);
97 		MainSurface->Char(xc,yc,xc+CharWidth-1,yc+CharHeight-1,ch);
98 		xc = xc + CharWidth;
99 	}
100 	if (xc >= DEFAULT_SCX || ch == 13)
101 	{
102 		xc = TextLeft;
103 		yc = yc + CharHeight;
104 		if (yc + CharHeight >= DEFAULT_SCY)
105 		{
106 			MainSurface->Copy(*MainSurface,src,TextLeft,TextOrigin);
107 			MainSurface->SetColour(0,0,0);
108 			MainSurface->FillRect(TextLeft,yc,DEFAULT_SCX,DEFAULT_SCY);
109 			yc = yc - CharHeight;
110 		}
111 	}
112 }
113 
114 /************************************************************************/
115 /*																		*/
116 /*			Select the current drawing colour, should use RGB()			*/
117 /*																		*/
118 /************************************************************************/
119 
HWColour(int c)120 void HWColour(int c)
121 {
122 	Red = (c & 4) ? 255:0;
123 	Green = (c & 2) ? 255:0;
124 	Blue = (c & 1) ? 255:0;
125 }
126 
127 /************************************************************************/
128 /*																		*/
129 /*						Draw line in current colour						*/
130 /*																		*/
131 /************************************************************************/
132 
HWLine(int x1,int y1,int x2,int y2)133 void HWLine(int x1,int y1,int x2,int y2)
134 {
135 	x1 = x1 * TextLeft/1280;y1 = DEFAULT_SCY-y1 * DEFAULT_SCY/1024;
136 	x2 = x2 * TextLeft/1280;y2 = DEFAULT_SCY-y2 * DEFAULT_SCY/1024;
137 	MainSurface->SetColour(Red,Green,Blue);
138 	MainSurface->Line(x1,y1,x2,y2);
139 }
140 
141 /***********************************************************************/
142 /*																		*/
143 /*			Read an upper case ASCII key, or Carriage Return (13)		*/
144 /*																		*/
145 /************************************************************************/
146 
HWGetKey(void)147 int HWGetKey(void)
148 {
149 	int n;
150 	MainSurface->Copy();
151 	MainSurface->Flip();
152 	do
153 	{
154 		n = GetKey();
155 		if (n == 273) n = 'N';
156 		if (n == 274) n = 'S';
157 		if (n == 275) n = 'E';
158 		if (n == 276) n = 'W';
159 
160 	}
161 	while (n < ' ' || n > 127);
162 	return toupper(n);
163 }
164 
165 
166 /************************************************************************/
167 /*																		*/
168 /*						Clear the graphics area							*/
169 /*																		*/
170 /************************************************************************/
171 
HWClear(void)172 void HWClear(void)
173 {
174 	MainSurface->SetColour(0,0,0);
175 	MainSurface->FillRect(0,0,TextLeft-1,DEFAULT_SCY);
176 }
177 
178 
179 
180