Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
Added a moving camera to the main menu to allow scrolling.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-rumpf committed Jul 21, 2020
1 parent d9ff22e commit 60e897b
Show file tree
Hide file tree
Showing 20 changed files with 160 additions and 30 deletions.
8 changes: 8 additions & 0 deletions GraphTheoryPuzzle.yyp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions objects/obj_camera/Create_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// @desc Set up camera.

// Define viewport size
w = 800;
h = 600;

// Define viewport position (left edge)
pos = 0;

// Define rightmost allowed position
pos_max = room_width - w - 1;

// Activate camera to scroll over menu screen
view_enabled = true;
view_visible[0] = true;
camera_set_view_size(view_camera[0], w, h);
camera_set_view_pos(view_camera[0], pos, 0);
18 changes: 18 additions & 0 deletions objects/obj_camera/Step_0.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// @desc Move camera.

// Ignore movement if mouse is close to GUI menu at top
if (mouse_y < 40)
exit;

// Move left if mouse is close to left edge
var left = mouse_x - pos;
if (pos > 0 && left <= 40)
pos = clamp(pos - 0.25*(40 - left), 0, pos_max);

// Move right if mouse is close to right edge
var right = pos + w - mouse_x;
if (pos < pos_max && right <= 40)
pos = clamp(pos + 0.25*(40 - right), 0, pos_max);

// Move camera to new position
camera_set_view_pos(view_camera[0], pos, 0);
48 changes: 48 additions & 0 deletions objects/obj_camera/obj_camera.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion objects/obj_game/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ global.music_on = true;
// Check whether save file exists

//###
// Check whether settings file exists
// Check whether settings file exists. If it does, go to the menu. If not, run new game code and go to new game room.
35 changes: 27 additions & 8 deletions objects/obj_gui/Other_4.gml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
if (room == rm_title)
exit;

// Get GUI width
var width = display_get_gui_width();

// Constant buttons

// Sound button
instance_create_layer(hspace, vspace, "Overlays", obj_gui_sound);
var sound = instance_create_layer(hspace, vspace, "Overlays", obj_gui_sound);
sound.xx = hspace;
sound.yy = vspace;

// Music button
instance_create_layer(hspace+1.5*hspace, vspace, "Overlays", obj_gui_music);
var music = instance_create_layer(hspace+1.5*hspace, vspace, "Overlays", obj_gui_music);
music.xx = hspace+1.5*hspace;
music.yy = vspace;

// Room-specific buttons
switch room
Expand All @@ -19,13 +26,19 @@ switch room
case rm_menu:

// Save clear button
instance_create_layer(hspace+3*hspace, vspace, "Overlays", obj_gui_save_clear);
var save = instance_create_layer(hspace+3*hspace, vspace, "Overlays", obj_gui_save_clear);
save.xx = hspace+3*hspace;
save.yy = vspace;

// Credits button
instance_create_layer(room_width-hspace-1.5*hspace, vspace, "Overlays", obj_gui_credits);
var credits = instance_create_layer(width-hspace-1.5*hspace, vspace, "Overlays", obj_gui_credits);
credits.xx = width-hspace-1.5*hspace;
credits.yy = vspace;

// Quit button
instance_create_layer(room_width-hspace, vspace, "Overlays", obj_gui_quit);
var quit = instance_create_layer(width-hspace, vspace, "Overlays", obj_gui_quit);
quit.xx = width-hspace;
quit.yy = vspace;

break;

Expand All @@ -35,7 +48,9 @@ switch room
case rm_ending:

// Menu return button
instance_create_layer(room_width-hspace, vspace, "Overlays", obj_gui_back);
var menu = instance_create_layer(width-hspace, vspace, "Overlays", obj_gui_back);
menu.xx = width-hspace;
menu.yy = vspace;

break;

Expand All @@ -44,8 +59,12 @@ switch room
default:

// Menu return button
instance_create_layer(room_width-hspace, vspace, "Overlays", obj_gui_back);
var menu = instance_create_layer(width-hspace, vspace, "Overlays", obj_gui_back);
menu.xx = width-hspace;
menu.yy = vspace;

// Room reset button
instance_create_layer(room_width-hspace-1.5*hspace, vspace, "Overlays", obj_gui_reset);
var reset = instance_create_layer(width-hspace-1.5*hspace, vspace, "Overlays", obj_gui_reset);
reset.xx = width-hspace-1.5*hspace;
reset.yy = vspace;
}
4 changes: 2 additions & 2 deletions objects/obj_gui_back/Draw_64.gml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// Choose image attributes based on selection
if (selected == true)
draw_sprite_ext(spr_button_back, 0, x, y, 0.5, 0.5, 0, c_white, 1);
draw_sprite_ext(spr_button_back, 0, xx, yy, 0.5, 0.5, 0, c_white, 1);
else
draw_sprite_ext(spr_button_back, 0, x, y, 0.5, 0.5, 0, c_white, 0.6);
draw_sprite_ext(spr_button_back, 0, xx, yy, 0.5, 0.5, 0, c_white, 0.6);
4 changes: 2 additions & 2 deletions objects/obj_gui_credits/Draw_64.gml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// Choose image attributes based on selection
if (selected == true)
draw_sprite_ext(spr_button_credits, 0, x, y, 0.5, 0.5, 0, c_white, 1);
draw_sprite_ext(spr_button_credits, 0, xx, yy, 0.5, 0.5, 0, c_white, 1);
else
draw_sprite_ext(spr_button_credits, 0, x, y, 0.5, 0.5, 0, c_white, 0.6);
draw_sprite_ext(spr_button_credits, 0, xx, yy, 0.5, 0.5, 0, c_white, 0.6);
4 changes: 2 additions & 2 deletions objects/obj_gui_music/Draw_64.gml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ if (global.music_on == false)

