Sega Saturn Development > General Jo Engine Help
Trouble trying to set explosions in shooter game
SaturnTeam:
I have been trying to figure out how to tie in an explosion that is linked to an enemy ship being destroyed by the laser. I have been working on it for a while, looking through the code sections in the shooter demo. It's obvious where the enemy ships come in and the detection of whether an enemy ship has been hit and deleted, but I can't figure out how to input an explosion image to replace the enemy ship just vanishing into thin air. The closest I got was with adding an inline void and trying to tie it in with enemies being destroyed. It made it through the compiler, but nothing happened. I'm wondering if I need to create a header file for the enemy ship. I don't know if anyone can give me a hint. I know that Johannes considered this, because he left an explosion image in the directory.
ponut64:
It's a pretty basic thing with code in C.
Create a struct for a ship.
--- Code: ---
typedef struct {
} ship;
--- End code ---
Have it include the relevant sprites for a ship, including the destroyed sprite.
Have it also include states, like if the ship is destroyed or not.
From that bool, you can set it to display either the ship sprite or the explosion sprite.
Then, you can use something like
--- Code: ---
Sint32 curtime = jo_get_ticks();
--- End code ---
whenever the condition for exploding the ship is called, and...
--- Code: ---
if(explodeShip != true){
//Display the normal ship sprite.
} else if(explodeShip == true){
//Display the explode sprite.
if(curtime > 99){
//Display an empty sprite.
}
}
--- End code ---
SaturnTeam:
Okay. Thanks. I'll work on this another day. I'm out of time, today.
SaturnTeam:
Okay, I spent most of the day trying to implement this, but I'm stuck, again. I want to share the pieces of code I do have.
Here is the header file:
--- Code: ---
#ifndef __ENEMY_H__
# define __ENEMY_H__
# define ENEMY_TILE_COUNT (4)
/*
typedef enum
{
// NONE,
} e_ship;
*/
typedef struct
{
int anim_id;
// int x;
// int y;
// int speed;
// t_ship_horiz_move move;
char is_alive;
char is_dead;
// char is_moving_horizontaly;
// char reverse_animation;
// int shield_pos_x;
// int shield_pos_y;
// int shield_angle;
// int score;
} e_ship;
#endif /* !__ENEMY_H__ */
--- End code ---
I copied that from the ship header file, and changed it, but I'm not clear on changing the struct elements.
Here is code from the main C file. There are numerous mistakes, and obviously I left out the standard code:
--- Code: ---
#include "enemy.h"
static e_ship enemy;
static int enemy_sprite_id;
static int enemy_dead_sprite_id;
inline bool draw_enemy_dead(jo_node *node)
{
jo_sprite_draw3D(enemy_dead_sprite_id, node->data.coord.x, node->data.coord.y, 520);
node->data.coord.y += 2;
if (jo_list_any(&enemies_list, check_if_laser_hit_enemy, node))
get_enemy.anim_id();
}
inline void start_enemy_animation(char check_if_laser_hit_enemy)
{
jo_start_sprite_anim(enemy.anim_id);
enemy.anim_id = jo_create_sprite_anim(enemy_sprite_id, 4, 2);
}
void init_game(void)
{
jo_tile enemy_tileset[ENEMY_TILE_COUNT] =
{
{0, 0, 40, 40},
{40, 0, 40, 40},
{80, 0, 40, 40},
{120, 0, 40, 40},
};
enemy_dead_sprite_id = jo_sprite_add_tga_tileset(JO_ROOT_DIR, "ENEMY.TGA", JO_COLOR_Blue, enemy_tileset, ENEMY_TILE_COUNT);
enemy_sprite_id = jo_sprite_add_tga(JO_ROOT_DIR, "EN.TGA", JO_COLOR_Blue);
enemy.anim_id = jo_create_sprite_anim(enemy_dead_sprite_id, ENEMY_TILE_COUNT, 4);
}
--- End code ---
The explosion animation is 4 tiles, from left to right. I didn't get to the curtime part, because I am having trouble setting up the code before that. I saw how the animation is handled in the sprite animation demo, but this is different with it being a whole game. The demo is just a changing sprite without outside interaction.
XL2:
If it can make it easier, don't worry about the animation functions and just add a status parameter and a timer.
Something like
void renderShip(ship_t * ship)
{
if (ship->status & alive)
Display(shipID);
else
{
if (Ship->timer ++ < max_anim_frames)
Display(shipID + Ship->timer);
else
Ship->timer=max_anim_frames;
}
}
Navigation
[0] Message Index
[#] Next page
Go to full version