Added a temporary font spritesheet and the ability to interfacePrint in SDL with aforementioned font. This simply works by getting the numerical offset of the ASCII character value within the spritesheet (same principle as the rest of the tiles). In the future SDL_ttf will be used, but for the time being this will suffice.

netcode
kts 2013-10-17 19:38:00 -07:00
parent 4c204db4f3
commit 45ebcfe970
19 changed files with 97 additions and 57 deletions

View File

@ -17,6 +17,8 @@
int interfaceInit() {
// Load it up!
SDL_Init(SDL_INIT_VIDEO);
// Enable Unicode, for later text input
SDL_EnableUNICODE(1);
// Set up our SDL Window
if ((screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE)) == NULL) {
return ERROR;
@ -24,6 +26,7 @@ int interfaceInit() {
SDL_WM_SetCaption(NAME, NULL);
camera_surface = SDL_CreateRGBSurface(screen->flags, 512, 512, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
font_spritesheet = IMG_Load_RW(SDL_RWFromMem(&font_images, font_images_length), 1);
player_spritesheet = IMG_Load_RW(SDL_RWFromMem(&player_images, player_images_length), 1);
wall_spritesheet = IMG_Load_RW(SDL_RWFromMem(&wall_images, wall_images_length), 1);
floor_spritesheet = IMG_Load_RW(SDL_RWFromMem(&floor_images, floor_images_length), 1);
@ -108,7 +111,12 @@ void interfaceLoop() {
is_running = 0;
break;
case SDL_KEYDOWN:
(*current_context)(event.key.keysym.sym);
if (SDL_GetModState() & KMOD_SHIFT) {
(*current_context)(toupper(event.key.keysym.sym));
} else {
(*current_context)(event.key.keysym.sym);
}
//(*current_context)(event.key.keysym.sym);
/*if (event.key.keysym.sym == SDLK_q) {
is_running = 0;
} else if (event.key.keysym.sym == SDLK_UP) {
@ -134,7 +142,17 @@ void interfaceDraw() {
}
void interfacePrint(const char *string) {
int i = 0;
SDL_Rect print_area = {0, 512, 600, 32};
SDL_FillRect(screen, &print_area, SDL_MapRGB(screen->format,128, 128, 0));
while (string[i] != '\0') {
int y_offset = string[i] / 16; // 16 tiles across in spritesheet
int x_offset = string[i] - (y_offset*16);
SDL_Rect character_offset = { x_offset*TILE_WIDTH, y_offset*TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT};
SDL_Rect render_position = {i*TILE_WIDTH, 512, TILE_WIDTH, TILE_HEIGHT};
SDL_BlitSurface(font_spritesheet, &character_offset, screen, &render_position);
i++;
}
}
void interfaceClose() {

View File

@ -2,6 +2,7 @@
#define SDL_H
#include "../player.h" // for races/class totals
SDL_Surface* screen;
SDL_Surface* font_spritesheet;
SDL_Surface* player_spritesheet;
SDL_Surface* shadow_spritesheet;
SDL_Surface* wall_spritesheet;

View File

@ -30,6 +30,7 @@ int main(int argc, char **argv) {
fprintf(tiles_h, "#ifndef TILES_H\n#define TILES_H\n");
fprintf(tiles_h, "#define TILE_WIDTH 16\n#define TILE_HEIGHT 32\n");
convert("tiles/font.png", "font_images");
convert("tiles/players.png", "player_images");
convert("tiles/walls.png", "wall_images");
convert("tiles/floors.png", "floor_images");

BIN
tiles.o

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,9 @@
#define TILES_H
#define TILE_WIDTH 16
#define TILE_HEIGHT 32
extern unsigned char font_images[];
extern unsigned int font_images_length;
extern unsigned char player_images[];
extern unsigned int player_images_length;

View File

@ -216,10 +216,10 @@
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>203852F11810908E00BA5BC2</string>
<string>2076112A1810D62500D8CB9A</string>
<key>history</key>
<array>
<string>2088594E180FE315007E7565</string>
<string>203852F11810908E00BA5BC2</string>
</array>
</dict>
<key>SplitCount</key>
@ -359,7 +359,7 @@
<key>PBXProjectModuleGUID</key>
<string>1CE0B20306471E060097A5F4</string>
<key>PBXProjectModuleLabel</key>
<string>game.c</string>
<string>sdl.c</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
@ -367,11 +367,11 @@
<key>PBXProjectModuleGUID</key>
<string>1CE0B20406471E060097A5F4</string>
<key>PBXProjectModuleLabel</key>
<string>game.c</string>
<string>sdl.c</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>203852F01810908E00BA5BC2</string>
<string>207611291810D62500D8CB9A</string>
<key>history</key>
<array>
<string>20567ECF17E95DEC0002B1A9</string>
@ -397,10 +397,10 @@
<string>20CD0579180FBCD8005A8231</string>
<string>20CD057A180FBCD8005A8231</string>
<string>20CD057B180FBCD8005A8231</string>
<string>20CD057C180FBCD8005A8231</string>
<string>20CD057D180FBCD8005A8231</string>
<string>20CD057E180FBCD8005A8231</string>
<string>2088594D180FE315007E7565</string>
<string>207610F21810CDC500D8CB9A</string>
<string>207610EF1810CDBC00D8CB9A</string>
</array>
<key>prevStack</key>
<array>
@ -431,6 +431,7 @@
<string>206D605B1808F99A00C0DE49</string>
<string>206D60B7180907AC00C0DE49</string>
<string>20CD05AE180FBCD8005A8231</string>
<string>207610F31810CDC500D8CB9A</string>
</array>
</dict>
<key>SplitCount</key>
@ -488,9 +489,9 @@
</array>
<key>TableOfContents</key>
<array>
<string>203852E31810908D00BA5BC2</string>
<string>207610D21810A9BF00D8CB9A</string>
<string>1CE0B1FE06471DED0097A5F4</string>
<string>203852E41810908D00BA5BC2</string>
<string>207610D31810A9BF00D8CB9A</string>
<string>1CE0B20306471E060097A5F4</string>
<string>1CE0B20506471E060097A5F4</string>
</array>
@ -624,8 +625,8 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
<string>203852EE1810908D00BA5BC2</string>
<string>203852EF1810908D00BA5BC2</string>
<string>207610E01810AB3300D8CB9A</string>
<string>207610E11810AB3300D8CB9A</string>
<string>1C78EAAD065D492600B07095</string>
<string>1CD10A99069EF8BA00B06720</string>
<string>20F6A1B417E95A6200BAD261</string>
@ -649,12 +650,14 @@
<key>Dock</key>
<array>
<dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>1CD0528F0623707200166675</string>
<key>PBXProjectModuleLabel</key>
<string></string>
<string>sdl.c</string>
<key>StatusBarVisibility</key>
<true/>
</dict>
@ -710,7 +713,7 @@
<key>TableOfContents</key>
<array>
<string>20F6A1B417E95A6200BAD261</string>
<string>203852E61810908D00BA5BC2</string>
<string>207610D51810A9BF00D8CB9A</string>
<string>1CD0528F0623707200166675</string>
<string>XCMainBuildResultsModuleGUID</string>
</array>
@ -830,13 +833,13 @@
<key>TableOfContents</key>
<array>
<string>1CD10A99069EF8BA00B06720</string>
<string>203852E71810908D00BA5BC2</string>
<string>207610D91810AB3300D8CB9A</string>
<string>1C162984064C10D400B95A72</string>
<string>203852E81810908D00BA5BC2</string>
<string>203852E91810908D00BA5BC2</string>
<string>203852EA1810908D00BA5BC2</string>
<string>203852EB1810908D00BA5BC2</string>
<string>203852EC1810908D00BA5BC2</string>
<string>207610DA1810AB3300D8CB9A</string>
<string>207610DB1810AB3300D8CB9A</string>
<string>207610DC1810AB3300D8CB9A</string>
<string>207610DD1810AB3300D8CB9A</string>
<string>207610DE1810AB3300D8CB9A</string>
</array>
<key>ToolbarConfiguration</key>
<string>xcode.toolbar.config.debugV3</string>
@ -998,7 +1001,7 @@
<key>TableOfContents</key>
<array>
<string>1C78EAAD065D492600B07095</string>
<string>203852ED1810908D00BA5BC2</string>
<string>207610DF1810AB3300D8CB9A</string>
<string>1C78EAAC065D492600B07095</string>
</array>
<key>ToolbarConfiguration</key>

View File

@ -42,16 +42,6 @@
vrLen = 508;
vrLoc = 0;
};
203852F01810908E00BA5BC2 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 20568DD217EBE9490022F314 /* game.c */;
name = "game.c: 22";
rLen = 0;
rLoc = 433;
rType = 0;
vrLen = 1212;
vrLoc = 12;
};
203852F11810908E00BA5BC2 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 20F6A1F017E95B6F00BAD261 /* sdl.c */;
@ -443,7 +433,15 @@
vrLen = 1159;
vrLoc = 0;
};
2088594D180FE315007E7565 /* PBXTextBookmark */ = {
207610EF1810CDBC00D8CB9A /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
comments = "error: 'tile_rect' undeclared (first use in this function)";
fRef = 20F6A1F017E95B6F00BAD261 /* sdl.c */;
rLen = 1;
rLoc = 152;
rType = 1;
};
207610F21810CDC500D8CB9A /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 20568DD217EBE9490022F314 /* game.c */;
name = "game.c: 22";
@ -453,15 +451,35 @@
vrLen = 1212;
vrLoc = 12;
};
2088594E180FE315007E7565 /* PBXTextBookmark */ = {
207610F31810CDC500D8CB9A /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 20568DD217EBE9490022F314 /* game.c */;
name = "game.c: 22";
rLen = 0;
rLoc = 433;
rType = 0;
vrLen = 1212;
vrLoc = 12;
};
207611291810D62500D8CB9A /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 20F6A1F017E95B6F00BAD261 /* sdl.c */;
name = "sdl.c: 5";
name = "sdl.c: 146";
rLen = 0;
rLoc = 101;
rLoc = 5730;
rType = 0;
vrLen = 1500;
vrLoc = 1969;
vrLen = 1135;
vrLoc = 5154;
};
2076112A1810D62500D8CB9A /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 20F6A1F017E95B6F00BAD261 /* sdl.c */;
name = "sdl.c: 161";
rLen = 0;
rLoc = 6289;
rType = 0;
vrLen = 1339;
vrLoc = 1475;
};
2090287B17E95E780051A253 /* timesynk_Prefix.pch */ = {
uiCtxt = {
@ -551,16 +569,6 @@
vrLen = 607;
vrLoc = 0;
};
20CD057C180FBCD8005A8231 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 20F6A1F017E95B6F00BAD261 /* sdl.c */;
name = "sdl.c: 79";
rLen = 0;
rLoc = 3320;
rType = 0;
vrLen = 1791;
vrLoc = 1999;
};
20CD057D180FBCD8005A8231 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 204F942518005466007B4DAD /* map.h */;
@ -755,9 +763,9 @@
};
20F6A1F017E95B6F00BAD261 /* sdl.c */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {1224, 1862}}";
sepNavSelRange = "{101, 0}";
sepNavVisRange = "{1969, 1500}";
sepNavIntBoundsRect = "{{0, 0}, {1224, 2226}}";
sepNavSelRange = "{6289, 0}";
sepNavVisRange = "{1475, 1339}";
sepNavWindowFrame = "{{174, 72}, {750, 558}}";
};
};
@ -883,13 +891,12 @@
PBXFileDataSource_Warnings_ColumnID,
);
};
PBXPerProjectTemplateStateSaveDate = 403738651;
PBXWorkspaceStateSaveDate = 403738651;
PBXPerProjectTemplateStateSaveDate = 403745201;
PBXWorkspaceStateSaveDate = 403745201;
};
perUserProjectItems = {
2002F0D917E972B3003CF277 /* PlistBookmark */ = 2002F0D917E972B3003CF277 /* PlistBookmark */;
2007C93017ECF2EB00268653 /* PBXTextBookmark */ = 2007C93017ECF2EB00268653 /* PBXTextBookmark */;
203852F01810908E00BA5BC2 /* PBXTextBookmark */ = 203852F01810908E00BA5BC2 /* PBXTextBookmark */;
203852F11810908E00BA5BC2 /* PBXTextBookmark */ = 203852F11810908E00BA5BC2 /* PBXTextBookmark */;
203B68D117F7D77900272675 /* PBXTextBookmark */ = 203B68D117F7D77900272675 /* PBXTextBookmark */;
204F943D18005532007B4DAD /* PBXTextBookmark */ = 204F943D18005532007B4DAD /* PBXTextBookmark */;
@ -920,8 +927,11 @@
206D60B4180907AC00C0DE49 /* PBXTextBookmark */ = 206D60B4180907AC00C0DE49 /* PBXTextBookmark */;
206D60B7180907AC00C0DE49 /* PBXTextBookmark */ = 206D60B7180907AC00C0DE49 /* PBXTextBookmark */;
206D60C918090A6700C0DE49 /* PBXTextBookmark */ = 206D60C918090A6700C0DE49 /* PBXTextBookmark */;
2088594D180FE315007E7565 /* PBXTextBookmark */ = 2088594D180FE315007E7565 /* PBXTextBookmark */;
2088594E180FE315007E7565 /* PBXTextBookmark */ = 2088594E180FE315007E7565 /* PBXTextBookmark */;
207610EF1810CDBC00D8CB9A /* PBXTextBookmark */ = 207610EF1810CDBC00D8CB9A /* PBXTextBookmark */;
207610F21810CDC500D8CB9A /* PBXTextBookmark */ = 207610F21810CDC500D8CB9A /* PBXTextBookmark */;
207610F31810CDC500D8CB9A /* PBXTextBookmark */ = 207610F31810CDC500D8CB9A /* PBXTextBookmark */;
207611291810D62500D8CB9A /* PBXTextBookmark */ = 207611291810D62500D8CB9A /* PBXTextBookmark */;
2076112A1810D62500D8CB9A /* PBXTextBookmark */ = 2076112A1810D62500D8CB9A /* PBXTextBookmark */;
2090289E17E95F9E0051A253 /* PBXTextBookmark */ = 2090289E17E95F9E0051A253 /* PBXTextBookmark */;
2090289F17E95F9E0051A253 /* PBXTextBookmark */ = 2090289F17E95F9E0051A253 /* PBXTextBookmark */;
209028A517E95F9E0051A253 /* PBXTextBookmark */ = 209028A517E95F9E0051A253 /* PBXTextBookmark */;
@ -930,7 +940,6 @@
20CD0579180FBCD8005A8231 /* PBXTextBookmark */ = 20CD0579180FBCD8005A8231 /* PBXTextBookmark */;
20CD057A180FBCD8005A8231 /* PBXTextBookmark */ = 20CD057A180FBCD8005A8231 /* PBXTextBookmark */;
20CD057B180FBCD8005A8231 /* PBXTextBookmark */ = 20CD057B180FBCD8005A8231 /* PBXTextBookmark */;
20CD057C180FBCD8005A8231 /* PBXTextBookmark */ = 20CD057C180FBCD8005A8231 /* PBXTextBookmark */;
20CD057D180FBCD8005A8231 /* PBXTextBookmark */ = 20CD057D180FBCD8005A8231 /* PBXTextBookmark */;
20CD057E180FBCD8005A8231 /* PBXTextBookmark */ = 20CD057E180FBCD8005A8231 /* PBXTextBookmark */;
20CD05AE180FBCD8005A8231 /* PBXTextBookmark */ = 20CD05AE180FBCD8005A8231 /* PBXTextBookmark */;