/*==============================================================================
------>> Platformer Game by Foxy Of Jungle <<------
No object is used in this project, the whole game is found in that piece of code.
I don't recommend using this to make a new game, it serves only as a way to
study GML and it was just a personal challenge.
==============================================================================*/
/// GAME INIT ///
#region functions
// core
function game_init_essentials()
{
//
}
gml_pragma("global", "game_init_essentials()");
// gui
function gui_mouse_x() {return device_mouse_x_to_gui(0);}
function gui_mouse_y() {return device_mouse_y_to_gui(0);}
function gui_w() {return display_get_gui_width();}
function gui_h() {return display_get_gui_height();}
// game
/// @func alert()
function alert()
{
var _alert = string(argument[0]);
if (argument_count > 1) {_alert += ": " + string(argument[1]);}
show_debug_message(_alert);
}
/// @func game_room_add(index, room_name)
/// @arg index
/// @arg room_name
function game_room_add(index, room_name)
{
/// @func _game_room(_ii, _nn)
_game_room = function(_ii ,_nn) constructor
{
//variaveis para pegar à esquerda
indx = _ii;
name = _nn;
}
return new _game_room(index, room_name);
}
/// @func game_room_goto(index)
/// @arg index
function game_room_goto(index)
{
// destroy all instances
global.game_instances[0] = 0;
global.game_instances_n = 0;
// set the id of the new room
for (var r=0; r<array_length(global.game_room); r+=1)
{
var _struct = global.game_room[r];
var _struct_array = variable_struct_get_names(_struct);
for (var i=0; i<array_length(_struct_array); i+=1;)
{
if (variable_struct_get(_struct, _struct_array[i]) == index)
{
var _level = _struct.indx;
global.game_room_index = _level;
}
}
}
// enable room loading
global.game_room_can_load = true;
}
/// @func game_room_goto_next()
function game_room_goto_next()
{
// destroy all instances
global.game_instances[0] = 0;
global.game_instances_n = 0;
// next room
global.game_room_index += 1;
// enable room loading
global.game_room_can_load = true;
}
/// @func game_room_goto_previous()
function game_room_goto_previous()
{
// destroy all instances
global.game_instances[0] = 0;
global.game_instances_n = 0;
// previous room
global.game_room_index -= 1;
// enable room loading
global.game_room_can_load = true;
}
/// @func game_instance_create(x, y, object)
/// @arg x
/// @arg y
/// @arg object
function game_instance_create(x, y, object)
{
global.game_instances_n += 1;
global.game_instances[global.game_instances_n] = new object(x, y);
global.game_instances[global.game_instances_n].idd = global.game_instances_n;
return global.game_instances[global.game_instances_n];
}
#endregion
#region setup resolution
var screen_width = 0;
var screen_height = 270;
aspect_ratio = display_get_width() / display_get_height();
game_zoom = 1;
screen_width = round(screen_height * aspect_ratio);
//screen_height = round(screen_width/aspect_ratio);
screen_width = round(screen_width);
screen_height = round(screen_height);
if(screen_width & 1) screen_width -= 1;
if(screen_height & 1) screen_height -= 1;
global.Main_Camera = camera_create_view(0, 0, screen_width, screen_height, 0, noone,0,0,0,0);
camera_set_view_size(global.Main_Camera, screen_width, screen_height);
room_set_camera(0, 0, global.Main_Camera);
room_set_view_enabled(0, true);
room_set_viewport(0, 0, true, 0, 0, screen_width*game_zoom, screen_height*game_zoom);
surface_resize(application_surface, screen_width, screen_height);
display_set_gui_size(screen_width, screen_height);
window_set_size(screen_width*game_zoom, screen_height*game_zoom);
#endregion
#region create rooms
global.game_room[0] = game_room_add(0, "room_menu");
global.game_room[1] = game_room_add(1, "room_level1");
global.game_room[2] = game_room_add(2, "room_level2");
global.game_room_index = 0;
// >>> [room_menu] obj_menu
function obj_menu(_x, _y) constructor
{
// create event
idd = -1;
xx = _x;
yy = _y;
v_menu_title = "NoObjectsChallenge";
// events [step and draw]
static core = function()
{
// step
if keyboard_check_pressed(vk_enter)
{
game_room_goto("room_level1");
}
// draw
draw_text(10, 10, v_menu_title);
}
}
// >>> [room_level1] obj_level1
function obj_level1(_x, _y) constructor
{
// create event
idd = -1;
xx = _x;
yy = _y;
// events [step and draw]
static core = function()
{
draw_text(xx, yy, "Level1");
}
}
#endregion
#region create layers
global.game_layer_game = layer_create(0, "game");
#endregion
#region create other objects
// >>> obj_model [test object, not used]
function obj_model(_x, _y) constructor
{
// create event
idd = -1;
xx = _x;
yy = _y;
// events [step and draw]
static core = function()
{
draw_text(xx, yy, "Object_"+string(idd)+string("\nx: ")+string(xx)+string(" | y: ")+string(yy));
}
}
#endregion
#region others variables
//alert(global.game_room[0].indx, global.game_room[0].name)
global.game_instances[0] = 0;
global.game_instances_n = 0;
global.game_room_can_load = true;
#endregion
/// MENU ///
game_room_goto("room_menu");
game_instance_create(0, 0, obj_menu);
// EXECUTE OBJECTS EVENTS
function game_objects_layer_script_end()
{
/// @func game_objects_layer_script_end()
draw_clear(c_black);
// ROOM START
// load and create rooms and levels
if (global.game_room_can_load)
{
switch (global.game_room_index)
{
// room_menu
case 0:
show_debug_message("LOAD MENU LEVEL");
break;
// room_level1
case 1:
show_debug_message("LOAD LEVEL 1");
break;
// room_level2
case 2:
show_debug_message("LOAD LEVEL 2");
break;
}
global.game_room_can_load = false;
}
// STEP EVENT
//show_debug_message(global.game_room_index)
if keyboard_check_pressed(ord("R")) room_restart();
// DRAW EVENT
// draw instances structs here
if (array_length(global.game_instances) > 0)
{
for (var i = 1; i < array_length(global.game_instances); ++i)
{
// draw it [draw and step event]
global.game_instances[i].core();
}
}
// DRAW GUI EVENT
if (event_type == ev_draw)
{
if (event_number == ev_gui)
{
draw_text(10, 240, fps_real);
}
}
}
layer_script_end(global.game_layer_game, game_objects_layer_script_end);