Hi everyone. I am a C student and I am making a library to improve my projects.
I am using gcc on Linux and MingW on Windows. When I open my project on Windows
the Image and the background works well, but when I go to Linux the same backgrounds
which work on Windows don’t show.
What did I miss?
Here is my main code code:
Code:
/*
- File: main.h
- Author: Bean Dragon*
- Created on 19 de Mar?o de 2015, 21:50
*/
#ifndef MAIN_H
#define MAIN_H
#include <place.h>
#ifdef __cplusplus
extern “C” {
#endif
static SPRITE * sprite_global = NULL;
///static SOUND * sound_global = NULL;
static STATUS init(PLACE ** to);
static OBJECT * object_start(PLACE * to);
static STATUS update(PLACE * to);
static void destroy(PLACE * to);
static STATUS init(PLACE ** to) {
*to = place_set(
0,
machine_set(0, "Animation", 1280, 800, 0, 0, SDL_INIT_EVERYTHING,
SDL_WINDOW_FULLSCREEN, audio_standard()),
connection_set(NULL, 5000));
if (!(*to)->start(*to)) {
fprintf(stderr, "Could not init machine\n\n");
return (Off);
}
#ifdef WIN32
if (!sprite_global) {/// load all the images from project here
sprite_next_front(
&sprite_global,
sprite_set((*to)->machine->RENDERER,
“E:/Image/Background/green.jpg”, “Cliff”));
sprite_next_front(
&sprite_global,
sprite_set((*to)->machine->RENDERER,
“E:/Image/sprite/twinsen/twinsen-front-up.png”,
“Twinsen Front Up”));
sprite_next_front(
&sprite_global,
sprite_set((*to)->machine->RENDERER,
“E:/Image/sprite/twinsen/twinsen-back.png”,
“Twinsen Back”));
sprite_next_front(
&sprite_global,
sprite_set((*to)->machine->RENDERER,
“E:/Image/sprite/twinsen/twinsen-side-up.png”,
“Twinsen Side Up”));
sprite_next_front(
&sprite_global,
sprite_set((*to)->machine->RENDERER,
“E:/Image/sprite/twinsen/twinsen-diagonal-up1.png”,
“Twinsen Diagonal Up”));
sprite_next_front(
&sprite_global,
sprite_set((*to)->machine->RENDERER,
“E:/Image/sprite/twinsen/twinsen-back-diagonal.png”,
“Twinsen Back Diagonal”));
}
#elif linux
if (!sprite_global) {/// load all the images from project here
sprite_next_front(&sprite_global, sprite_set((*to)->machine->RENDERER, “/media/bean/Traveler/Image/Background/Rock.png”, “Cliff”));
sprite_next_front(&sprite_global, sprite_set((*to)->machine->RENDERER, “/media/bean/Traveler/Image/sprite/twinsen/twinsen-front-up.png”, “Twinsen Front Up”));
sprite_next_front(&sprite_global, sprite_set((*to)->machine->RENDERER, “/media/bean/Traveler/Image/sprite/twinsen/twinsen-back.png”, “Twinsen Back”));
sprite_next_front(&sprite_global, sprite_set((*to)->machine->RENDERER, “/media/bean/Traveler/Image/sprite/twinsen/twinsen-side-up.png”, “Twinsen Side Up”));
sprite_next_front(&sprite_global, sprite_set((*to)->machine->RENDERER, “/media/bean/Traveler/Image/sprite/twinsen/twinsen-diagonal-up1.png”, “Twinsen Diagonal Up”));
sprite_next_front(&sprite_global, sprite_set((*to)->machine->RENDERER, “/media/bean/Traveler/Image/sprite/twinsen/twinsen-back-diagonal.png”, “Twinsen Back Diagonal”));
}
#endif
double x_speed = 20.0, y_speed = 20.0;
(*to)->map_set(
*to,
object_set(0, “Map”, 0, 0, x_speed, y_speed, timer_set(1),
sprite_get(sprite_global, “Cliff”),
#ifdef WIN32
sound_set(“E:/music/game/mus.mp3”, NULL)));
#elif linux
sound_set("/media/bean/Traveler/music/game/mus.mp3", NULL)));
#endif
//(*to)->map->width = 1000;
//(to)->map->height = 1000;
(to)->object = object_start(to);
///fprintf(stdout,"%li\n", (*to)->MAX);
return (On);
}
static OBJECT * object_start(PLACE * to) {
if (to != NULL && to->map != NULL) {
static OBJECT * object = NULL;
long int id, max = 10;
int x = (rand() % to->map_width_get(to));
int y = (rand() % to->map_height_get(to));
double x_speed = 1.0, y_speed = 1.0;
for (id = 0; id < max; id++) {
x = (rand() % to->map_width_get(to));
y = (rand() % ((to->map_height_get(to) / 100) * 75)), y
+= (to->map_height_get(to) / 100) * 25;
if (object != NULL) {
object->next_back(
&object,
object_set(id, "Hero", x, y, x_speed, y_speed,
timer_set(1000 / 25),
sprite_get(sprite_global, "Twinsen Front Up"),
sound_set(NULL, "E:/sound/SonicRing.wav")));
to->MAX++;
} else {
/// like to say OBJECT * object = new Object(...) in c++
object = object_set(id, "Hero", x, y, x_speed + 9.0,
y_speed + 9.0, timer_set(1000 / 25),
sprite_get(sprite_global, "Twinsen Front Up"),
sound_set(NULL, "E:/sound/SonicRing.wav"));
to->MAX++;
}
}
return (object);
}
return (NULL);
}
#define REACH 500
static STATUS update(PLACE * to) {
if (to && to->object) {
static STATUS camera_first_adjust = Off;
long int selected = 0;
OBJECT * hero = to->object->search(to->object, selected), *object =
NULL;
if (camera_first_adjust == Off) {
to->camera_object(to, hero);
camera_first_adjust = On;
}
static STATUS route = Off;
if (!music_is_playing(to->map))
music_play(to->map, 0);
to->camera_mouse(to);
///fprintf(stdout,"#\n");
for (object = to->object; object; object = object->next) {
if (object->id == selected) {
if (to->mouse_button(to, SDL_BUTTON_RIGHT) && to->type(to,
SDL_MOUSEBUTTONDOWN)) {
object->x_route = to->mouse_x_get(to);
object->y_route = to->mouse_y_get(to);
route = On;
}
if (timer_get(object->timer)) {
if (to->key_get(SDL_SCANCODE_LEFT)) {
object->image_set(object,
sprite_get(sprite_global, "Twinsen Side Up"));
object->flip = SDL_FLIP_HORIZONTAL;
object->x_route = object->x - object->x_speed;
to->camera_object(to, object);
route = On;
}
if (to->key_get(SDL_SCANCODE_RIGHT)) {
object->image_set(object,
sprite_get(sprite_global, "Twinsen Side Up"));
object->flip = SDL_FLIP_NONE;
object->x_route = object->x + object->x_speed;
to->camera_object(to, object);
route = On;
}
if (to->key_get(SDL_SCANCODE_UP)) {
object->image_set(object,
sprite_get(sprite_global, "Twinsen Back"));
object->y_route = object->y - object->y_speed;
;
to->camera_object(to, object);
route = On;
}
if (to->key_get(SDL_SCANCODE_DOWN)) {
object->image_set(object,
sprite_get(sprite_global, "Twinsen Front Up"));
object->flip = SDL_FLIP_NONE;
object->y_route = object->y + object->y_speed;
to->camera_object(to, object);
route = On;
}
if (to->key_get(SDL_SCANCODE_LCTRL) && to->key_get(
SDL_SCANCODE_Z) && to->key_get(SDL_SCANCODE_EQUALS)) {
object->width_zoom += 0.1;
object->height_zoom += 0.1;
}
if (to->key_get(SDL_SCANCODE_LCTRL) && to->key_get(
SDL_SCANCODE_Z) && to->key_get(SDL_SCANCODE_MINUS)) {
object->width_zoom -= 0.1;
object->height_zoom -= 0.1;
}
if (to->key_get(SDL_SCANCODE_LCTRL) && !to->key_get(
SDL_SCANCODE_LALT) && to->key_get(SDL_SCANCODE_S)
&& to->key_get(SDL_SCANCODE_EQUALS)) {
object->x_speed += 0.1;
object->y_speed += 0.1;
///fprintf(stdout,"object speed x %lf y %lf\n",object->x_speed,object->y_speed);
}
if (to->key_get(SDL_SCANCODE_LCTRL) && !to->key_get(
SDL_SCANCODE_LALT) && to->key_get(SDL_SCANCODE_S)
&& to->key_get(SDL_SCANCODE_MINUS)) {
object->x_speed -= 0.1;
object->y_speed -= 0.1;
///fprintf(stdout,"object speed x %lf y %lf\n",object->x_speed,object->y_speed);
}
if (to->key_get(SDL_SCANCODE_LCTRL) && to->key_get(
SDL_SCANCODE_LALT) && to->key_get(SDL_SCANCODE_S)
&& to->key_get(SDL_SCANCODE_EQUALS)) {
to->map->x_speed += 0.1;
to->map->y_speed += 0.1;
///fprintf(stdout,"map speed x %lf y %lf\n",to->map->x_speed,to->map->y_speed);
}
if (to->key_get(SDL_SCANCODE_LCTRL) && to->key_get(
SDL_SCANCODE_LALT) && to->key_get(SDL_SCANCODE_S)
&& to->key_get(SDL_SCANCODE_MINUS)) {
to->map->x_speed -= 0.1;
to->map->y_speed -= 0.1;
///fprintf(stdout,"map speed x %lf y %lf\n",to->map->x_speed,to->map->y_speed);
}
if (to->key_get(SDL_SCANCODE_LCTRL) && to->key_get(
SDL_SCANCODE_A) && to->key_get(SDL_SCANCODE_EQUALS)) {
object->angle += 1.0;
}
if (to->key_get(SDL_SCANCODE_LCTRL) && to->key_get(
SDL_SCANCODE_A) && to->key_get(SDL_SCANCODE_MINUS)) {
object->angle -= 1.0;
}
if (to->key_get(SDL_SCANCODE_LCTRL) && to->key_get(
SDL_SCANCODE_A) && to->key_get(SDL_SCANCODE_0)) {
object->angle = 0.0;
}
if (to->key_get(SDL_SCANCODE_LCTRL) && to->key_get(
SDL_SCANCODE_T) && to->key_get(SDL_SCANCODE_EQUALS)) {
object->color->a += 1;
}
if (to->key_get(SDL_SCANCODE_LCTRL) && to->key_get(
SDL_SCANCODE_T) && to->key_get(SDL_SCANCODE_MINUS)) {
object->color->a -= 1;
}
if (to->key_get(SDL_SCANCODE_LCTRL) && to->key_get(
SDL_SCANCODE_T) && to->key_get(SDL_SCANCODE_0)) {
object->color->a = 255;
}
if (route) {
if (!object_route(to, object, object->x_route,
object->y_route)) {
if (object->where == NORTH) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Back"));
}
if (object->where == NORTHEAST) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Back Diagonal"));
object->flip = SDL_FLIP_NONE;
}
if (object->where == NORTHWEST) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Back Diagonal"));
object->flip = SDL_FLIP_HORIZONTAL;
}
if (object->where == SOUTH) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Front Up"));
}
if (object->where == SOUTHEAST) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Diagonal Up"));
object->flip = SDL_FLIP_HORIZONTAL;
}
if (object->where == SOUTHWEST) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Diagonal Up"));
object->flip = SDL_FLIP_NONE;
}
if (object->where == WEST) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Side Up"));
object->flip = SDL_FLIP_HORIZONTAL;
}
if (object->where == EAST) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Side Up"));
object->flip = SDL_FLIP_NONE;
}
} else
route = Off;
}
timer_start(object->timer);
}
} else if (object->id != selected) { /// controle da maquina
if (timer_get(object->timer)) {
if (object_route(to, object, object->x_route,
object->y_route)) {
object->x_route = (rand() % (int) (to->map->width
* to->map->width_zoom));
int y_size = (int) (to->map->height
* to->map->height_zoom);
object->y_route = (rand() % ((y_size / 100) * 75)), object->y_route
+= ((y_size / 100) * 25);
} else {
OBJECT * hero = object->search(to->object, selected);
if (object->x >= hero->x - REACH && object->x
<= hero->x + REACH && object->y >= hero->y
- REACH && object->y <= hero->y + REACH) {
object->x_route = hero->x;
object->y_route = hero->y;
///fprintf(stdout, "%li following %li\n",object->id,hero->id);
}
if (!object_route(to, object, object->x_route,
object->y_route)) {
if (object->where == NORTH) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Back"));
}
if (object->where == NORTHEAST) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Back Diagonal"));
object->flip = SDL_FLIP_NONE;
}
if (object->where == NORTHWEST) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Back Diagonal"));
object->flip = SDL_FLIP_HORIZONTAL;
}
if (object->where == SOUTH) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Front Up"));
}
if (object->where == SOUTHEAST) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Diagonal Up"));
object->flip = SDL_FLIP_HORIZONTAL;
}
if (object->where == SOUTHWEST) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Diagonal Up"));
object->flip = SDL_FLIP_NONE;
}
if (object->where == WEST) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Side Up"));
object->flip = SDL_FLIP_HORIZONTAL;
}
if (object->where == EAST) {
object->image_set(
object,
sprite_get(sprite_global,
"Twinsen Side Up"));
object->flip = SDL_FLIP_NONE;
}
}
}
timer_start(object->timer);
}
}
}
///fprintf(stdout,"*\n");
to->update(to);
to->show(to);
if (PLACE_EXIT(to))
to->stop(to);
return (On);
}
return (Off);
}
static void destroy(PLACE * to) {
to->destroy(to);
}
#ifdef __cplusplus
}
#endif
#endif /* MAIN_H */
And Here is the function that I am using to load the sprites
Code:
PLACE_CALL SPRITE *
sprite_set(SDL_Renderer * renderer, SDL_PixelFormat * pixel, const char * path, char * name) {
if (renderer == NULL)
return (NULL);
SPRITE * to = (SPRITE *) malloc(sizeof (SPRITE));
if (to == NULL)
return (NULL);
if (name != NULL) {
to->name = strdup(name);
}
SDL_Surface * image = (path) ? IMG_Load(path) : NULL;
if (!image)return (NULL);
SDL_Surface * optimized = SDL_ConvertSurface(image,pixel,0);
to->sprite = (optimized != NULL) ? SDL_CreateTextureFromSurface(renderer,optimized) : NULL;
to->next = NULL;
to->preview = NULL;
return (to);
}
I don’t know why it does happen. Help me, please.