Update to working version

This commit is contained in:
John Murphy
2017-09-17 23:04:20 -07:00
parent a48a9a1310
commit 3a8344d0dc
10 changed files with 185 additions and 93 deletions
+9
View File
@@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=1]
[ext_resource path="res://debug_draw.gd" type="Script" id=1]
[node name="debug_draw" type="Node2D"]
script/script = ExtResource( 1 )
+32 -8
View File
@@ -1,34 +1,58 @@
[gd_scene load_steps=4 format=1]
[ext_resource path="res://earth.gd" type="Script" id=1]
[ext_resource path="res://Earth-800px.png" type="Texture" id=2]
[ext_resource path="res://Earth-800px.png" type="Texture" id=1]
[sub_resource type="CircleShape2D" id=1]
custom_solver_bias = 0.0
radius = 10.0
radius = 200.0
[sub_resource type="CircleShape2D" id=2]
custom_solver_bias = 0.0
radius = 800.0
[node name="Earth" type="KinematicBody2D"]
input/pickable = false
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 20, 0, 0, 20, 0, 0 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/0/trigger = false
collision/layers = 1
collision/mask = 1
collision/margin = 0.08
script/script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
[node name="Sprite" type="Sprite" parent="."]
transform/scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 2 )
texture = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
[node name="EarthCollision" type="CollisionShape2D" parent="."]
transform/scale = Vector2( 20, 20 )
shape = SubResource( 1 )
trigger = false
_update_shape_index = 0
[node name="GravityArea" type="Area2D" parent="."]
input/pickable = true
shapes/0/shape = SubResource( 2 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/0/trigger = false
space_override = 1
gravity_point = true
gravity_vec = Vector2( 0, 1 )
gravity = 55.0
linear_damp = 0.0
angular_damp = 0.0
[node name="GravityCollision" type="CollisionShape2D" parent="GravityArea"]
shape = SubResource( 2 )
trigger = false
_update_shape_index = 0
+16 -1
View File
@@ -1,10 +1,18 @@
[gd_scene load_steps=2 format=1]
[gd_scene load_steps=3 format=1]
[ext_resource path="res://eartharea.gd" type="Script" id=1]
[sub_resource type="CircleShape2D" id=1]
custom_solver_bias = 0.0
radius = 10.0
[node name="Area2D" type="Area2D"]
input/pickable = true
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 20, 0, 0, 20, 0, 0 )
shapes/0/trigger = true
space_override = 3
gravity_vec = Vector2( 0, 1 )
gravity = 98.0
@@ -12,4 +20,11 @@ linear_damp = 0.1
angular_damp = 1.0
script/script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
transform/scale = Vector2( 20, 20 )
shape = SubResource( 1 )
trigger = true
_update_shape_index = 0
+12 -41
View File
@@ -1,54 +1,25 @@
[gd_scene load_steps=7 format=1]
[gd_scene load_steps=5 format=1]
[ext_resource path="res://Level.gd" type="Script" id=1]
[ext_resource path="res://Rocket.tscn" type="PackedScene" id=2]
[ext_resource path="res://Moon.tscn" type="PackedScene" id=3]
[ext_resource path="res://Earth.tscn" type="PackedScene" id=4]
[ext_resource path="res://EarthArea.tscn" type="PackedScene" id=5]
[ext_resource path="res://camera.gd" type="Script" id=6]
[ext_resource path="res://Earth.tscn" type="PackedScene" id=2]
[ext_resource path="res://Rocket.tscn" type="PackedScene" id=3]
[ext_resource path="res://Moon.tscn" type="PackedScene" id=4]
[node name="MoonSpace" type="Node2D"]
script/script = ExtResource( 1 )
[node name="Rocket" parent="." instance=ExtResource( 2 )]
[node name="Earth" parent="." instance=ExtResource( 2 )]
transform/pos = Vector2( 246.872, 361.618 )
transform/pos = Vector2( 211.028, 755.178 )
[node name="Moon" parent="." instance=ExtResource( 3 )]
[node name="Rocket" parent="." instance=ExtResource( 3 )]
transform/pos = Vector2( 433.782, 663.086 )
transform/rot = 290.0
[node name="Moon" parent="." instance=ExtResource( 4 )]
transform/pos = Vector2( 1347.34, 318.09 )
[node name="Earth" parent="." instance=ExtResource( 4 )]
transform/pos = Vector2( 250, 600 )
[node name="Area2D" parent="Earth" instance=ExtResource( 5 )]
transform/scale = Vector2( 10, 10 )
gravity_point = true
gravity_distance_scale = 1.0
gravity = 1000.0
[node name="Camera2D" type="Camera2D" parent="."]
transform/pos = Vector2( 960, 540 )
anchor_mode = 1
rotating = false
current = false
zoom = Vector2( 1, 1 )
limit/left = -10000000
limit/top = -10000000
limit/right = 10000000
limit/bottom = 10000000
drag_margin/h_enabled = true
drag_margin/v_enabled = true
smoothing/enable = false
smoothing/speed = 5.0
drag_margin/left = 0.2
drag_margin/top = 0.2
drag_margin/right = 0.2
drag_margin/bottom = 0.2
script/script = ExtResource( 6 )
+26 -2
View File
@@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=1]
[gd_scene load_steps=5 format=1]
[ext_resource path="res://moon.gd" type="Script" id=1]
[ext_resource path="res://1311069131-800px.png" type="Texture" id=2]
@@ -8,6 +8,11 @@
custom_solver_bias = 0.0
radius = 80.0
[sub_resource type="CircleShape2D" id=2]
custom_solver_bias = 0.0
radius = 300.0
[node name="Moon" type="KinematicBody2D"]
input/pickable = false
@@ -24,10 +29,29 @@ script/script = ExtResource( 1 )
transform/scale = Vector2( 0.2, 0.2 )
texture = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
[node name="MoonCollision" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )
trigger = false
_update_shape_index = 0
[node name="Area2D" type="Area2D" parent="."]
input/pickable = true
shapes/0/shape = SubResource( 2 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/0/trigger = false
space_override = 1
gravity_point = true
gravity_vec = Vector2( 0, 1 )
gravity = 40.0
linear_damp = 0.0
angular_damp = 0.0
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource( 2 )
trigger = false
_update_shape_index = 0
+27 -2
View File
@@ -1,7 +1,8 @@
[gd_scene load_steps=4 format=1]
[gd_scene load_steps=5 format=1]
[ext_resource path="res://rocket.gd" type="Script" id=1]
[ext_resource path="res://rocket-297573-800px.png" type="Texture" id=2]
[ext_resource path="res://DebugDraw.tscn" type="PackedScene" id=3]
[sub_resource type="RectangleShape2D" id=1]
@@ -17,7 +18,7 @@ shapes/0/trigger = false
collision/layers = 1
collision/mask = 1
mode = 0
mass = 10.0
mass = 5.0
friction = 1.0
bounce = 0.0
gravity_scale = 1.0
@@ -32,6 +33,9 @@ velocity/angular = 0.0
damp_override/linear = -1.0
damp_override/angular = -1.0
script/script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
[node name="Sprite" type="Sprite" parent="."]
@@ -46,4 +50,25 @@ shape = SubResource( 1 )
trigger = false
_update_shape_index = 0
[node name="debug_draw" parent="." instance=ExtResource( 3 )]
[node name="Camera2D" type="Camera2D" parent="."]
anchor_mode = 1
rotating = false
current = true
zoom = Vector2( 1, 1 )
limit/left = -10000000
limit/top = -10000000
limit/right = 10000000
limit/bottom = 10000000
drag_margin/h_enabled = true
drag_margin/v_enabled = true
smoothing/enable = false
smoothing/speed = 5.0
drag_margin/left = 0.2
drag_margin/top = 0.2
drag_margin/right = 0.2
drag_margin/bottom = 0.2
+50
View File
@@ -0,0 +1,50 @@
# adapted with thanks from code by GDQuest
# http://gdquest.com/
extends Node2D
var colors = {
'BLUE': Color(.216, .474, .702),
'RED': Color(1.0, .329, .298),
'YELLOW': Color(.867, .91, .247),
'GREEN': Color(.054, .718, .247)
}
var WIDTH = 5
var parent = null
func _ready():
parent = get_parent()
set_process(true)
set_process_input(true)
set_hidden(true)
func _input(event):
#if event.is_action_pressed("ui_focus_next"):
# set_hidden(not is_hidden())
pass
func _process(delta):
set_global_rot(0)
update()
func _draw():
draw_arrow(parent.get_linear_velocity(), Vector2(), 1.0, 'YELLOW')
draw_arrow(parent.get_applied_force(), Vector2(), 0.5, 'RED')
func draw_arrow(vector, pos, scale, color):
color = colors[color]
if vector.length() == 0:
return
draw_line(pos * scale, vector * scale, color, WIDTH)
var dir = vector.normalized()
draw_triangle(vector * scale, dir, 10, color)
draw_circle(pos, 5, color)
func draw_triangle(pos, dir, size, color):
var a = pos + dir * size
var b = pos + dir.rotated(2*PI/3) * size
var c = pos + dir.rotated(4*PI/3) * size
var points = Vector2Array([a, b, c])
draw_polygon(points, ColorArray([color]))
+13 -39
View File
@@ -1,43 +1,17 @@
extends RigidBody2D
var time = 0.0
var thrust_force = Vector2()
var thrust
var revthrust
var bear_left
var bear_right
func _input(delta):
# var lv = s.get_linear_velocity()
# var step = s.get_step()
var rotation = get_rot()
# Get the controls
thrust = Input.is_action_pressed("thrust")
revthrust = Input.is_action_pressed("revthrust")
bear_left = Input.is_action_pressed("bear_left")
bear_right = Input.is_action_pressed("bear_right")
thrust_force = 5*Vector2(sin(rotation), cos(rotation))
func _fixed_process(delta):
time += delta
# print(time)
if (thrust):
# print("Rotation: ", rotation, " Linear velocity: ", lv, " sin rotation: ", sin(rotation), " cos rotation: ", cos(rotation))
apply_impulse(Vector2(0,0), -thrust_force)
if (revthrust):
apply_impulse(Vector2(0,0), thrust_force)
if (bear_left):
rotate(0.1)
if (bear_right):
rotate(-0.1)
var thrust = Vector2(0, 450)
var torque = 20000
func _ready():
# set_gravity_scale(1)
set_process(true)
set_process_input(true)
set_fixed_process(true)
pass
func _integrate_forces(state):
if Input.is_action_pressed("thrust"):
set_applied_force(state.get_total_gravity() - thrust.rotated(get_rot()))
elif Input.is_action_pressed("revthrust"):
set_applied_force(state.get_total_gravity() + thrust.rotated(get_rot()))
else:
set_applied_force(state.get_total_gravity() + Vector2())
var t = Input.is_action_pressed("bear_right") - Input.is_action_pressed("bear_left")
set_applied_torque(torque * t)
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB