Agrego el yunque y su colisión.

master
Félix Arreola Rodríguez 2018-06-19 13:51:02 -05:00
parent 950e548c6a
commit bbcd25ff80
28 changed files with 255 additions and 24 deletions

View File

@ -101,7 +101,31 @@ nobase_dist_gamedata_DATA = images/background.png \
images/bag_stack_58.png \ images/bag_stack_58.png \
images/bag_stack_59.png \ images/bag_stack_59.png \
images/bag_stack_60.png \ images/bag_stack_60.png \
images/truck.png images/truck.png \
images/anvil_00.png \
images/anvil_01.png \
images/anvil_02.png \
images/anvil_03.png \
images/anvil_04.png \
images/anvil_05.png \
images/anvil_06.png \
images/anvil_07.png \
images/anvil_08.png \
images/anvil_09.png \
images/anvil_10.png \
images/anvil_11.png \
images/anvil_12.png \
images/anvil_13.png \
images/anvil_14.png \
images/anvil_15.png \
images/anvil_16.png \
images/anvil_17.png \
images/anvil_18.png \
images/anvil_19.png \
images/anvil_20.png \
images/anvil_21.png \
images/anvil_22.png \
images/anvil_23.png
# Instalar los archivos .desktop e iconos # Instalar los archivos .desktop e iconos
applicationsdir = $(datadir)/applications applicationsdir = $(datadir)/applications

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -73,7 +73,10 @@ typedef struct _BeanBag {
int throw_length; int throw_length;
int frame; int frame;
union {
const int (*bag_points)[3]; const int (*bag_points)[3];
const int (*object_points)[2];
};
struct _BeanBag *prev; struct _BeanBag *prev;
struct _BeanBag *next; struct _BeanBag *next;
@ -157,6 +160,31 @@ enum {
IMG_TRUCK, IMG_TRUCK,
IMG_ANVIL_0,
IMG_ANVIL_1,
IMG_ANVIL_2,
IMG_ANVIL_3,
IMG_ANVIL_4,
IMG_ANVIL_5,
IMG_ANVIL_6,
IMG_ANVIL_7,
IMG_ANVIL_8,
IMG_ANVIL_9,
IMG_ANVIL_10,
IMG_ANVIL_11,
IMG_ANVIL_12,
IMG_ANVIL_13,
IMG_ANVIL_14,
IMG_ANVIL_15,
IMG_ANVIL_16,
IMG_ANVIL_17,
IMG_ANVIL_18,
IMG_ANVIL_19,
IMG_ANVIL_20,
IMG_ANVIL_21,
IMG_ANVIL_22,
IMG_ANVIL_23,
NUM_IMAGES NUM_IMAGES
}; };
@ -231,7 +259,32 @@ const char *images_names[NUM_IMAGES] = {
"images/bag_stack_59.png", "images/bag_stack_59.png",
"images/bag_stack_60.png", "images/bag_stack_60.png",
"images/truck.png" "images/truck.png",
"images/anvil_00.png",
"images/anvil_01.png",
"images/anvil_02.png",
"images/anvil_03.png",
"images/anvil_04.png",
"images/anvil_05.png",
"images/anvil_06.png",
"images/anvil_07.png",
"images/anvil_08.png",
"images/anvil_09.png",
"images/anvil_10.png",
"images/anvil_11.png",
"images/anvil_12.png",
"images/anvil_13.png",
"images/anvil_14.png",
"images/anvil_15.png",
"images/anvil_16.png",
"images/anvil_17.png",
"images/anvil_18.png",
"images/anvil_19.png",
"images/anvil_20.png",
"images/anvil_21.png",
"images/anvil_22.png",
"images/anvil_23.png"
}; };
enum { enum {
@ -580,6 +633,59 @@ const int bag_stack_offsets[30][2] = {
// {2, 11} del 30 al 60 // {2, 11} del 30 al 60
}; };
const int anvil_offsets [24][2] = {
{631, 276},
{609, 226},
{589, 185},
{570, 151},
{551, 126},
{534, 109},
{519, 101},
{509, 100},
{503, 100},
{495, 103},
{486, 111},
{478, 124},
{470, 137},
{464, 154},
{458, 171},
{454, 192},
{450, 214},
{446, 238},
{443, 263},
{441, 291},
{437, 320},
{435, 352},
{432, 384},
{422, 406}
};
const int anvil_collider_offsets [23][2] = {
{692, 298},
{669, 245},
{647, 201},
{627, 165},
{608, 138},
{590, 120},
{574, 111},
{564, 109},
{559, 109},
{550, 112},
{541, 119},
{533, 132},
{525, 145},
{519, 162},
{512, 180},
{508, 202},
{503, 223},
{499, 249},
{496, 275},
{492, 304},
{488, 333},
{485, 366},
{482, 399}
};
/* Prototipos de función */ /* Prototipos de función */
int game_intro (void); int game_intro (void);
int game_loop (void); int game_loop (void);
@ -596,6 +702,7 @@ SDL_Surface * images[NUM_IMAGES];
SDL_Surface * penguin_images[NUM_PENGUIN_FRAMES]; SDL_Surface * penguin_images[NUM_PENGUIN_FRAMES];
int use_sound; int use_sound;
Collider *colliders[NUM_COLLIDERS]; Collider *colliders[NUM_COLLIDERS];
Collider *colliders_hazards[3];
int color_penguin = 0; int color_penguin = 0;
@ -750,6 +857,7 @@ int game_loop (void) {
int bag_activity = 15; int bag_activity = 15;
int airbone = 0, max_airbone = 1; int airbone = 0, max_airbone = 1;
int nivel = 1; int nivel = 1;
int anvil_out = FALSE;
int bag_stack = 0; int bag_stack = 0;
@ -852,6 +960,10 @@ int game_loop (void) {
if (i <= 3) { if (i <= 3) {
add_bag (i); add_bag (i);
airbone++; airbone++;
} else if (i == 5 && nivel >= 2 && anvil_out == FALSE) {
add_bag (5);
airbone++;
anvil_out = TRUE;
} }
} }
} }
@ -871,7 +983,7 @@ int game_loop (void) {
j = thisbag->frame - thisbag->throw_length; j = thisbag->frame - thisbag->throw_length;
if (j < 0 && next_level_visible == FALSE && bags < 6) { if (j < 0 && next_level_visible == FALSE && bags < 6 && thisbag->bag <= 3) {
/* Calcular aquí la colisión contra el pingüino */ /* Calcular aquí la colisión contra el pingüino */
i = collider_hittest (colliders[COLLIDER_BAG_3], thisbag->bag_points[thisbag->frame][1], thisbag->bag_points[thisbag->frame][2], colliders[k], penguinx - 120, 251); i = collider_hittest (colliders[COLLIDER_BAG_3], thisbag->bag_points[thisbag->frame][1], thisbag->bag_points[thisbag->frame][2], colliders[k], penguinx - 120, 251);
@ -906,12 +1018,46 @@ int game_loop (void) {
thisbag = nextbag; thisbag = nextbag;
continue; continue;
} }
} else if (j < 0 && thisbag->bag == 5) {
i = collider_hittest (colliders_hazards[0], anvil_collider_offsets[thisbag->frame][0], anvil_collider_offsets[thisbag->frame][1], colliders[k], penguinx - 120, 251);
if (i == SDL_TRUE) {
bags = 7;
/* TODO: Reproducir el sonido de golpe de yunque */
/* TODO: Acomodar la animación de "Crash" */
printf ("Penguin Crash by anvil\n");
if (vidas > 0) {
try_visible = TRUE;
printf ("Try again visible\n");
animacion = 0;
airbone = 1000; /* El airbone bloquea que salgan más objetos */
vidas--;
} else {
gameover_visible = TRUE;
printf ("Game Over visible\n");
} }
anvil_out = FALSE;
airbone--;
delete_bag (thisbag);
thisbag = nextbag;
continue;
}
}
if (thisbag->bag <= 3) {
if (j == 0) { if (j == 0) {
/* Eliminar del airbone */ /* Eliminar del airbone */
airbone--; airbone--;
} }
} else if (thisbag->bag == 5) {
if (j == 2) {
airbone--;
anvil_out = FALSE;
}
}
if (j >= 35) { if (j >= 35) {
/* Eliminar esta bolsa */ /* Eliminar esta bolsa */
@ -981,6 +1127,8 @@ int game_loop (void) {
thisbag = first_bag; thisbag = first_bag;
while (thisbag != NULL) { while (thisbag != NULL) {
if (thisbag->bag <= 3) {
/* Dibujar las bolsas de café estándar */
if (thisbag->frame < thisbag->throw_length) { if (thisbag->frame < thisbag->throw_length) {
/* Dibujar la bolsa */ /* Dibujar la bolsa */
i = IMG_BAG_1 + thisbag->bag_points[thisbag->frame][0]; i = IMG_BAG_1 + thisbag->bag_points[thisbag->frame][0];
@ -1001,6 +1149,26 @@ int game_loop (void) {
} else { } else {
SDL_BlitSurface (images[i], NULL, screen, &rect); SDL_BlitSurface (images[i], NULL, screen, &rect);
} }
} else if (thisbag->bag == 5) {
/* Dibujar un yunque */
if (thisbag->frame < thisbag->throw_length) {
i = IMG_ANVIL_0 + thisbag->frame;
rect.x = thisbag->object_points[thisbag->frame][0];
rect.y = thisbag->object_points[thisbag->frame][1];
j = 0;
} else {
i = IMG_ANVIL_23;
rect.x = thisbag->object_points[23][0];
rect.y = thisbag->object_points[23][1];
j = thisbag->frame - thisbag->throw_length;
}
if (i == IMG_ANVIL_23 && j > 25) {
SDL_gfxBlitRGBAWithAlpha (images[i], NULL, screen, &rect, 255 - SDL_ALPHA_OPAQUE * (j - 25) / 10);
} else {
SDL_BlitSurface (images[i], NULL, screen, &rect);
}
}
thisbag = thisbag->next; thisbag = thisbag->next;
} }
@ -1166,6 +1334,9 @@ void setup (void) {
colliders[g] = c; colliders[g] = c;
} }
/* Generar los colliders de bloque */
colliders_hazards[0] = collider_new_block (9, 45);
if (use_sound) { if (use_sound) {
/*for (g = 0; g < NUM_SOUNDS; g++) { /*for (g = 0; g < NUM_SOUNDS; g++) {
sprintf (buffer_file, "%s%s", systemdata_path, sound_names[g]); sprintf (buffer_file, "%s%s", systemdata_path, sound_names[g]);
@ -1379,6 +1550,9 @@ void add_bag (int tipo) {
} else if (tipo == 3) { } else if (tipo == 3) {
new->throw_length = 32; new->throw_length = 32;
new->bag_points = bag_3_points; new->bag_points = bag_3_points;
} else if (tipo == 5) {
new->throw_length = 24;
new->object_points = anvil_offsets;
} }
/* Ahora sus campos para lista doble ligada */ /* Ahora sus campos para lista doble ligada */

View File

@ -135,6 +135,38 @@ bad_load:
return NULL; return NULL;
} }
Collider * collider_new_block (int w, int h) {
Collider *new;
int map_size;
new = (Collider *) malloc (sizeof (Collider));
if (new == NULL) return NULL;
new->size_w = w;
new->size_h = h;
new->offset_x = new->offset_y = 0;
if (new->size_w % 32 != 0) {
new->pitch = (new->size_w / 32) + 2;
} else {
new->pitch = (new->size_w / 32) + 1;
}
map_size = new->pitch * new->size_h;
/* Reservar los bytes necesarios */
new->pixels = (Uint32 *) malloc (sizeof (Uint32) * map_size);
if (new->pixels == NULL) {
free (new);
return NULL;
}
memset (new->pixels, -1, sizeof (Uint32) * map_size);
return new;
}
int collider_hittest (Collider *a, int x1, int y1, Collider *b, int x2, int y2) { int collider_hittest (Collider *a, int x1, int y1, Collider *b, int x2, int y2) {
SDL_Rect rect_left, rect_right, result; SDL_Rect rect_left, rect_right, result;
int first = SDL_FALSE; int first = SDL_FALSE;

View File

@ -26,6 +26,7 @@
typedef struct _Collider Collider; typedef struct _Collider Collider;
Collider * collider_new_from_file (const char *filename); Collider * collider_new_from_file (const char *filename);
Collider * collider_new_block (int w, int h);
int collider_hittest (Collider *a, int x1, int y1, Collider *b, int x2, int y2); int collider_hittest (Collider *a, int x1, int y1, Collider *b, int x2, int y2);
#endif #endif