Author Topic: SOLVED: Run Storyboard demo externally inside my game?  (Read 168 times)

SaturnTeam

  • Jr. Member
  • **
  • Posts: 68
  • Karma: +5/-0
    • View Profile
    • Saturn Team
SOLVED: Run Storyboard demo externally inside my game?
« on: July 04, 2018, 02:26:21 am »
I am trying to run the Storyboard demo from the C file with an attached header file, by linking the header file inside my game's main file. The name on both files matches. I added the external C file to the makefile. In the end, I'm trying to get it to work so I can gut it and make my own storyboard code. For the most part, it seems to be set up correctly, but I'm getting some errors.

Here is my header file code:
Code: [Select]
#ifndef __CLOUDS_H__
# define __CLOUDS_H__

void    my_draw(void);
void    my_gamepad(void);
void    animate_circular_saws(void);
void    animate_drone(void);
void    animate_sentry(void);
void    init_circular_saw_sprite_and_position(void);
void    init_drone_sprite_and_position(void);
void    init_sentry_sprite_and_position(void);
//void    jo_main(void);

#endif /* !__CLOUDS_H__ */

/*
** END OF FILE
*/

I commented out the jo_main section here and in the C file, because I assumed I needed to initialize the functions inside of jo_main in the main C file. I included the header file at the top of the external C file. Here is what I added in my main C file:
Code: [Select]
#include "clouds.h"

void     jo_main(void)
{
init_circular_saw_sprite_and_position();
init_drone_sprite_and_position();
init_sentry_sprite_and_position();
animate_circular_saws();
animate_drone();
animate_sentry();
}

When I try to compile the project, I get an error on the storyboard C file that "static jo_storyboard    *drone_storyboard;" has a syntax error before the * token. I get warnings on that part that the "type defaults to 'int' in declaration of 'drone_storyboard'", and that "data definition has no type or storage class". I also get a warning in the storyboard C file of "implicit declaration of function 'jo_storyboard_toggle'". Additionally, I get errors from the same file saying, "'jo_storyboard', 'storyboard', 'animation', 'jo_animation' undeclared". There are other related warnings, but I don't think I need to list all of them here. I haven't changed the code in the demo, other than commenting out the jo_main section and bringing up the same items inside of the jo_main in my main game file. I know this isn't super complicated, but I haven't tried doing this before. My main C file is getting too cluttered.
« Last Edit: July 04, 2018, 06:01:15 pm by SaturnTeam »
Founder of Saturn Team

ponut64

  • Full Member
  • ***
  • Posts: 175
  • Karma: +13/-0
    • View Profile
Re: Run Storyboard demo externally inside my game?
« Reply #1 on: July 04, 2018, 05:38:26 am »
Have you checked the modules in the makefile?
Has anything you commented out to get the Shooter demo to work broken the other demo?
Have you tried removing the "static" definition from all the variables?

Have you tried including the header in the storyboard file?
Have you tried putting something like the following in the header file?

Code: [Select]
// A custom structure to show that you can use customs as well as jo_2d_object_attributes, jo_pos2D, etc.
typedef struct
{
    /* Must be the first field in our custom structure in order to let the storyboard retrieve where the location of our object is */
    jo_2d_object_attributes     attributes;
    int                         sprite_id;
    // Add other attributes here or not ;)
}                               circular_saw_t;

extern circular_saw_t           saws[2];
extern jo_pos2D                 drone;
extern jo_pos2D                 sentry;

extern int                      sentry_sprite_id;
extern int                      drone_sprite_id;

extern jo_storyboard            *drone_storyboard;


I'm probably not being all that helpful, but next time you have an issue like this, throwing up what you're working with in a zip file (the entire directory) would be helpful.

SaturnTeam

  • Jr. Member
  • **
  • Posts: 68
  • Karma: +5/-0
    • View Profile
    • Saturn Team
Re: Run Storyboard demo externally inside my game?
« Reply #2 on: July 04, 2018, 06:01:01 pm »
I figured it out! It feels good to actually get something working. I had forgotten to add the storyboard module in the makefile. After getting continual errors and warnings, I realized I didn't even need the extra C file. The communication between the three files was just a nightmare. I just dumped the code into the header file and made some alterations. Below is what I did, so others can execute the same thing for their projects:

MAKEFILE LINE:
Code: [Select]
JO_COMPILE_WITH_STORYBOARD_MODULE = 1

HEADER:
Code: [Select]
#ifndef __STORYBOARD_H__
# define __STORYBOARD_H__

#include <jo/jo.h>

// A custom structure to show that you can use customs as well as jo_2d_object_attributes, jo_pos2D, etc.

