added a very basic boat simulation
This commit is contained in:
10
resources/scenes/Level1.tscn
Normal file
10
resources/scenes/Level1.tscn
Normal file
@@ -0,0 +1,10 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://resources/scenes/Player.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://resources/scenes/Player.gd" type="Script" id=2]
|
||||
|
||||
[node name="Level1" type="Node2D"]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource( 1 )]
|
||||
position = Vector2( 304, 152 )
|
||||
script = ExtResource( 2 )
|
37
resources/scenes/Player.gd
Normal file
37
resources/scenes/Player.gd
Normal file
@@ -0,0 +1,37 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
const WIND = 20
|
||||
const SPEED = 400
|
||||
const STEERING = deg2rad(5)
|
||||
const WINDLIMIT = deg2rad(180-45)
|
||||
const WINDDIR = Vector2(0,1)
|
||||
const STEERPEN = 1
|
||||
const ACCELERATION = 2
|
||||
|
||||
var velocity = Vector2(0,10)
|
||||
|
||||
func _calculate_velocity(_velocity, _acceleration, _rotation):
|
||||
velocity = _velocity * _acceleration
|
||||
velocity = velocity.clamped(_calculate_maxspeed())
|
||||
return velocity.rotated(_rotation)
|
||||
|
||||
func _calculate_maxspeed():
|
||||
var angle_to_wind = WINDDIR.angle_to(velocity)
|
||||
if angle_to_wind > WINDLIMIT || angle_to_wind < -WINDLIMIT:
|
||||
return 0.1
|
||||
else:
|
||||
return 75
|
||||
|
||||
func _physics_process(_delta):
|
||||
if Input.is_action_pressed("right"):
|
||||
velocity = _calculate_velocity(velocity, STEERPEN, STEERING)
|
||||
rotate(STEERING)
|
||||
elif Input.is_action_pressed("left"):
|
||||
velocity = _calculate_velocity(velocity, STEERPEN, -STEERING)
|
||||
rotate(-STEERING)
|
||||
else:
|
||||
velocity = _calculate_velocity(velocity, ACCELERATION, 0)
|
||||
velocity = move_and_slide(velocity)
|
||||
|
||||
func _ready():
|
||||
pass
|
14
resources/scenes/Player.tscn
Normal file
14
resources/scenes/Player.tscn
Normal file
@@ -0,0 +1,14 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://resources/sprites/bluedotwithline.png" type="Texture" id=1]
|
||||
|
||||
[sub_resource type="CircleShape2D" id=1]
|
||||
|
||||
[node name="Player" type="KinematicBody2D"]
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
scale = Vector2( 5, 5 )
|
||||
shape = SubResource( 1 )
|
Reference in New Issue
Block a user