Emerald Nova Games

Jo Engine

Hello World and Print Statements

The basic print satement in Jo Engine is void jo_print(int x, int y, char* str). With this print statement, you can print up to 40 characters in a line over 30 lines. int x gives the horizontal position on the screen to print the character array char* str, while int y gives the vertical position (line.) (0,0) is the top left corner of the screen. To print hellow world:


/*
** Jo Sega Saturn Engine
** Copyright (c) 2012-2017, Johannes Fetz (johannesfetz@gmail.com)
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**     * Redistributions of source code must retain the above copyright
**       notice, this list of conditions and the following disclaimer.
**     * Redistributions in binary form must reproduce the above copyright
**       notice, this list of conditions and the following disclaimer in the
**       documentation and/or other materials provided with the distribution.
**     * Neither the name of the Johannes Fetz nor the
**       names of its contributors may be used to endorse or promote products
**       derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <jo/jo.h>

//  Primary Logic Loop
void primary_loop(void)
{
	char string[40] = "Hello World!";
	jo_print(0, 0, string);
}

void jo_main(void)
{
	//  Initialize engine with black background
	jo_core_init(JO_COLOR_Black);	

	//	Main loop of game
	jo_core_add_callback(primary_loop);	
	jo_core_run();
}

Also available is a formatted print statement jo_printf. This works much the same as printf, allowing you to insert variables into a string for printing. Here the primary loop is altered to show the character space on screen:


void primary_loop(void)
{
	char string[40] = "0123456789012345678901234567890123456789";
	jo_print(0, 0, string);
	
	for(int i = 1; i <= 29; i++)
	{
		jo_printf(0, i, "Line # %d/%d.", i, 29);
	}
}

You can change the color of jo_printf statements by preceeding it with jo_set_printf_color_index with an indexed color. You can also use jo_printf_with_color with an indexed color. Note that indexed colors all start with JO_COLOR_INDEX_.


void primary_loop(void)
{
    jo_set_printf_color_index(JO_COLOR_INDEX_Green);
    jo_printf(0, 0, "Year: %d", 1994);
    jo_printf_with_color(0, 1, JO_COLOR_INDEX_Red, "Sega Saturn: $%d", 399);
}