// Choose image attributes based on selection
if (selected == true)
draw_sprite_ext(spr_button_music, index, x, y, 0.5, 0.5, 0, c_white, 1);
draw_sprite_ext(spr_button_music, index, xx, yy, 0.5, 0.5, 0, c_white, 1);
else
draw_sprite_ext(spr_button_music, index, x, y, 0.5, 0.5, 0, c_white, 0.6);
draw_sprite_ext(spr_button_music, index, xx, yy, 0.5, 0.5, 0, c_white, 0.6);
2 changes: 2 additions & 0 deletions objects/obj_gui_parent/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ image_yscale = 0.5;

// Other attributes
selected = false; // whether the button is selected
xx = 0; // x-coordinate relative to viewport
yy = 0; // y-coordinate relative to viewport
2 changes: 1 addition & 1 deletion objects/obj_gui_parent/Draw_0.gml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/// @desc Placeholder to prevent default sprite drawing.
/// @desc Placeholder to prevent sprite drawing.

exit;
4 changes: 4 additions & 0 deletions objects/obj_gui_parent/Step_1.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// @desc Move to follow viewport on main menu.

if (room == rm_menu)
x = obj_camera.pos + xx;
12 changes: 11 additions & 1 deletion objects/obj_gui_parent/obj_gui_parent.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions objects/obj_gui_quit/Draw_64.gml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// Choose image attributes based on selection
if (selected == true)
draw_sprite_ext(spr_button_quit, 0, x, y, 0.5, 0.5, 0, c_white, 1);
draw_sprite_ext(spr_button_quit, 0, xx, yy, 0.5, 0.5, 0, c_white, 1);
else
draw_sprite_ext(spr_button_quit, 0, x, y, 0.5, 0.5, 0, c_white, 0.6);
draw_sprite_ext(spr_button_quit, 0, xx, yy, 0.5, 0.5, 0, c_white, 0.6);
4 changes: 2 additions & 2 deletions objects/obj_gui_reset/Draw_64.gml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// Choose image attributes based on selection
if (selected == true)
draw_sprite_ext(spr_button_restart, 0, x, y, 0.5, 0.5, 0, c_white, 1);
draw_sprite_ext(spr_button_restart, 0, xx, yy, 0.5, 0.5, 0, c_white, 1);
else
draw_sprite_ext(spr_button_restart, 0, x, y, 0.5, 0.5, 0, c_white, 0.6);
draw_sprite_ext(spr_button_restart, 0, xx, yy, 0.5, 0.5, 0, c_white, 0.6);
4 changes: 2 additions & 2 deletions objects/obj_gui_save_clear/Draw_64.gml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// Choose image attributes based on selection
if (selected == true)
draw_sprite_ext(spr_button_save_delete, 0, x, y, 0.5, 0.5, 0, c_white, 1);
draw_sprite_ext(spr_button_save_delete, 0, xx, yy, 0.5, 0.5, 0, c_white, 1);
else
draw_sprite_ext(spr_button_save_delete, 0, x, y, 0.5, 0.5, 0, c_white, 0.6);
draw_sprite_ext(spr_button_save_delete, 0, xx, yy, 0.5, 0.5, 0, c_white, 0.6);
3 changes: 2 additions & 1 deletion objects/obj_gui_save_clear/Step_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ if (selected == false)

// If selected, listen for mouse click to reset save file
if (mouse_check_button_pressed(mb_left))
scr_save_clear();
//### Screen transition
room_goto(rm_save_clear);

// Deselect self
selected = false;
4 changes: 2 additions & 2 deletions objects/obj_gui_sound/Draw_64.gml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ if (global.sound_on == false)

// Choose image attributes based on selection
if (selected == true)
draw_sprite_ext(spr_button_sound, index, x, y, 0.5, 0.5, 0, c_white, 1);
draw_sprite_ext(spr_button_sound, index, xx, yy, 0.5, 0.5, 0, c_white, 1);
else
draw_sprite_ext(spr_button_sound, index, x, y, 0.5, 0.5, 0, c_white, 0.6);
draw_sprite_ext(spr_button_sound, index, xx, yy, 0.5, 0.5, 0, c_white, 0.6);
8 changes: 5 additions & 3 deletions rooms/rm_menu/rm_menu.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion views/513aea68-f411-437f-991f-96e7450873d6.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 60e897b

Please sign in to comment.