Skip to content

Commit

Permalink
added camera speed options
Browse files Browse the repository at this point in the history
  • Loading branch information
jack27121 committed Jan 17, 2023
1 parent deecc57 commit 1fc36f1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 7 deletions.
2 changes: 2 additions & 0 deletions objects/demo_obj_player/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pointer_y = 0;
zoom_mode = 0;
zoom_text = "no zooming"

speed_mode = 1;

game_res = 2;
gui_res = 4;

Expand Down
2 changes: 2 additions & 0 deletions objects/demo_obj_player/Draw_64.gml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ draw_text_outline(1,offset*3,"[LMB] move cam to pos (when not following)",outlin
draw_text_outline(1,offset*4,"[RMB] "+ zoom_text,outline_width);
var constrained = (obj_stanncam.camera_constrain) ? "camera constrained to room" : "camera not constrained to room";
draw_text_outline(1,offset*5,"[CTRL] "+ constrained,outline_width);
draw_text_outline(1,offset*6,"[S] camera shake",outline_width);
draw_text_outline(1,offset*7,"[Tab] camera speed "+ string(obj_stanncam.spd),outline_width);

//draw current resolution text
draw_set_halign(fa_right)
Expand Down
31 changes: 31 additions & 0 deletions objects/demo_obj_player/Step_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,44 @@ if(mouse_check_button_pressed(mb_right)){
}
}

//toggle camera speed
if(keyboard_check_pressed(vk_tab)){
speed_mode++;
if(speed_mode > 3) speed_mode = 0;

switch (speed_mode) {
case 0:
//speed 0.5
stanncam_speed(0.5,50);
break;
case 1:
//speed 2
stanncam_speed(1,50);
break;
case 2:
//speed 10
stanncam_speed(2,50);
break;
case 3:
//speed 10
stanncam_speed(10,50);
break;
}
}

//toggle if the camera is constrained to the room size
if(keyboard_check_pressed(vk_control)){
if(obj_stanncam.camera_constrain) obj_stanncam.camera_constrain = false;
else obj_stanncam.camera_constrain = true;

}

//do a screenshake
if(keyboard_check_pressed(ord("S"))){
stanncam_shake(30,room_speed*1);

}

//switch resolutions
if(keyboard_check_pressed(vk_f1))
{
Expand Down
3 changes: 2 additions & 1 deletion objects/obj_stanncam/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ global.gui_h = 720; //gui resolution height
global.upscale = 4; //how much the game should be upscaled

global.camera_follow = undefined; //what object the camera should follow
spd = 0.2; //how fast the camera follows an object
spd = 1; //how fast the camera follows an object
spd_threshold = 50; //the minimum distance the camera is away, for the speed to be in full effect
gui_hires = true; //if the gui should be independant of the game resolution
camera_constrain = false; //if camera should be constrained to the room size
//the camera bounding box, for the followed object to leave before the camera starts moving
Expand Down
17 changes: 11 additions & 6 deletions objects/obj_stanncam/Step_2.gml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ if (!is_undefined(global.camera_follow)){
xTo = global.camera_follow.x;
yTo = global.camera_follow.y;

var dist_w = max(bounds_w,abs(xTo - x)) - bounds_w;
var dist_h = max(bounds_h,abs(yTo - y)) - bounds_h;

//update camera position
while (abs(xTo - x) > bounds_w)
if (abs(xTo - x) > bounds_w)
{
if (x < xTo) x+=spd;
else if (x > xTo) x-=spd;
var _spd = (dist_w/spd_threshold)*spd;
if (x < xTo) x+=_spd;
else if (x > xTo) x-=_spd;
}

while (abs(y - yTo) > bounds_h)
if (abs(y - yTo) > bounds_h)
{
if (y < yTo) y+=spd;
else if (y > yTo) y-=spd;
var _spd = (dist_h/spd_threshold)*spd;
if (y < yTo) y+=_spd;
else if (y > yTo) y-=_spd;
}
} else if(moving){
//gradually moves camera into position based on duration
Expand Down
9 changes: 9 additions & 0 deletions scripts/stanncam_functions/stanncam_functions.gml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ function stanncam_zoom(_zoom, duration){
obj_stanncam.zoom_duration = duration;
}

/// @function stanncam_speed(spd,threshold)
/// @description changes the speed of the camera
/// @param spd how fast the camera can move
/// @param threshold minimum distance for the speed to have full effect
function stanncam_speed(spd,threshold){
obj_stanncam.spd = spd;
obj_stanncam.spd_threshold = threshold;
}

/// @function stanncam_x()
/// @description get camera x position. if need the middle of the screen use obj_stanncam.x
function stanncam_x(){
Expand Down

0 comments on commit 1fc36f1

Please sign in to comment.