Basic credits

This commit is contained in:
Andrew "Akari" Alexeyew 2012-08-05 04:36:55 +03:00
parent 5f7eae47a5
commit e2b8163447
15 changed files with 302 additions and 17 deletions

View file

@ -53,6 +53,8 @@ set(SRCs
stages/stage5_events.c
stages/stage6.c
stages/stage6_events.c
ending.c
credits.c
resource/resource.c
resource/texture.c
resource/animation.c

220
src/credits.c Normal file
View file

@ -0,0 +1,220 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
* Copyright (C) 2012, Alexeyew Andrew <http://akari.thebadasschoobs.org/>
*/
#include "credits.h"
#include "global.h"
#include "stageutils.h"
#include "video.h"
static Stage3D bgcontext;
typedef struct CreditsEntry {
char **data;
int lines;
int time;
} CreditsEntry;
static struct {
CreditsEntry *entries;
int ecount;
float panelalpha;
} credits;
void credits_add(char *data, int time) {
CreditsEntry *e;
char *c, buf[256];
int l = 0, i = 0;
credits.entries = realloc(credits.entries, (++credits.ecount) * sizeof(CreditsEntry));
e = &(credits.entries[credits.ecount-1]);
e->time = time;
e->lines = 1;
for(c = data; *c; ++c)
if(*c == '\n') e->lines++;
e->data = malloc(e->lines * sizeof(char**));
for(c = data; *c; ++c) {
if(*c == '\n') {
buf[i] = 0;
e->data[l] = malloc(strlen(buf) + 1);
strcpy(e->data[l], buf);
i = 0;
++l;
} else {
buf[i++] = *c;
}
}
buf[i] = 0;
e->data[l] = malloc(strlen(buf) + 1);
strcpy(e->data[l], buf);
}
Vector **stage6_towerwall_pos(Vector pos, float maxrange);
void stage6_towerwall_draw(Vector pos);
void credits_skysphere_draw(Vector pos) {
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D, get_tex("stage6/sky")->gltex);
glPushMatrix();
glTranslatef(pos[0], pos[1], pos[2]-30);
float s = 370;
glScalef(s, s, s);
draw_model("skysphere");
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
}
void credits_fill(void) {
credits_add("Taisei Project", 200);
credits_add("String 1\nDerp 2\nHuge derp 3", 500);
credits_add("lol 1\nomg 2\nwtf 3", 500);
}
Vector **credits_skysphere_pos(Vector pos, float maxrange) {
return single3dpos(pos, maxrange, bgcontext.cx);
}
void credits_init(void) {
memset(&credits, 0, sizeof(credits));
init_stage3d(&bgcontext);
add_model(&bgcontext, credits_skysphere_draw, credits_skysphere_pos);
add_model(&bgcontext, stage6_towerwall_draw, stage6_towerwall_pos);
bgcontext.cx[0] = 0;
bgcontext.cx[1] = 600;
bgcontext.crot[0] = 0;
bgcontext.crot[1] = 10;
global.frames = 0;
credits_fill();
}
void credits_draw_entry(CreditsEntry *e) {
int time = global.frames - 400, i;
float first, other = 0, fadein = 1, fadeout = 1;
CreditsEntry *o;
for(o = credits.entries; o != e; ++o)
time -= o->time + CREDITS_ENTRY_FADEOUT;
if(time < 0)
return;
if(time <= CREDITS_ENTRY_FADEIN)
fadein = time / CREDITS_ENTRY_FADEIN;
if(time - e->time - CREDITS_ENTRY_FADEIN > 0)
fadeout = max(0, 1 - (time - e->time - CREDITS_ENTRY_FADEIN) / CREDITS_ENTRY_FADEOUT);
if(!fadein || !fadeout)
return;
first = stringheight(e->data[0], _fonts.mainmenu) * 1.2;
if(e->lines > 1)
other = stringheight(e->data[1], _fonts.standard) * 1.3;
glPushMatrix();
if(fadein < 1)
glTranslatef(0, (SCREEN_W * pow(1 - fadein, 2)) * 0.5, 0);
else if(fadeout < 1)
glTranslatef(0, (SCREEN_W * pow(1 - fadeout, 2)) * -0.5, 0);
glColor4f(1, 1, 1, fadein * fadeout);
for(i = 0; i < e->lines; ++i)
draw_text(AL_Center, 0, -0.5 * (i? (other * (e->lines - i) - first) : first), e->data[i], (i? _fonts.standard : _fonts.mainmenu));
glPopMatrix();
}
void credits_draw(void) {
//glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(-SCREEN_W/2, 0, 0);
glEnable(GL_DEPTH_TEST);
set_perspective_viewport(&bgcontext, 100, 9000, 0, 0, SCREEN_W, SCREEN_H);
draw_stage3d(&bgcontext, 10000);
bgcontext.cx[2] = 200 - global.frames * 50;
bgcontext.cx[1] = 500 + 100 * psin(global.frames / 100.0) * psin(global.frames / 200.0 + M_PI);
bgcontext.cx[0] += nfrand();
glPopMatrix();
set_ortho();
glPushMatrix();
glColor4f(0, 0, 0, credits.panelalpha * 0.7);
glTranslatef(SCREEN_W/4*3, SCREEN_H/2, 0);
glScalef(300, SCREEN_H, 1);
draw_quad();
glPopMatrix();
glPushMatrix();
glColor4f(1, 1, 1, credits.panelalpha * 0.7);
glTranslatef(SCREEN_W/4*3, SCREEN_H/2, 0);
int i; for(i = 0; i < credits.ecount; ++i)
credits_draw_entry(&(credits.entries[i]));
glPopMatrix();
fade_out(1 - (global.frames / 300.0));
}
void credits_process(void) {
TIMER(&global.frames);
FROM_TO(200, 300, 1)
credits.panelalpha += 0.01;
}
void credits_input(void) {
SDL_Event event;
while(SDL_PollEvent(&event)) {
//int sym = event.key.keysym.sym;
global_processevent(&event);
switch(event.type) {
case SDL_QUIT:
exit(1);
break;
}
}
}
void credits_free(void) {
int i, j;
for(i = 0; i < credits.ecount; ++i) {
CreditsEntry *e = &(credits.entries[i]);
for(j = 0; j < e->lines; ++j)
free(e->data[j]);
free(e->data);
}
free(credits.entries);
}
void credits_loop(void) {
credits_init();
while(1) {
credits_input();
credits_process();
credits_draw();
global.frames++;
SDL_GL_SwapBuffers();
frame_rate(&global.lasttime);
}
credits_free();
}