typedef struct
{
    /* Must be the first field in our custom structure in order to let the storyboard retrieve where the location of our object is */
    jo_2d_object_attributes     attributes;
    int                         sprite_id;
    // Add other attributes here or not ;)
}                               circular_saw_t;

static circular_saw_t           saws[2];
static jo_pos2D                 drone;
static jo_pos2D                 sentry;

static int                      sentry_sprite_id;
static int                      drone_sprite_id;

static jo_storyboard            *drone_storyboard;

void                            animate_circular_saws(void)
{
    jo_storyboard               *storyboard;
    jo_animation                *animation;

    // We create a new storyboard for all saw (that means that you can use the same storyboard with multiple object)
    storyboard = jo_storyboard_create(true, false);
    // Now we add a new custom animation (smooth translation + rotation) (that means that you can add multiple animation)
    animation = jo_storyboard_create_animation(storyboard, 0, 0);
    animation->sin_radius = 80;
    animation->translation_speed_y = 2;
    animation->rotation_speed = 10;
    // Now we can animate any object
    jo_storyboard_add_object(storyboard, &saws[0]);
    jo_storyboard_add_object(storyboard, &saws[1]);
    // Next step in my_draw()
}

void                            animate_drone(void)
{
    //jo_storyboard_create_for_object() = jo_storyboard_create() + jo_storyboard_add_object()
    drone_storyboard = jo_storyboard_create_for_object(true, true, &drone);
    jo_storyboard_create_translation_animation_using_direction(drone_storyboard, RIGHT, 1, 160);
    jo_storyboard_create_translation_animation_using_direction(drone_storyboard, DOWN, 1, 160);
    jo_storyboard_create_translation_animation_using_direction(drone_storyboard, LEFT, 1, 160);
    // You can also translate in any direction (angle)
    jo_storyboard_create_translation_animation(drone_storyboard, 270, 1, 160);
    // You can create complex animation :)
}

void                            animate_sentry(void)
{
    // There is many powerful helpers in jo/storyboard.h
    // jo_storyboard_move_object_in_circle() = jo_storyboard_create() + jo_storyboard_add_object() + jo_storyboard_create_circle_animation()
    jo_storyboard_move_object_in_circle(&sentry, 90, 1, JO_STORYBOARD_INFINITE_DURATION);
}

void                            init_circular_saw_sprite_and_position(void)
{
    // First saw
    saws[0].attributes.z = 500;
    saws[0].attributes.x = -50;
    saws[0].sprite_id = jo_sprite_add_tga(JO_ROOT_DIR, "SAW.TGA", JO_COLOR_Green);
    // Second saw
    saws[1].attributes.x = 50;
    saws[1].attributes.z = saws[0].attributes.z; // Same z position
    saws[1].sprite_id = saws[0].sprite_id; // Same sprite
}

void                            init_drone_sprite_and_position(void)
{
    drone_sprite_id = jo_sprite_add_tga(JO_ROOT_DIR, "EMY.TGA", JO_COLOR_Green);
    drone.x = -80;
    drone.y = -80;
}

void                            init_sentry_sprite_and_position(void)
{
    sentry_sprite_id = jo_sprite_add_tga(JO_ROOT_DIR, "CAM.TGA", JO_COLOR_Green);
    sentry.x = 0;
    sentry.y = 0;
}

#endif /* !__STORYBOARD_H__ */

/*
** END OF FILE
*/
So I took out the gamepad part, because I didn't need it. I moved the important info in my_draw and jo_main to my main file, and deleted those sections in the header file. Here is the needed code in the main C file:
Code: [Select]
#include "storyboard.h"

void                my_draw(void)
{
    jo_sprite_draw3D_and_rotate(saws[0].sprite_id, saws[0].attributes.x, saws[0].attributes.y, saws[0].attributes.z, saws[0].attributes.rz);
    jo_sprite_draw3D_and_rotate(saws[1].sprite_id, saws[1].attributes.x, saws[1].attributes.y, saws[1].attributes.z, saws[1].attributes.rz);
    jo_sprite_draw3D(drone_sprite_id, drone.x, drone.y, 550);
    jo_sprite_draw3D(sentry_sprite_id, sentry.x, sentry.y, 400);
}

void     jo_main(void)
{
init_circular_saw_sprite_and_position();
init_drone_sprite_and_position();
init_sentry_sprite_and_position();
animate_circular_saws();
animate_drone();
animate_sentry();
}
There you have it! Thanks, ponut64!
Founder of Saturn Team

 

Sitemap 1 2 3 4 5 6 7 8 9 10 
SMF spam blocked by CleanTalk