Sega Saturn Development > General Jo Engine Help
Trouble trying to set explosions in shooter game
SaturnTeam:
Okay. Thanks. I'll integrate this idea and keep working on this tomorrow.
SaturnTeam:
Okay, this is what I have after a few days. This is kind of a mess. I'll include the warnings/errors under the code.
--- Code: ---
#ifndef __ENEMY_H__
# define __ENEMY_H__
# define ENEMY_TILE_COUNT (4)
/*
typedef enum
{
NONE,
} e_ship;
*/
typedef struct
{
int anim_id;
char alive;
char status;
char max_anim_frames;
char timer;
// int x;
// int y;
// int speed;
// t_ship_horiz_move move;
char first_dead_sprite_id;
// 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'm still not clear on what char items should be included in the structure and the implementation connection with the main file.
--- Code: ---
#include "enemy.h"
static e_ship enemy;
static int enemy_sprite_id;
static int enemy_dead_sprite_id;
inline bool explodeEnemy(jo_node *node)
{
Sint32 curtime = jo_get_ticks();
if(explodeEnemy != true)
{
jo_sprite_draw3D(enemy_sprite_id, node->data.coord.x, node->data.coord.y, 520);
}
else if(explodeEnemy == true)
{
jo_sprite_draw3D(enemy_dead_sprite_id, node->data.coord.x, node->data.coord.y, 520);
}
if(curtime > 99)
{
jo_sprite_draw3D(enemy_sprite_id, node->data.coord.x, node->data.coord.y, 520);
}
}
inline void renderEnemy(e_ship * enemy, char alive, char status, char max_anim_frames, char timer, jo_node *node)
{
if (enemy->status & alive)
Display(enemy);
else if (enemy->timer ++ < max_anim_frames)
Display(enemy + enemy->timer);
else
enemy->timer=max_anim_frames;
}
inline void start_enemy_animation(e_ship enemy, char first_dead_sprite_id)
{
jo_start_sprite_anim(enemy.anim_id);
// enemy.reverse_animation = reverse_animation;
enemy.anim_id = jo_create_sprite_anim(first_dead_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 compiler warns me that my early mention of static e_ship enemy shadows the global declaration. With the if explode enemy is true, the warning is about the comparison between pointer and integer. At the end of the explode section, it warns that there is no return statement in function returning non-void. There is a warning/error about using the term "display," because it doesn't know where this comes from and doesn't seem to be embedded in the engine. In the renderEnemy section, the status, timer, and node go unused. I realize that these are just mentioned, but not implemented. I don't know enough about it to do this. It also warns that at the end of the explodeEnemy section, "control reaches end of non-void function." I'm wondering if there is an easier way to implement an explosion, but I haven't figured it out yet.
ponut64:
A "static" variable becomes read-only. You can generally avoid using this.
I would guess the compiler is complaining about redefinition of e_ship because the type is not static but your variable is. Plus, you should put the following line in the .h file.
--- Code: ---
extern e_ship enemy;
--- End code ---
You use extern to notify another document (especially ones compiled separately) that this variable exists, though you do not define the variable's contents with extern.
I generally avoid using "char" variables, if you can remember the state with integers, you should use integers (S or U int 8/16/32, depending on how much bit depth you need and whether or not you need negative values)
If your function code is not meant to return data to a variable, its return type should be "void".
--- Code: ---
inline bool explodeEnemy(jo_node *node);
just becomes
void explodeEnemy(jo_node *node);
--- End code ---
You generally see a lot of programmers use bool as a function return type so the function can return TRUE or FALSE depending on successful or unsuccessful execution of the intended result. You haven't written in those conditions; you don't need to.
"Display" is in fact undefined in the SGL and SBL libraries; you need to define what "Display" means in terms of SGL or SBL.
Do you mean debug information? If so you would be looking at "jo_printf" or "slPrintFX".
Also, programming is gonna take a long time. Welcome to the club.
SaturnTeam:
Okay. That's good information. I appreciate the help. I will soldier on!
XL2:
In fact, a static variable will have 2 different behaviours depending on how you declare it.
Within a function, it will remain in memory in that function for all the program's life. Try to avoid that.
A global static variable is one that you can only see within one c file.
It's useful if you need variables for some functions but you don't want them to become available for the whole program.
Try to avoid global variables and use local variables and pointers as much as possible.
Also, a bool is 32 bits with SGL, so you waste 31 bits.
A better way is to use bitmasks.
Like say your enum says alive = 1<<17;
Then
ship->status |= alive; //sets the ship to alive
ship->status &= ~alive; //sets the ship to dead
To check if the ship is alive :
If (ship->status & alive) //same as == true
If ((ship->status & alive)==0) //same as == false
You could then use status for 31 others true/false flags in the same maner.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version