#include <jo/jo.h>
#define LEV_ID (0)
#define HITBOX_POS_X (JO_TV_WIDTH_2)
#define HITBOX_POS_Y (JO_TV_HEIGHT_2)
#define HITBOX_WIDTH (32)
#define HITBOX_HEIGHT (32)
int selection = 0;
int selections = 6;
int mode = 0;
int animspeed = 3;
float sscale = 1;
int rot = 0;
static int map_pos_x = 0;
static int map_pos_y = -160;
static int hitbox_sprite_id;
bool togtil = true;
bool togpar = true;
/*static int walk_width = 48;
static int walk_height = 48;*/
static int walk_id = 0;
static const jo_tile SonicWalk[] =
{
{48 * 0, 0, 48, 48},
{48 * 1, 0, 48, 48},
{48 * 2, 0, 48, 48},
{48 * 3, 0, 48, 48},
{48 * 4, 0, 48, 48},
{48 * 5, 0, 48, 48},
{48 * 6, 0, 48, 48},
{48 * 7, 0, 48, 48},
{48 * 8, 0, 48, 48},
{48 * 9, 0, 48, 48},
{48 * 10, 0, 48, 48},
{48 * 11, 0, 48, 48},
};
static const items[] =
{
{"Input Test"},
{"Animation Demo"},
{"Scaling and Rotation"},
{"Parallax & Collision"},
{"Mode 7"},
{"Sounds"},
{"Input-based Animation (Timeline)"},
{"Saturn Sonic (Unavailable)"},
};
void menu(void)
{
if(mode == 0){
//If UP? Erase cursor -> Handle Overflow
if(jo_is_pad1_key_down(JO_KEY_UP)){
jo_printf(1, selection + 3, " ");
if(selection == 0){
selection = selections;
} else{
selection--;
}
draw();
}
//If DOWN? Erase cursor -> Handle Overflow
if(jo_is_pad1_key_down(JO_KEY_DOWN)){
jo_printf(1, selection + 3, " ");
if(selection == selections){
selection = 0;
} else{
selection++;
}
draw();
}
if(jo_is_pad1_key_down(JO_KEY_A)){
if(selection == 0){
mode = 1;
}
if(selection == 1){
mode = 2;
}
if(selection == 2){
mode = 3;
}
if(selection == 3){
mode = 4;
draw();
}
if(selection == 4){
mode = 5;
}
if(selection == 5){
mode = 6;
}
if(selection == 6){
mode = 7;
}
if(selection == 7){
mode = 8;
}
}
}
//Input
if(mode == 1){
jo_clear_screen();
input();
}
//Sprite Animation
if(mode == 2){
jo_clear_screen();
animation();
}
//Scale/Rotation
if(mode == 3){
jo_clear_screen();
scalerot();
}
//Tiles and Parallax
if(mode == 4){
jo_map_draw(LEV_ID, map_pos_x, map_pos_y);
parallax();
}
}
void draw(void)
{
if(mode == 0){
jo_clear_background(JO_COLOR_Black);
jo_clear_screen();
//Main
jo_printf(1, 1, "Saturn Sonic V.0.0.0.0.1");
//Cursor
jo_printf(1, selection + 3, ">");
//Display items
jo_printf(2, 3, items[0]);
jo_printf(2, 3 + 1, items[1]);
jo_printf(2, 3 + 2, items[2]);
jo_printf(2, 3 + 3, items[3]);
jo_printf(2, 3 + 4, items[4]);
jo_printf(2, 3 + 5, items[5]);
jo_printf(2, 3 + 6, items[6]);
jo_printf(2, 3 + 7, items[7]);
}
if(mode == 1){
//NULL
}
if(mode == 2){
sonic_setup();
}
if(mode == 3){
sonic_setup();
}
if(mode == 4){
map_load();
}
}
void input(void)
{
if (!jo_is_pad1_available()){
return;
}
jo_clear_background(JO_COLOR_SemiBlue);
jo_printf(1, 1, "Hold A, B, and C to return");
//Inputs
jo_printf(30, 1, "INPUTS:");
jo_printf(30, 3, "A:");
jo_printf(30, 5, "B:");
jo_printf(30, 7, "C:");
jo_printf(30, 9, "L:");
jo_printf(30, 11, "R:");
jo_printf(30, 13, "U:");
jo_printf(30, 15, "D:");
jo_printf(30, 17, "<:");
jo_printf(30, 19, ">:");
if(jo_is_pad1_key_pressed(JO_KEY_A) && jo_is_pad1_key_pressed(JO_KEY_B) && jo_is_pad1_key_pressed(JO_KEY_C)){
back();
return;
}
//A
if(jo_is_pad1_key_pressed(JO_KEY_A)){
jo_printf(32, 3, "TRUE ");
}
if(!jo_is_pad1_key_pressed(JO_KEY_A)){
jo_printf(32, 3, "FALSE");
}
//B
if(jo_is_pad1_key_pressed(JO_KEY_B)){
jo_printf(32, 5, "TRUE ");
}
if(!jo_is_pad1_key_pressed(JO_KEY_B)){
jo_printf(32, 5, "FALSE");
}
//C
if(jo_is_pad1_key_pressed(JO_KEY_C)){
jo_printf(32, 7, "TRUE ");
}
if(!jo_is_pad1_key_pressed(JO_KEY_C)){
jo_printf(32, 7, "FALSE");
}
//L
if(jo_is_pad1_key_pressed(JO_KEY_L)){
jo_printf(32, 9, "TRUE ");
}
if(!jo_is_pad1_key_pressed(JO_KEY_L)){
jo_printf(32, 9, "FALSE");
}
//R
if(jo_is_pad1_key_pressed(JO_KEY_R)){
jo_printf(32, 11, "TRUE ");
}
if(!jo_is_pad1_key_pressed(JO_KEY_R)){
jo_printf(32, 11, "FALSE");
}
//UP
if(jo_is_pad1_key_pressed(JO_KEY_UP)){
jo_printf(32, 13, "TRUE ");
draw();
}
if(!jo_is_pad1_key_pressed(JO_KEY_UP)){
jo_printf(32, 13, "FALSE");
}
//DOWN
if(jo_is_pad1_key_pressed(JO_KEY_DOWN)){
jo_printf(32, 15, "TRUE ");
draw();
}
if(!jo_is_pad1_key_pressed(JO_KEY_DOWN)){
jo_printf(32, 15, "FALSE");
}
//LEFT
if(jo_is_pad1_key_pressed(JO_KEY_LEFT)){
jo_printf(32, 17, "TRUE ");
}
if(!jo_is_pad1_key_pressed(JO_KEY_LEFT)){
jo_printf(32, 17, "FALSE");
}
//RIGHT
if(jo_is_pad1_key_pressed(JO_KEY_RIGHT)){
jo_printf(32, 19, "TRUE ");
}
if(!jo_is_pad1_key_pressed(JO_KEY_RIGHT)){
jo_printf(32, 19, "FALSE");
}
}
void animation(void)
{
jo_clear_background(JO_COLOR_SemiPurple);
jo_printf(1, 1, "Animation Demo");
jo_printf(1, 2, "Press B to return");
jo_printf(1, 4, "<: Decrease Animation Speed");
jo_printf(1, 5, ">: Increase Animation Speed");
jo_printf(1, 20, "I'm not sure why, but");
jo_printf(1, 21, "animation framerates can only be");
jo_printf(1, 22, "displayed at whole-integer");
jo_printf(1, 23, "intervals. The difference in speeds");
jo_printf(1, 24, "will be noticeable. This can be");
jo_printf(1, 25, "fixed with timeline-based animation.");
jo_sprite_draw3D(jo_get_anim_sprite(walk_id), -15, -15, 490);
jo_set_sprite_anim_frame_rate(walk_id, animspeed);
if(animspeed < 0){
animspeed = 0;
}
if(jo_is_pad1_key_down(JO_KEY_RIGHT)){
animspeed--;
}
if(jo_is_pad1_key_down(JO_KEY_LEFT)){
animspeed++;
}
if(jo_is_pad1_key_pressed(JO_KEY_B)){
back();
return;
}
}
void scalerot(void)
{
jo_clear_background(JO_COLOR_SemiGreen);
jo_printf(1, 1, "Scale and Rotation Demo");
jo_printf(1, 2, "Press B to return");
jo_printf(1, 4, "</>: Rotate Left/Right");
jo_printf(1, 5, "U/D: Inc/Dec Scale");
jo_printf(1, 7, "A: Reset");
jo_sprite_draw3D_and_rotate(jo_get_anim_sprite(walk_id), -15, -15, 490, rot);
jo_set_sprite_anim_frame_rate(walk_id, 3);
jo_sprite_change_sprite_scale(sscale);
if(jo_is_pad1_key_pressed(JO_KEY_RIGHT)){
rot--;
}
if(jo_is_pad1_key_pressed(JO_KEY_LEFT)){
rot++;
}
if(jo_is_pad1_key_pressed(JO_KEY_DOWN)){
sscale-=0.02;
}
if(jo_is_pad1_key_pressed(JO_KEY_UP)){
sscale+=0.02;
}
if(jo_is_pad1_key_pressed(JO_KEY_A)){
sscale = 1;
rot = 0;
}
if(jo_is_pad1_key_pressed(JO_KEY_B)){
back();
return;
}
}
void parallax(void)
{
jo_clear_background(JO_COLOR_DarkRed);
jo_clear_screen();
jo_printf(1, 1, "Tiles, Parallax, & Sprite Collision");
jo_printf(1, 2, "Press B to return");
jo_printf(1, 4, "(Just tiles for now.");
jo_printf(1, 5, "Parallax comes tomorrow.)");
if (!jo_is_pad1_available())
return ;
if (jo_is_pad1_key_pressed(JO_KEY_LEFT))
map_pos_x -= 2;
if (jo_is_pad1_key_pressed(JO_KEY_RIGHT))
map_pos_x += 2;
if (jo_is_pad1_key_pressed(JO_KEY_UP))
map_pos_y -= 2;
if (jo_is_pad1_key_pressed(JO_KEY_DOWN))
map_pos_y += 2;
if(jo_is_pad1_key_pressed(JO_KEY_B)){
back();
return;
}
}
void back(void)
{
mode = 0;
menu();
draw();
}
void sonic_setup(void)
{
int sprite_id = jo_sprite_add_bin_tileset("SONIC", "WALK.BIN", JO_COLOR_Green, SonicWalk, JO_TILE_COUNT(SonicWalk));
walk_id = jo_create_sprite_anim(sprite_id, JO_TILE_COUNT(SonicWalk), animspeed);
jo_start_sprite_anim_loop(walk_id);
}
void map_load(void)
{
jo_map_load_from_file(LEV_ID, 450, "LEV", "LEV.MAP");
jo_sprite_add_image_pack("BLK", "BLK.TEX", JO_COLOR_Red);
}
void jo_main(void)
{
jo_core_init(JO_COLOR_Black);
draw();
map_load();
jo_core_add_callback(menu);
sonic_setup();
jo_core_run();
}
/*
** END OF FILE
*/
Comments