forked from 2121578/gai-ca2
Initialized player
parent
0ba4cee5d4
commit
64106039c8
|
@ -10,7 +10,6 @@
|
|||
script = ExtResource("1_eeg2d")
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
offset = Vector2(575.745, 325.09)
|
||||
script = ExtResource("2_1vbjl")
|
||||
|
||||
[node name="Tileset" type="Node2D" parent="."]
|
||||
|
|
|
@ -66,6 +66,11 @@ key_2={
|
|||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":50,"key_label":0,"unicode":50,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
key_3={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":51,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
key_9={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":57,"key_label":0,"unicode":57,"location":0,"echo":false,"script":null)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
class_name Camera
|
||||
extends Camera2D
|
||||
|
||||
@export var border_acceleration: float = 800.0
|
||||
@export var border_acceleration: float = 2000.0
|
||||
@export var max_speed: float = 500.0
|
||||
@export var inner_border_threshold: float = 60.0
|
||||
@export var outer_border_threshold: float = 20.0
|
||||
@export var outer_border_threshold: float = 40.0
|
||||
@export var min_position: Vector2 = Vector2(-1000, -1000)
|
||||
@export var max_position: Vector2 = Vector2(4000, 4000)
|
||||
|
||||
|
@ -29,7 +29,11 @@ func go_to(position: Vector2) -> void:
|
|||
|
||||
|
||||
func print_config() -> void:
|
||||
print("camera.go_to_zooming(Vector2(", position.x, ", ", position.y, "), ", zoom, ")")
|
||||
print("camera.go_to_zooming(Vector2(", position.x, ", ", position.y, "), ", zoom.x, ")")
|
||||
|
||||
|
||||
func map_range(value: float, from_min: float, from_max: float, to_min: float, to_max: float) -> float:
|
||||
return to_min + (value - from_min) / (from_max - from_min) * (to_max - to_min)
|
||||
|
||||
|
||||
func _input(event):
|
||||
|
@ -70,9 +74,9 @@ func _process(delta):
|
|||
var is_zoom_out: bool = Input.is_action_pressed("camera_zoom_out")
|
||||
|
||||
if is_zoom_in:
|
||||
zoom = zoom * 1.1
|
||||
zoom = zoom * 1.02
|
||||
elif is_zoom_out:
|
||||
zoom = zoom / 1.1
|
||||
zoom = zoom / 1.02
|
||||
|
||||
if zoom.length() < 0.2:
|
||||
zoom = Vector2(1, 1).normalized() * 0.2
|
||||
|
@ -83,10 +87,13 @@ func _process(delta):
|
|||
var screen_size: Vector2 = get_viewport().get_visible_rect().size
|
||||
var acceleration: Vector2 = Vector2.ZERO
|
||||
|
||||
var is_up: bool = Input.is_action_pressed("camera_up") or mouse_pos.y < inner_border_threshold and mouse_pos.y > -outer_border_threshold
|
||||
var is_down: bool = Input.is_action_pressed("camera_down") or mouse_pos.y > screen_size.y - inner_border_threshold and mouse_pos.y < screen_size.y + outer_border_threshold
|
||||
var is_left: bool = Input.is_action_pressed("camera_left") or mouse_pos.x < inner_border_threshold and mouse_pos.x > -outer_border_threshold
|
||||
var is_right: bool = Input.is_action_pressed("camera_right") or mouse_pos.x > screen_size.x - inner_border_threshold and mouse_pos.x < screen_size.x + outer_border_threshold
|
||||
# the bigger the viewport size, the bigger the border threshold
|
||||
var border_threshold_addition: float = max(0, map_range(screen_size.length(), 1320, 2600, 0, 100))
|
||||
|
||||
var is_up: bool = Input.is_action_pressed("camera_up") or mouse_pos.y < inner_border_threshold + border_threshold_addition and mouse_pos.y > -outer_border_threshold
|
||||
var is_down: bool = Input.is_action_pressed("camera_down") or mouse_pos.y > screen_size.y - inner_border_threshold - border_threshold_addition and mouse_pos.y < screen_size.y + outer_border_threshold
|
||||
var is_left: bool = Input.is_action_pressed("camera_left") or mouse_pos.x < inner_border_threshold + border_threshold_addition and mouse_pos.x > -outer_border_threshold
|
||||
var is_right: bool = Input.is_action_pressed("camera_right") or mouse_pos.x > screen_size.x - inner_border_threshold - border_threshold_addition and mouse_pos.x < screen_size.x + outer_border_threshold
|
||||
|
||||
if is_left:
|
||||
acceleration.x = -border_acceleration
|
||||
|
|
|
@ -6,12 +6,13 @@ extends Node
|
|||
@onready var camera: Camera2D = $Camera2D
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
player.world = world
|
||||
player.camera = camera
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("key_1"):
|
||||
camera.go_to_zooming(Vector2(-100, -50), 1.5)
|
||||
camera.go_to_zooming(Vector2(517.469787597656, 289.846008300781), 1.771561)
|
||||
if Input.is_action_just_pressed("key_2"):
|
||||
camera.go_to_zooming(Vector2(200, 100), 0.4)
|
||||
camera.go_to_zooming(Vector2(789.883972167969, 450.102813720703), 0.56015348434448)
|
||||
if Input.is_action_just_pressed("key_9"):
|
||||
camera.print_config()
|
||||
|
|
|
@ -1,2 +1,19 @@
|
|||
class_name PlayerManager
|
||||
extends Node
|
||||
extends Node
|
||||
|
||||
var board_position: Vector2 = Vector2(0, 0)
|
||||
var world: World = null
|
||||
var camera: Camera2D = null
|
||||
#
|
||||
var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
|
||||
|
||||
func _ready() -> void:
|
||||
call_deferred("update_board")
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("key_3"):
|
||||
camera.go_to_zooming(world.tilemap_player.cell_to_local(board_position), 2)
|
||||
|
||||
func update_board() -> void:
|
||||
world.tilemap_player.clear_cells()
|
||||
world.tilemap_player.set_cell(board_position, tilemap_types.PLAYER)
|
||||
|
|
|
@ -28,16 +28,10 @@ func _ready() -> void:
|
|||
tilemap_player.setup()
|
||||
tilemap_temperature.setup()
|
||||
|
||||
|
||||
# example usage
|
||||
# tilemap_temperature.fill_area(Vector2i(0, 0), Vector2i(10, 10), tilemap_types.TEMPERATURE_COLD_1)
|
||||
# tilemap_temperature.fill_area(Vector2i(4, 4), Vector2i(6, 6), tilemap_types.TEMPERATURE_NORMAL)
|
||||
# print(tilemap_non_interactive.get_cells_by_custom_data("walkable", true))
|
||||
# tilemap_ground.clear_cells()
|
||||
# tilemap_ground.set_cell(Vector2i(0, 0), tilemap_types.GROUND_GRASS)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
# example usage
|
||||
# tilemap_temperature.fill_area(Vector2i(0, 0), Vector2i(10, 10), tilemap_types.TEMPERATURE_COLD_1)
|
||||
# tilemap_temperature.fill_area(Vector2i(4, 4), Vector2i(6, 6), tilemap_types.TEMPERATURE_NORMAL)
|
||||
# print(tilemap_non_interactive.get_cells_by_custom_data("walkable", true))
|
||||
# tilemap_ground.clear_cells()
|
||||
# tilemap_ground.set_cell(Vector2i(0, 0), tilemap_types.GROUND_GRASS)
|
||||
# print(tilemap_ground.local_to_cell(get_local_mouse_position()))
|
||||
|
|
Loading…
Reference in New Issue