removing SDL_image dependency
taisei now uses plain libpng to load graphics ... and various other changes I don't remember.
This commit is contained in:
parent
aa1ed4d3c3
commit
b16df91ad5
14 changed files with 6577 additions and 2601 deletions
3
README
3
README
|
@ -7,7 +7,8 @@ Taisei is an open clone of the Touhou series. Touhou is a one-man project of sho
|
|||
2. Installation
|
||||
|
||||
Dependencies:
|
||||
- SDL, SDL_image, SDL_ttf
|
||||
- SDL, SDL_ttf
|
||||
- libpng
|
||||
- OpenGL
|
||||
- OpenAL, ALUT
|
||||
- CMake (build system)
|
||||
|
|
BIN
gfx/ani_1_8_5_cirno.png
Normal file
BIN
gfx/ani_1_8_5_cirno.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
8890
gfx/cirno.svg
8890
gfx/cirno.svg
File diff suppressed because it is too large
Load diff
Before Width: | Height: | Size: 298 KiB After Width: | Height: | Size: 487 KiB |
128
gfx/dialog/youmu.svg
Normal file
128
gfx/dialog/youmu.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 496 KiB |
|
@ -23,13 +23,13 @@ find_package(SDL REQUIRED)
|
|||
find_package(OpenGL REQUIRED)
|
||||
find_package(OpenAL REQUIRED)
|
||||
find_package(ALUT REQUIRED)
|
||||
find_package(SDL_image REQUIRED)
|
||||
find_package(PNG REQUIRED)
|
||||
find_package(SDL_ttf REQUIRED)
|
||||
|
||||
add_definitions(-DPREFIX="${CMAKE_INSTALL_PREFIX}" -DGL_GLEXT_PROTOTYPES)
|
||||
|
||||
include_directories(${SDL_INCLUDE_DIRS} ${ALUT_INCLUDE_DIRS})
|
||||
add_executable(taisei ${SRCs})
|
||||
target_link_libraries(taisei ${SDL_LIBRARY} ${OPENGL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLTTF_LIBRARY} ${OPENAL_LIBRARY} ${ALUT_LIBRARY})
|
||||
target_link_libraries(taisei ${SDL_LIBRARY} ${OPENGL_LIBRARY} ${PNG_LIBRARY} ${SDLTTF_LIBRARY} ${OPENAL_LIBRARY} ${ALUT_LIBRARY})
|
||||
|
||||
install(TARGETS taisei RUNTIME DESTINATION bin)
|
||||
|
|
|
@ -19,7 +19,8 @@ void init_fonts() {
|
|||
|
||||
Texture *load_text(const char *text, TTF_Font *font) {
|
||||
Texture *tex = malloc(sizeof(Texture));
|
||||
SDL_Surface *surf = TTF_RenderText_Blended(font, text, ((SDL_Color){255,255,255}));
|
||||
SDL_Color clr = {255,255,255};
|
||||
SDL_Surface *surf = TTF_RenderText_Blended(font, text, clr);
|
||||
assert(surf != NULL);
|
||||
|
||||
load_sdl_surf(surf, tex);
|
||||
|
|
|
@ -94,8 +94,7 @@ void player_logic(Player* plr) {
|
|||
if(!(global.frames % 4)) {
|
||||
create_projectile("youmu", plr->pos + 10 - I*20, NULL, linear, -20I)->type = PlrProj;
|
||||
create_projectile("youmu", plr->pos - 10 - I*20, NULL, linear, -20I)->type = PlrProj;
|
||||
|
||||
|
||||
|
||||
if(plr->power >= 2) {
|
||||
float a = 0.20;
|
||||
if(plr->focus > 0) a = 0.06;
|
||||
|
@ -125,7 +124,7 @@ void plr_bomb(Player *plr) {
|
|||
if(e->hp != ENEMY_IMMUNE)
|
||||
e->hp = 0;
|
||||
|
||||
delete_projectiles();
|
||||
delete_projectiles(&global.projs);
|
||||
|
||||
play_sound("laser1");
|
||||
|
||||
|
|
|
@ -34,22 +34,20 @@ void youmu_opposite_logic(Enemy *e, int t) {
|
|||
e->pos0 = e->pos + plr->pos;
|
||||
}
|
||||
|
||||
void youmu_homing(complex *pos, complex *pos0, float *angle, int t, complex* a) { // a[0]: velocity
|
||||
*angle = t/30.0;
|
||||
void youmu_homing(Projectile *p, int t) { // a[0]: velocity
|
||||
p->angle = t/30.0;
|
||||
|
||||
complex tv = 0;
|
||||
|
||||
if(global.enemies != NULL)
|
||||
tv = cexp(I*carg(global.enemies[0].pos - *pos));;
|
||||
tv = cexp(I*carg(global.enemies[0].pos - p->pos));;
|
||||
if(global.boss != NULL)
|
||||
tv = cexp(I*carg(global.boss->pos - *pos));;
|
||||
tv = cexp(I*carg(global.boss->pos - p->pos));;
|
||||
|
||||
if(t > 150 || tv == 0)
|
||||
tv = - ((rand()%3)-1)/2.0 - 0.5I;
|
||||
|
||||
complex s0 = 0;
|
||||
|
||||
*pos += a[0]*log(t + 1) + tv*t/15.0;
|
||||
*pos0 = *pos;
|
||||
p->pos += p->args[0]*log(t + 1) + tv*t/15.0;
|
||||
p->pos0 = p->pos;
|
||||
|
||||
}
|
|
@ -9,10 +9,11 @@
|
|||
#define PLRMODES_H
|
||||
|
||||
#include "enemy.h"
|
||||
#include "projectile.h"
|
||||
|
||||
void youmu_opposite_draw(Enemy *e, int t);
|
||||
void youmu_opposite_logic(Enemy *e, int t);
|
||||
|
||||
void youmu_homing(complex *pos, complex *pos0, float *angle, int t, complex* a);
|
||||
void youmu_homing(Projectile *p, int t);
|
||||
|
||||
#endif
|
|
@ -26,9 +26,9 @@ inline Color *rgb(float r, float g, float b) {
|
|||
return rgba(r, g, b, 1.0);
|
||||
}
|
||||
|
||||
Projectile *create_projectile(char *name, complex pos, Color *clr,
|
||||
ProjRule rule, complex args, ...) {
|
||||
Projectile *p = create_element((void **)&global.projs, sizeof(Projectile));
|
||||
Projectile *create_projectile_d(Projectile **dest, char *name, complex pos, Color *clr,
|
||||
ProjRule rule, complex args, ...) {
|
||||
Projectile *p = create_element((void **)dest, sizeof(Projectile));
|
||||
|
||||
char buf[128];
|
||||
strcpy(buf, "proj/");
|
||||
|
@ -61,12 +61,12 @@ void _delete_projectile(void **projs, void *proj) {
|
|||
delete_element(projs, proj);
|
||||
}
|
||||
|
||||
void delete_projectile(Projectile *proj) {
|
||||
_delete_projectile((void **)&global.projs, proj);
|
||||
void delete_projectile(Projectile **projs, Projectile *proj) {
|
||||
_delete_projectile((void **)projs, proj);
|
||||
}
|
||||
|
||||
void delete_projectiles() {
|
||||
delete_all_elements((void **)&global.projs, _delete_projectile);
|
||||
void delete_projectiles(Projectile **projs) {
|
||||
delete_all_elements((void **)projs, _delete_projectile);
|
||||
}
|
||||
|
||||
int collision_projectile(Projectile *p) {
|
||||
|
@ -95,13 +95,13 @@ int collision_projectile(Projectile *p) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void draw_projectiles() {
|
||||
void draw_projectiles(Projectile *projs) {
|
||||
Projectile *proj;
|
||||
|
||||
GLuint shader = get_shader("bullet_color");
|
||||
glUseProgramObjectARB(shader);
|
||||
|
||||
for(proj = global.projs; proj; proj = proj->next) {
|
||||
for(proj = projs; proj; proj = proj->next) {
|
||||
if(proj->clr == NULL)
|
||||
glUseProgramObjectARB(0);
|
||||
|
||||
|
@ -120,12 +120,15 @@ void draw_projectiles() {
|
|||
glUseProgramObjectARB(0);
|
||||
}
|
||||
|
||||
void process_projectiles() {
|
||||
Projectile *proj = global.projs, *del = NULL;
|
||||
void process_projectiles(Projectile **projs, short collision) {
|
||||
Projectile *proj = *projs, *del = NULL;
|
||||
while(proj != NULL) {
|
||||
proj->rule(&proj->pos, &proj->pos0, &proj->angle, global.frames - proj->birthtime, proj->args);
|
||||
proj->rule(proj, global.frames - proj->birthtime);
|
||||
|
||||
int v = 0;
|
||||
if(collision)
|
||||
v = collision_projectile(proj);
|
||||
|
||||
int v = collision_projectile(proj);
|
||||
if(v == 1 && (global.frames - abs(global.plr.recovery)) >= 0)
|
||||
plr_death(&global.plr);
|
||||
|
||||
|
@ -133,7 +136,7 @@ void process_projectiles() {
|
|||
|| cimag(proj->pos) + proj->tex->h/2 < 0 || cimag(proj->pos) - proj->tex->h/2 > VIEWPORT_H) {
|
||||
del = proj;
|
||||
proj = proj->next;
|
||||
delete_projectile(del);
|
||||
delete_projectile(projs, del);
|
||||
if(proj == NULL) break;
|
||||
} else {
|
||||
proj = proj->next;
|
||||
|
@ -141,7 +144,7 @@ void process_projectiles() {
|
|||
}
|
||||
}
|
||||
|
||||
void linear(complex *pos, complex *pos0, float *angle, int time, complex* a) { // sure is physics in here; a[0]: velocity
|
||||
*angle = carg(a[0]);
|
||||
*pos = *pos0 + a[0]*time;
|
||||
void linear(Projectile *p, int t) { // sure is physics in here; a[0]: velocity
|
||||
p->angle = carg(p->args[0]);
|
||||
p->pos = p->pos0 + p->args[0]*t;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ typedef struct {
|
|||
} Color;
|
||||
|
||||
struct Projectile;
|
||||
typedef void (*ProjRule)(complex *pos, complex *pos0, float *angle, int time, complex* args);
|
||||
typedef void (*ProjRule)(struct Projectile *p, int t);
|
||||
|
||||
typedef struct Projectile {
|
||||
struct Projectile *next;
|
||||
|
@ -50,13 +50,14 @@ Color *rgba(float r, float g, float b, float a);
|
|||
|
||||
inline Color *rgb(float r, float g, float b);
|
||||
|
||||
Projectile *create_projectile(char *name, complex pos, Color *clr, ProjRule rule, complex args, ...);
|
||||
void delete_projectile(Projectile *proj);
|
||||
void delete_projectiles();
|
||||
void draw_projectile(Projectile *proj);
|
||||
void draw_projectiles();
|
||||
#define create_particle(name, pos, clr, rule, args) (create_projectile_d(&global.particles, name, pos, clr, rule, args))
|
||||
#define create_projectile(name, pos, clr, rule, args) (create_projectile_d(&global.projs, name, pos, clr, rule, args))
|
||||
Projectile *create_projectile_d(Projectile **dest, char *name, complex pos, Color *clr, ProjRule rule, complex args, ...);
|
||||
void delete_projectile(Projectile **dest, Projectile *proj);
|
||||
void delete_projectiles(Projectile **dest);
|
||||
void draw_projectiles(Projectile *projs);
|
||||
int collision_projectile(Projectile *p);
|
||||
void process_projectiles();
|
||||
void process_projectiles(Projectile **projs, short collision);
|
||||
|
||||
void linear(complex *pos, complex *pos0, float *angle, int time, complex* args);
|
||||
void linear(Projectile *p, int t);
|
||||
#endif
|
|
@ -89,7 +89,7 @@ void stage_draw() {
|
|||
apply_bg_shaders();
|
||||
player_draw(&global.plr);
|
||||
|
||||
draw_projectiles();
|
||||
draw_projectiles(global.projs);
|
||||
draw_enemies(global.enemies);
|
||||
draw_items();
|
||||
draw_lasers();
|
||||
|
@ -162,7 +162,7 @@ void stage_logic() {
|
|||
player_logic(&global.plr);
|
||||
|
||||
process_enemies(&global.enemies);
|
||||
process_projectiles();
|
||||
process_projectiles(&global.projs, True);
|
||||
process_items();
|
||||
process_lasers();
|
||||
|
||||
|
@ -185,7 +185,7 @@ void stage_logic() {
|
|||
}
|
||||
|
||||
void stage_end() {
|
||||
delete_projectiles();
|
||||
delete_projectiles(&global.projs);
|
||||
delete_enemies(&global.enemies);
|
||||
delete_items();
|
||||
delete_lasers();
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <png.h>
|
||||
#include "audio.h"
|
||||
#include "shader.h"
|
||||
#include "list.h"
|
||||
|
@ -91,7 +92,7 @@ void delete_textures() {
|
|||
}
|
||||
|
||||
Texture *load_texture(const char *filename) {
|
||||
SDL_Surface *surface = IMG_Load(filename);
|
||||
SDL_Surface *surface = load_png(filename);
|
||||
|
||||
if(surface == NULL)
|
||||
err(-1,"load_texture():\n!- cannot load '%s'", filename);
|
||||
|
@ -112,6 +113,68 @@ Texture *load_texture(const char *filename) {
|
|||
return texture;
|
||||
}
|
||||
|
||||
SDL_Surface *load_png(const char *filename) {
|
||||
FILE *fp = fopen(filename, "rb");
|
||||
if(!fp)
|
||||
err(-1, "Error loading '%s'", filename);
|
||||
|
||||
png_structp png_ptr;
|
||||
if(!(png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
|
||||
errx(-1,"Error loading '%s'", filename);
|
||||
|
||||
png_infop info_ptr;
|
||||
if(!(info_ptr = png_create_info_struct(png_ptr))) {
|
||||
png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||
errx(-1,"Error loading '%s'", filename);
|
||||
}
|
||||
|
||||
png_infop end_info;
|
||||
if(!(end_info = png_create_info_struct(png_ptr))) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
errx(-1,"Error loading '%s'", filename);
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, fp);
|
||||
|
||||
png_read_png(png_ptr, info_ptr, 0, NULL);
|
||||
|
||||
int width = png_get_image_width(png_ptr, info_ptr);
|
||||
int height = png_get_image_height(png_ptr, info_ptr);
|
||||
int depth = png_get_bit_depth(png_ptr, info_ptr);
|
||||
|
||||
png_bytep *row_pointers = png_get_rows(png_ptr, info_ptr);
|
||||
|
||||
Uint32 *pixels = malloc(sizeof(Uint32)*width*height);
|
||||
|
||||
int i;
|
||||
for(i = 0; i < height; i++)
|
||||
memcpy(&pixels[i*width], row_pointers[i], sizeof(Uint32)*width);
|
||||
|
||||
Uint32 rmask, gmask, bmask, amask;
|
||||
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
rmask = 0xff000000;
|
||||
gmask = 0x00ff0000;
|
||||
bmask = 0x0000ff00;
|
||||
amask = 0x000000ff;
|
||||
#else
|
||||
rmask = 0x000000ff;
|
||||
gmask = 0x0000ff00;
|
||||
bmask = 0x00ff0000;
|
||||
amask = 0xff000000;
|
||||
#endif
|
||||
|
||||
SDL_Surface *res = SDL_CreateRGBSurfaceFrom(pixels, width, height, depth*4, 0, rmask, gmask, bmask, amask);
|
||||
if(!res)
|
||||
errx(-1,"Error loading '%s'", filename);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void load_sdl_surf(SDL_Surface *surface, Texture *texture) {
|
||||
glGenTextures(1, &texture->gltex);
|
||||
glBindTexture(GL_TEXTURE_2D, texture->gltex);
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#define TEXTURE_H
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL/SDL_image.h>
|
||||
#include <SDL/SDL_opengl.h>
|
||||
#include <math.h>
|
||||
|
||||
|
@ -30,6 +29,8 @@ Texture *get_tex(char *name);
|
|||
void load_textures();
|
||||
void load_resources();
|
||||
|
||||
SDL_Surface *load_png(const char *filename);
|
||||
|
||||
void delete_texture(void **texs, void *tex);
|
||||
void delete_textures();
|
||||
|
||||
|
|
Loading…
Reference in a new issue