Draw mission info and keys.
This commit is contained in:
parent
2c5e105cdb
commit
5ca947cab0
|
@ -27,6 +27,9 @@ static void loadMissions(void);
|
||||||
static void unlockNeighbouringMission(HubMission *sourceMission);
|
static void unlockNeighbouringMission(HubMission *sourceMission);
|
||||||
static int missionComparator(const void *a, const void *b);
|
static int missionComparator(const void *a, const void *b);
|
||||||
static HubMission *getMissionAt(int x, int y);
|
static HubMission *getMissionAt(int x, int y);
|
||||||
|
static void drawMissions(void);
|
||||||
|
static void drawInfoBar(void);
|
||||||
|
static void drawMissionInfo(void);
|
||||||
static void logic(void);
|
static void logic(void);
|
||||||
static void draw(void);
|
static void draw(void);
|
||||||
|
|
||||||
|
@ -36,6 +39,7 @@ static HubMission *selectedMission;
|
||||||
static Atlas *worldMap;
|
static Atlas *worldMap;
|
||||||
static Atlas *alert;
|
static Atlas *alert;
|
||||||
static Atlas *clouds;
|
static Atlas *clouds;
|
||||||
|
static Sprite *keySprites[MAX_KEY_TYPES];
|
||||||
static Texture *atlasTexture;
|
static Texture *atlasTexture;
|
||||||
static int completedMissions;
|
static int completedMissions;
|
||||||
static int numMissions;
|
static int numMissions;
|
||||||
|
@ -44,18 +48,28 @@ static float blipValue;
|
||||||
|
|
||||||
void initHub(void)
|
void initHub(void)
|
||||||
{
|
{
|
||||||
int unlockedMissions, unlockTeeka;
|
int unlockedMissions, unlockTeeka, i;
|
||||||
HubMission *mission, *teeka;
|
HubMission *mission, *teeka;
|
||||||
Tuple *t;
|
Tuple *t;
|
||||||
|
|
||||||
memset(&hubMissionHead, 0, sizeof(HubMission));
|
memset(&hubMissionHead, 0, sizeof(HubMission));
|
||||||
hubMissionTail = &hubMissionHead;
|
hubMissionTail = &hubMissionHead;
|
||||||
|
|
||||||
|
memset(&keySprites, 0, sizeof(Sprite*) * MAX_KEY_TYPES);
|
||||||
|
|
||||||
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
||||||
worldMap = getImageFromAtlas("gfx/hub/worldMap.jpg");
|
worldMap = getImageFromAtlas("gfx/hub/worldMap.jpg");
|
||||||
alert = getImageFromAtlas("gfx/hub/alert.png");
|
alert = getImageFromAtlas("gfx/hub/alert.png");
|
||||||
clouds = getImageFromAtlas("gfx/hub/clouds.png");
|
clouds = getImageFromAtlas("gfx/hub/clouds.png");
|
||||||
|
|
||||||
|
for (i = 0 ; i < MAX_KEY_TYPES ; i++)
|
||||||
|
{
|
||||||
|
if (game.keys[i].value.i > 0)
|
||||||
|
{
|
||||||
|
keySprites[i] = getSprite(game.keys[i].key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
loadMissions();
|
loadMissions();
|
||||||
|
|
||||||
if (dev.cheatLevels)
|
if (dev.cheatLevels)
|
||||||
|
@ -139,8 +153,10 @@ static void logic(void)
|
||||||
|
|
||||||
blipSize = 64 + (sin(blipValue) * 16);
|
blipSize = 64 + (sin(blipValue) * 16);
|
||||||
|
|
||||||
m = NULL;
|
animateSprites();
|
||||||
|
|
||||||
|
if (selectedMission == NULL)
|
||||||
|
{
|
||||||
if (app.mouse.button[SDL_BUTTON_LEFT])
|
if (app.mouse.button[SDL_BUTTON_LEFT])
|
||||||
{
|
{
|
||||||
m = getMissionAt(app.mouse.x, app.mouse.y);
|
m = getMissionAt(app.mouse.x, app.mouse.y);
|
||||||
|
@ -151,14 +167,35 @@ static void logic(void)
|
||||||
app.mouse.button[SDL_BUTTON_LEFT] = 0;
|
app.mouse.button[SDL_BUTTON_LEFT] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (app.keyboard[SDL_SCANCODE_ESCAPE])
|
||||||
|
{
|
||||||
|
selectedMission = NULL;
|
||||||
|
app.keyboard[SDL_SCANCODE_ESCAPE] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw(void)
|
static void draw(void)
|
||||||
{
|
{
|
||||||
HubMission *mission;
|
|
||||||
|
|
||||||
blitRectScaled(atlasTexture->texture, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, &worldMap->rect, 0);
|
blitRectScaled(atlasTexture->texture, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, &worldMap->rect, 0);
|
||||||
|
|
||||||
|
drawMissions();
|
||||||
|
|
||||||
|
drawInfoBar();
|
||||||
|
|
||||||
|
if (selectedMission != NULL)
|
||||||
|
{
|
||||||
|
drawMissionInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void drawMissions(void)
|
||||||
|
{
|
||||||
|
HubMission *mission;
|
||||||
|
|
||||||
for (mission = hubMissionHead.next ; mission != NULL ; mission = mission->next)
|
for (mission = hubMissionHead.next ; mission != NULL ; mission = mission->next)
|
||||||
{
|
{
|
||||||
switch (mission->status)
|
switch (mission->status)
|
||||||
|
@ -179,7 +216,10 @@ static void draw(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_SetTextureColorMod(atlasTexture->texture, 255, 255, 255);
|
SDL_SetTextureColorMod(atlasTexture->texture, 255, 255, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void drawInfoBar(void)
|
||||||
|
{
|
||||||
drawRect(0, 0, SCREEN_WIDTH, 32, 0, 0, 0, 192);
|
drawRect(0, 0, SCREEN_WIDTH, 32, 0, 0, 0, 192);
|
||||||
|
|
||||||
drawText(10, 5, 18, TA_LEFT, colors.white, "Missions : %d / %d", completedMissions, numMissions);
|
drawText(10, 5, 18, TA_LEFT, colors.white, "Missions : %d / %d", completedMissions, numMissions);
|
||||||
|
@ -195,6 +235,55 @@ static void draw(void)
|
||||||
drawText(1010, 5, 18, TA_LEFT, colors.white, "Cells : %d / %d", 0, game.totalCells);
|
drawText(1010, 5, 18, TA_LEFT, colors.white, "Cells : %d / %d", 0, game.totalCells);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void drawMissionInfo(void)
|
||||||
|
{
|
||||||
|
int w, h, x, y, size, mid, i;
|
||||||
|
SDL_Rect r;
|
||||||
|
|
||||||
|
w = 800;
|
||||||
|
h = 550;
|
||||||
|
x = (SCREEN_WIDTH - w) / 2;
|
||||||
|
y = (SCREEN_HEIGHT - h) / 2;
|
||||||
|
|
||||||
|
drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0, 128);
|
||||||
|
|
||||||
|
drawRect(x, y, w, h, 0, 0, 0, 192);
|
||||||
|
drawOutlineRect(x, y, w, h, 255, 255, 255, 255);
|
||||||
|
|
||||||
|
drawText(SCREEN_WIDTH / 2, y + 25, 32, TA_CENTER, colors.white, selectedMission->name);
|
||||||
|
|
||||||
|
limitTextWidth(w - 150);
|
||||||
|
drawText(x + 15, y + 100, 22, TA_LEFT, colors.white, selectedMission->description);
|
||||||
|
limitTextWidth(0);
|
||||||
|
|
||||||
|
drawText(SCREEN_WIDTH / 2, y + h - 165, 24, TA_CENTER, colors.white, "Keys");
|
||||||
|
|
||||||
|
size = 65;
|
||||||
|
mid = size / 2;
|
||||||
|
|
||||||
|
y = (((SCREEN_HEIGHT - h) / 2) + h) - 100;
|
||||||
|
|
||||||
|
x = ((SCREEN_WIDTH - w) / 2) + 30;
|
||||||
|
|
||||||
|
for (i = 0 ; i < MAX_KEY_TYPES ; i++)
|
||||||
|
{
|
||||||
|
drawRect(x, y, size, size, 0, 0, 0, 128);
|
||||||
|
|
||||||
|
drawOutlineRect(x, y, size, size, 255, 255, 255, 255);
|
||||||
|
|
||||||
|
if (game.keys[i].value.i > 0)
|
||||||
|
{
|
||||||
|
r = getCurrentFrame(keySprites[i]);
|
||||||
|
|
||||||
|
blitRect(atlasTexture->texture, x + mid, y + mid + 7, &r, 1);
|
||||||
|
|
||||||
|
drawText(x + size - 5, y, 18, TA_RIGHT, colors.white, "%d", game.keys[i].value.i);
|
||||||
|
}
|
||||||
|
|
||||||
|
x += (size + 30);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int getMissionStatus(char *id)
|
static int getMissionStatus(char *id)
|
||||||
{
|
{
|
||||||
Tuple *t;
|
Tuple *t;
|
||||||
|
|
|
@ -30,6 +30,10 @@ extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int
|
||||||
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
|
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
|
||||||
extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a);
|
extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a);
|
||||||
extern void drawOutlineRect(int x, int y, int w, int h, int r, int g, int b, int a);
|
extern void drawOutlineRect(int x, int y, int w, int h, int r, int g, int b, int a);
|
||||||
|
extern void limitTextWidth(int width);
|
||||||
|
extern Sprite *getSprite(char *name);
|
||||||
|
extern SDL_Rect getCurrentFrame(Sprite *s);
|
||||||
|
extern void animateSprites(void);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
extern Colors colors;
|
extern Colors colors;
|
||||||
|
|
|
@ -28,11 +28,11 @@ void initAtlasTest(void)
|
||||||
dev.cheatKeys = 0;
|
dev.cheatKeys = 0;
|
||||||
dev.cheatPower = 1;
|
dev.cheatPower = 1;
|
||||||
dev.cheatHealth = 1;
|
dev.cheatHealth = 1;
|
||||||
|
dev.cheatLevels = 1;
|
||||||
|
|
||||||
loadGame();
|
loadGame();
|
||||||
|
|
||||||
initHub();
|
/*
|
||||||
|
|
||||||
loadWorld("beachApproach");
|
loadWorld("beachApproach");
|
||||||
|
|
||||||
initWorld();
|
initWorld();
|
||||||
|
@ -44,4 +44,7 @@ void initAtlasTest(void)
|
||||||
saveConfig();
|
saveConfig();
|
||||||
|
|
||||||
saveGame();
|
saveGame();
|
||||||
|
*/
|
||||||
|
|
||||||
|
initHub();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue