Permalink
Browse files

Godot 101 - Part 15

  • Loading branch information...
Chris Bradfield
Chris Bradfield committed Jul 23, 2017
1 parent 9a78ce5 commit ba4db7d8b3e27f4719a302746cf62ce8f5cdcff0
Showing with 517 additions and 167 deletions.
  1. +1 −1 Godot101/Part 04/main.gd
  2. BIN Godot101/Part 15/Xolonium-Regular.ttf
  3. BIN Godot101/Part 15/art/back.pbm
  4. BIN Godot101/Part 15/art/back.tex
  5. BIN Godot101/Part 15/art/ballBlack_10.png
  6. BIN Godot101/Part 15/art/boxCrate_double.png
  7. BIN Godot101/Part 15/art/spaceEffects_003.pbm
  8. BIN Godot101/Part 15/art/spaceEffects_003.tex
  9. BIN Godot101/Part 15/art/spaceMeteors_001.pbm
  10. BIN Godot101/Part 15/art/spaceMeteors_001.tex
  11. BIN Godot101/Part 15/art/spaceShips_009.pbm
  12. BIN Godot101/Part 15/art/spaceShips_009.tex
  13. BIN Godot101/Part 15/art/tileBlack_02.png
  14. BIN Godot101/Part 15/crate_icon.png
  15. +49 −0 Godot101/Part 15/debug_draw.gd
  16. +9 −0 Godot101/Part 15/debug_draw.tscn
  17. +19 −0 Godot101/Part 15/engine.cfg
  18. BIN Godot101/Part 15/icon.png
  19. +5 −0 Godot101/Part 15/main.tscn
  20. +15 −0 Godot101/Part 15/ship.gd
  21. +72 −0 Godot101/Part 15/ship.tscn
  22. +99 −0 Godot101/Part 15/space.tscn
  23. BIN Godot101/working/art/back.pbm
  24. BIN Godot101/working/art/back.tex
  25. BIN Godot101/working/art/spaceEffects_003.pbm
  26. BIN Godot101/working/art/spaceEffects_003.tex
  27. BIN Godot101/working/art/spaceMeteors_001.pbm
  28. BIN Godot101/working/art/spaceMeteors_001.tex
  29. BIN Godot101/working/art/spaceShips_009.pbm
  30. BIN Godot101/working/art/spaceShips_009.tex
  31. +0 −9 Godot101/working/crate.gd
  32. +0 −49 Godot101/working/crate.tscn
  33. +49 −0 Godot101/working/debug_draw.gd
  34. +9 −0 Godot101/working/debug_draw.tscn
  35. +3 −6 Godot101/working/engine.cfg
  36. +1 −102 Godot101/working/main.tscn
  37. +15 −0 Godot101/working/ship.gd
  38. +72 −0 Godot101/working/ship.tscn
  39. +99 −0 Godot101/working/space.tscn
@@ -5,4 +5,4 @@ onready var sprite = preload("res://Sprite.tscn")
func _ready():
for i in range(150):
var s = sprite.instance()
add_child(s)
add_child(s)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,49 @@
# 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())
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]))
@@ -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 )
@@ -0,0 +1,19 @@
[application]
name="Godot101: RigidBody2D"
icon="res://crate_icon.png"
[debug]
print_fps=false
[image_loader]
filter=false
gen_mipmaps=false
[physics_2d]
default_gravity=0
default_linear_damp=0.0
default_angular_damp=0
Binary file not shown.
@@ -0,0 +1,5 @@
[gd_scene format=1]
[node name="main" type="Node"]
@@ -0,0 +1,15 @@
extends RigidBody2D
var thrust = Vector2(0, 250)
var torque = 20000
func _ready():
pass
func _integrate_forces(state):
if Input.is_action_pressed("ui_up"):
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("ui_right") - Input.is_action_pressed("ui_left")
set_applied_torque(torque * t)
@@ -0,0 +1,72 @@
[gd_scene load_steps=5 format=1]
[ext_resource path="res://ship.gd" type="Script" id=1]
[ext_resource path="res://art/spaceShips_009.tex" type="Texture" id=2]
[ext_resource path="res://debug_draw.tscn" type="PackedScene" id=3]
[sub_resource type="CircleShape2D" id=1]
custom_solver_bias = 0.0
radius = 40.9103
[node name="ship" type="RigidBody2D"]
transform/pos = Vector2( 136.837, 74.9346 )
input/pickable = false
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/0/trigger = false
collision/layers = 1
collision/mask = 1
mode = 0
mass = 1.0
friction = 1.0
bounce = 0.0
gravity_scale = 1.0
custom_integrator = false
continuous_cd = 0
contacts_reported = 0
contact_monitor = false
sleeping = false
can_sleep = true
velocity/linear = Vector2( 0, 0 )
velocity/angular = 0.0
damp_override/linear = -1.0
damp_override/angular = 5.0
script/script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
[node name="sprite" type="Sprite" parent="."]
texture = ExtResource( 2 )
[node name="collision" type="CollisionShape2D" parent="."]
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
@@ -0,0 +1,99 @@
[gd_scene load_steps=8 format=1]
[ext_resource path="res://art/back.tex" type="Texture" id=1]
[ext_resource path="res://art/ballBlack_10.png" type="Texture" id=2]
[ext_resource path="res://art/spaceMeteors_001.tex" type="Texture" id=3]
[ext_resource path="res://debug_draw.tscn" type="PackedScene" id=4]
[ext_resource path="res://ship.tscn" type="PackedScene" id=5]
[sub_resource type="CircleShape2D" id=1]
custom_solver_bias = 0.0
radius = 669.187
[sub_resource type="CircleShape2D" id=2]
custom_solver_bias = 0.0
radius = 104.901
[node name="space" type="Node"]
[node name="starfield-1" type="Sprite" parent="."]
transform/pos = Vector2( 2032.27, 356.497 )
texture = ExtResource( 1 )
region = true
region_rect = Rect2( 0, 0, 10000, 5000 )
[node name="planet" type="Area2D" parent="."]
transform/pos = Vector2( 1654.95, 295.684 )
input/pickable = true
shapes/0/shape = SubResource( 1 )
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 = 196.0
linear_damp = 0.0
angular_damp = 0.0
__meta__ = {
"_edit_group_": true
}
[node name="sprite" type="Sprite" parent="planet"]
texture = ExtResource( 2 )
[node name="collision" type="CollisionShape2D" parent="planet"]
shape = SubResource( 1 )
trigger = false
_update_shape_index = 0
[node name="rock" type="RigidBody2D" parent="."]
transform/pos = Vector2( 133.317, 114.271 )
input/pickable = false
shapes/0/shape = SubResource( 2 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/0/trigger = false
collision/layers = 1
collision/mask = 1
mode = 0
mass = 100.0
friction = 1.0
bounce = 0.0
gravity_scale = 1.0
custom_integrator = false
continuous_cd = 0
contacts_reported = 0
contact_monitor = false
sleeping = false
can_sleep = true
velocity/linear = Vector2( 20, 20 )
velocity/angular = 0.25
damp_override/linear = -1.0
damp_override/angular = -1.0
__meta__ = {
"_edit_group_": true
}
[node name="sprite" type="Sprite" parent="rock"]
texture = ExtResource( 3 )
[node name="collision" type="CollisionShape2D" parent="rock"]
shape = SubResource( 2 )
trigger = false
_update_shape_index = 0
[node name="debug_draw" parent="rock" instance=ExtResource( 4 )]
[node name="ship" parent="." instance=ExtResource( 5 )]
transform/pos = Vector2( 492.523, 304.312 )
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,49 @@
# 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())
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]))
Oops, something went wrong.

0 comments on commit ba4db7d

Please sign in to comment.