Skip to content

Commit

Permalink
Adjustments in controls
Browse files Browse the repository at this point in the history
  • Loading branch information
Dancovich committed May 28, 2021
1 parent f3f114b commit 02a2939
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
18 changes: 5 additions & 13 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -74,51 +74,43 @@ texture={
[input]

move_up={
"deadzone": 0.5,
"deadzone": 0.1,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
]
}
move_down={
"deadzone": 0.5,
"deadzone": 0.1,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
]
}
move_left={
"deadzone": 0.5,
"deadzone": 0.1,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
]
}
move_right={
"deadzone": 0.5,
"deadzone": 0.1,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
]
}
eat={
"deadzone": 0.5,
"deadzone": 0.1,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
]
}
accept={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777221,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
]
}

[layer_names]

Expand Down
26 changes: 18 additions & 8 deletions snake/snake.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ signal food_swallowed(snake, qtd_food_swallowed)
signal dead

const SPEED := 220.0
const ROTATION_SPEED := 2.2
const ROTATION_SPEED := deg2rad(360.0)
const DEFAULT_SIZE := 0.85
const SIZE_INCREMENT := 0.08

Expand All @@ -17,6 +17,7 @@ onready var _anim: AnimationPlayer = $AnimationPlayer

var _body_parts := []
var _speed := Vector2.RIGHT * SPEED
var _direction := Vector2.RIGHT
var _size := DEFAULT_SIZE
var _queue_kill := false

Expand Down Expand Up @@ -106,15 +107,24 @@ func _physics_process(delta: float) -> void:
Input.get_action_strength("move_right") - Input.get_action_strength("move_left"), \
Input.get_action_strength("move_down") - Input.get_action_strength("move_up"))

if move == Vector2.ZERO:
if _speed == Vector2.ZERO:
_speed = Vector2.DOWN * SPEED
move = _speed
if move != Vector2.ZERO:
_direction = move.normalized()

var angle_delta := _speed.angle_to(move)
_speed = _speed.rotated(angle_delta * delta * ROTATION_SPEED).normalized() * SPEED * delta
_head.position += _speed
var delta_angle = _speed.angle_to(_direction)
if delta_angle != 0.0:
if delta_angle >= 0.0:
var angle := ROTATION_SPEED * delta
if abs(angle) > abs(delta_angle):
angle = delta_angle
_speed = _speed.rotated(angle)
else:
var angle := -ROTATION_SPEED * delta
if abs(angle) > abs(delta_angle):
angle = delta_angle
_speed = _speed.rotated(angle)

_speed = _speed.normalized() * SPEED * delta
_head.position += _speed
_head.rotation = Vector2.DOWN.angle_to(_speed)

if !_body_parts.empty():
Expand Down

0 comments on commit 02a2939

Please sign in to comment.