17
src/credits.h Normal file
View file

@ -0,0 +1,17 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
* Copyright (C) 2012, Alexeyew Andrew <http://akari.thebadasschoobs.org/>
*/
#ifndef CREDITS_H
#define CREDITS_H
void credits_loop(void);
#define CREDITS_ENTRY_FADEIN 200.0
#define CREDITS_ENTRY_FADEOUT 100.0
#endif

12
src/ending.c Normal file
View file

@ -0,0 +1,12 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
* Copyright (C) 2012, Alexeyew Andrew <http://akari.thebadasschoobs.org/>
*/
#include "ending.h"
void ending_loop(void) {
}

14
src/ending.h Normal file
View file

@ -0,0 +1,14 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
* Copyright (C) 2012, Alexeyew Andrew <http://akari.thebadasschoobs.org/>
*/
#ifndef ENDING_H
#define ENDING_H
void ending_loop(void);
#endif

View file

@ -114,6 +114,15 @@ inline double min(double a, double b) {
return (a < b)? a : b;
}
inline double clamp(double f, double lower, double upper) {
if(f < lower)
return lower;
if(f > upper)
return upper;
return f;
}
void take_screenshot()
{
FILE *out;

View file

@ -147,6 +147,7 @@ double psin();
// min(huge_costly_expression, another_huge_costly_expression)
double min(double, double);
double max(double, double);
double clamp(double, double, double);
double approach(double v, double t, double d);
int strendswith(char *s, char *e);
char* difficulty_name(Difficulty diff);

View file

@ -110,7 +110,9 @@ int main(int argc, char** argv) {
printf("** Invalid stage number. Quitting stage skip mode.\n");
}
#endif
credits_loop();
MenuData menu;
create_main_menu(&menu);
printf("-- menu\n");

View file

@ -16,6 +16,8 @@
#include "global.h"
#include "stage.h"
#include "ending.h"
#include "credits.h"
#include "paths/native.h"
void quit_menu(void *arg) {
@ -46,6 +48,9 @@ troll:
}
global.game_over = 0;
ending_loop();
credits_loop();
}
void enter_options(void *arg) {

View file

@ -82,6 +82,12 @@ int stringwidth(char *s, TTF_Font *font) {
return w;
}
int stringheight(char *s, TTF_Font *font) {
int h;
TTF_SizeText(font, s, NULL, &h);
return h;
}
int charwidth(char c, TTF_Font *font) {
char s[2];
s[0] = c;

View file

@ -22,6 +22,7 @@ Texture *load_text(const char *text, TTF_Font *font);
void draw_text(Alignment align, float x, float y, const char *text, TTF_Font *font);
void init_fonts();
int stringwidth(char *s, TTF_Font *font);
int stringheight(char *s, TTF_Font *font);
int charwidth(char c, TTF_Font *font);
struct Fonts {

View file

@ -55,15 +55,6 @@ void stage5_stairs_draw(Vector pos) {
glUseProgram(0);
}
float clamp(float f, float lower, float upper) {
if(f < lower)
return lower;
if(f > upper)
return upper;
return f;
}
void stage5_draw() {
set_perspective(&bgcontext, 100, 20000);
draw_stage3d(&bgcontext, 30000);

View file

@ -173,4 +173,4 @@ void stage6_end() {
void stage6_loop() {
// ShaderRule shaderrules[] = { stage6_bloom, NULL };
stage_loop(stage_get(6), stage6_start, stage6_end, stage6_draw, stage6_events, NULL, 3900);
}
}

View file

@ -23,15 +23,19 @@ void add_model(Stage3D *s, SegmentDrawRule draw, SegmentPositionRule pos) {
s->models[s->msize - 1].pos = pos;
}
void set_perspective(Stage3D *s, float n, float f) {
void set_perspective_viewport(Stage3D *s, float n, float f, int vx, int vy, int vw, int vh) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glTranslatef(-(VIEWPORT_W/2.0)/SCREEN_W, 0, 0);
glTranslatef(-(vw/2.0)/SCREEN_W, 0, 0);
gluPerspective(s->projangle, 1, n, f);
glTranslatef(VIEWPORT_X+VIEWPORT_W/2.0, VIEWPORT_Y+VIEWPORT_H/2.0, 0);
glTranslatef(vx+vw/2.0, vy+vh/2.0, 0);
glMatrixMode(GL_MODELVIEW);
glMatrixMode(GL_MODELVIEW);
}
inline void set_perspective(Stage3D *s, float n, float f) {
set_perspective_viewport(s, n, f, VIEWPORT_X, VIEWPORT_Y, VIEWPORT_W, VIEWPORT_H);
}
void draw_stage3d(Stage3D *s, float maxrange) {

View file

@ -38,7 +38,8 @@ void init_stage3d(Stage3D *s);
void add_model(Stage3D *s, SegmentDrawRule draw, SegmentPositionRule pos);
void set_perspective(Stage3D *s, float near, float far);
void set_perspective_viewport(Stage3D *s, float n, float f, int vx, int vy, int vw, int vh);
inline void set_perspective(Stage3D *s, float near, float far);
void draw_stage3d(Stage3D *s, float maxrange);
void free_stage3d(Stage3D *s);
@ -46,4 +47,4 @@ void free_stage3d(Stage3D *s);
Vector **linear3dpos(Vector q, float maxrange, Vector p, Vector r);
Vector **single3dpos(Vector q, float maxrange, Vector p);
#endif
#endif