Skip to content

Commit

Permalink
[ench] mouse confined from MainMenu + Handle movement when cursor is …
Browse files Browse the repository at this point in the history
…on edges in Game
  • Loading branch information
theludovyc committed Feb 8, 2025
1 parent 8976d26 commit cbab919
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
5 changes: 5 additions & 0 deletions Script/Gui/Menu/MainMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ extends MainMenu

@onready var panel_menu = %PanelMenu

func _ready() -> void:
super._ready()

Input.mouse_mode = Input.MOUSE_MODE_CONFINED

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
if Input.is_anything_pressed():
Expand Down
44 changes: 23 additions & 21 deletions theLudovyc/Camera2D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,35 @@ var pos_limit_bot_right: Vector2

# Called when the node enters the scene tree for the first time.
func _ready():
#Input.mouse_mode = Input.MOUSE_MODE_CONFINED
Input.mouse_mode = Input.MOUSE_MODE_CONFINED
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
#var mouse_pos = get_viewport().get_mouse_position()
#
#var viewport_rect = get_viewport_rect()
#
var mouse_pos = get_viewport().get_mouse_position()

var viewport_rect = get_viewport_rect()

var dir: Vector2
#if mouse_pos.x < Edge_Limit:
#dir.x = -1
#
#if mouse_pos.x > viewport_rect.size.x - Edge_Limit:
#dir.x = 1
#
#if mouse_pos.y < Edge_Limit:
#dir.y = -1
#
#if mouse_pos.y > viewport_rect.size.y - Edge_Limit:
#dir.y = 1
#
#dir = dir.normalized()

#if dir.length() == 0:
dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
if mouse_pos.x < Edge_Limit:
dir.x = -1

if mouse_pos.x > viewport_rect.size.x - Edge_Limit:
dir.x = 1

if mouse_pos.y < Edge_Limit:
dir.y = -1

if mouse_pos.y > viewport_rect.size.y - Edge_Limit:
dir.y = 1

dir = dir.normalized()

if dir.length() == 0:
dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")

position += dir * SPEED * delta

position.x = clamp(position.x, pos_limit_top_left.x, pos_limit_bot_right.x)
position.y = clamp(position.y, pos_limit_top_left.y, pos_limit_bot_right.y)

0 comments on commit cbab919

Please sign in to comment.