started work on sticky cameras

made a new world scene with only the one camera and walls
master
Zachary Epps 4 years ago
parent e8c38d4478
commit 5eae948ebf
  1. BIN
      images/projectile.png
  2. 29
      images/projectile.png.import
  3. 6
      project.godot
  4. 82
      scenes/1CamWorld.tscn
  5. 56
      scenes/StickyCam.tscn
  6. 29
      scenes/player.tscn
  7. 2
      scenes/world.tscn
  8. 34
      scripts/NewPlayer.gd
  9. 27
      scripts/StickyCam.gd

Binary file not shown.

After

Width:  |  Height:  |  Size: 1003 B

@ -0,0 +1,29 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/projectile.png-677cc17c75d144b24ef7dd3ba5e08608.stex"
[deps]
source_file="res://images/projectile.png"
dest_files=[ "res://.import/projectile.png-677cc17c75d144b24ef7dd3ba5e08608.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

@ -13,12 +13,18 @@ config_version=3
config/name="2D Stealth Test"
config/icon="res://icon.png"
[input]
fire=[ 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)
]
[layer_names]
2d_physics/layer_1="player"
2d_physics/layer_2="environment"
2d_physics/layer_3="player points"
2d_physics/layer_4="camera vision"
2d_physics/layer_5="projectiles"
[rendering]

@ -0,0 +1,82 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://images/wall.png" type="Texture" id=1]
[ext_resource path="res://scenes/blocker.tscn" type="PackedScene" id=2]
[ext_resource path="res://scenes/player.tscn" type="PackedScene" id=3]
[ext_resource path="res://scenes/Camera.tscn" type="PackedScene" id=4]
[node name="world" type="Node2D" index="0"]
__meta__ = {
"_edit_horizontal_guides_": [ ],
"_edit_vertical_guides_": [ ]
}
[node name="BG" type="Sprite" parent="." index="0"]
self_modulate = Color( 0.472656, 0.273254, 0.273254, 1 )
position = Vector2( 296.637, 200.305 )
scale = Vector2( 10.2699, 7.25954 )
texture = ExtResource( 1 )
[node name="BulletHolder" type="Node2D" parent="." index="1"]
scale = Vector2( 1, 1 )
[node name="Walls" type="Node2D" parent="." index="2"]
scale = Vector2( 1, 1 )
[node name="blocker3" parent="Walls" index="0" instance=ExtResource( 2 )]
position = Vector2( 229.243, 60.4224 )
scale = Vector2( 4.1055, 0.320292 )
collision_layer = 2
collision_mask = 1
_sections_unfolded = [ "Collision", "Transform" ]
[node name="blocker4" parent="Walls" index="1" instance=ExtResource( 2 )]
position = Vector2( 229.243, 210.849 )
scale = Vector2( 4.1055, 0.320292 )
collision_layer = 2
collision_mask = 1
_sections_unfolded = [ "Collision", "Transform" ]
[node name="blocker5" parent="Walls" index="2" instance=ExtResource( 2 )]
position = Vector2( 102.655, 142.244 )
rotation = 1.5708
scale = Vector2( 4.1055, 0.320292 )
collision_layer = 2
collision_mask = 1
_sections_unfolded = [ "Collision", "Transform" ]
[node name="blocker6" parent="Walls" index="3" instance=ExtResource( 2 )]
position = Vector2( 358.349, 142.244 )
rotation = 1.5708
scale = Vector2( 4.1055, 0.320292 )
collision_layer = 2
collision_mask = 1
_sections_unfolded = [ "Collision", "Transform" ]
[node name="player" parent="." index="3" instance=ExtResource( 3 )]
position = Vector2( 230.081, 135.338 )
[node name="blocker" parent="." index="4" instance=ExtResource( 2 )]
position = Vector2( 194.043, 131.413 )
scale = Vector2( 0.320292, 0.320292 )
[node name="blocker2" parent="." index="5" instance=ExtResource( 2 )]
position = Vector2( 171.298, 161.534 )
scale = Vector2( 0.320292, 0.320292 )
[node name="Camera" parent="." index="6" instance=ExtResource( 4 )]
position = Vector2( 182.58, 101.129 )

@ -0,0 +1,56 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://scripts/StickyCam.gd" type="Script" id=1]
[ext_resource path="res://images/projectile.png" type="Texture" id=2]
[sub_resource type="CircleShape2D" id=1]
custom_solver_bias = 0.0
radius = 0.456815
[node name="StickyCam" type="KinematicBody2D"]
input_pickable = false
collision_layer = 16
collision_mask = 3
collision/safe_margin = 0.08
script = ExtResource( 1 )
_sections_unfolded = [ "Collision" ]
Speed = 20
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="0"]
shape = SubResource( 1 )
[node name="Sprite" type="Sprite" parent="." index="1"]
scale = Vector2( 0.01, 0.01 )
texture = ExtResource( 2 )
_sections_unfolded = [ "Transform", "Visibility" ]
[node name="Camera2D" type="Camera2D" parent="." index="2"]
anchor_mode = 1
rotating = false
current = false
zoom = Vector2( 1, 1 )
limit_left = -10000000
limit_top = -10000000
limit_right = 10000000
limit_bottom = 10000000
limit_smoothed = false
drag_margin_h_enabled = true
drag_margin_v_enabled = true
smoothing_enabled = false
smoothing_speed = 5.0
offset_v = 0.0
offset_h = 0.0
drag_margin_left = 0.2
drag_margin_top = 0.2
drag_margin_right = 0.2
drag_margin_bottom = 0.2
editor_draw_screen = true
editor_draw_limits = false
editor_draw_drag_margin = false

@ -1,7 +1,8 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://scripts/NewPlayer.gd" type="Script" id=1]
[ext_resource path="res://images/ground.png" type="Texture" id=2]
[ext_resource path="res://scenes/StickyCam.tscn" type="PackedScene" id=2]
[ext_resource path="res://images/ground.png" type="Texture" id=3]
[sub_resource type="OccluderPolygon2D" id=1]
@ -25,7 +26,7 @@ extents = Vector2( 0.803516, 0.825516 )
input_pickable = false
collision_layer = 1
collision_mask = 2
collision_mask = 18
collision/safe_margin = 0.08
script = ExtResource( 1 )
_sections_unfolded = [ "Collision" ]
@ -33,6 +34,7 @@ __meta__ = {
"_edit_vertical_guides_": [ 7.25047, -7.23965 ]
}
Speed = 10
StickyCam = ExtResource( 2 )
[node name="LightOccluder2D" type="LightOccluder2D" parent="." index="0"]
@ -42,7 +44,7 @@ light_mask = 1
[node name="Sprite" type="Sprite" parent="." index="1"]
scale = Vector2( 0.226408, 0.226408 )
texture = ExtResource( 2 )
texture = ExtResource( 3 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="2"]
@ -65,14 +67,14 @@ smoothing_enabled = false
smoothing_speed = 5.0
offset_v = 0.0
offset_h = 0.0
drag_margin_left = 0.1
drag_margin_top = 0.1
drag_margin_right = 0.1
drag_margin_bottom = 0.1
drag_margin_left = 0.01
drag_margin_top = 0.01
drag_margin_right = 0.01
drag_margin_bottom = 0.01
editor_draw_screen = true
editor_draw_limits = false
editor_draw_drag_margin = false
_sections_unfolded = [ "Editor", "Limit" ]
_sections_unfolded = [ "Drag Margin", "Editor", "Limit" ]
[node name="Points" type="Node2D" parent="." index="4"]
@ -177,4 +179,13 @@ _sections_unfolded = [ "Collision", "Transform" ]
shape = SubResource( 3 )
[node name="FirePoint" type="Node2D" parent="." index="5"]
_sections_unfolded = [ "Transform" ]
[node name="GunPoint" type="Position2D" parent="FirePoint" index="0"]
position = Vector2( 0, -8.28708 )
scale = Vector2( 1, 1 )

@ -205,7 +205,7 @@ scale = Vector2( 0.320292, 0.320292 )
position = Vector2( 171.298, 161.534 )
scale = Vector2( 0.320292, 0.320292 )
[node name="NewNewCamera" parent="." index="6" instance=ExtResource( 7 )]
[node name="Camera" parent="." index="6" instance=ExtResource( 7 )]
position = Vector2( 180.878, 100.109 )

@ -1,10 +1,20 @@
extends KinematicBody2D
enum Direction {
LEFT,
RIGHT,
UP,
DOWN
}
export(int) var Speed = 10
export(PackedScene) var StickyCam
onready var BulletParent = get_tree().root.find_node("BulletHolder", true, false)
onready var GunEnd = get_node("FirePoint/GunPoint")
onready var Gun = GunEnd.get_node("..")
func _ready():
pass
var CurrentDirection = UP
func _process(delta):
# if we set up velocity to be 0 then we stop as soon as the player
@ -17,19 +27,37 @@ func _process(delta):
# going left and right
if Input.is_action_pressed('ui_left'):
Gun.set_rotation_degrees(-90)
CurrentDirection = LEFT
velocity.x -= Speed
elif Input.is_action_pressed('ui_right'):
Gun.set_rotation_degrees(90)
CurrentDirection = RIGHT
velocity.x += Speed
# going up and down
if Input.is_action_pressed('ui_up'):
Gun.set_rotation_degrees(0)
CurrentDirection = UP
velocity.y -= Speed
elif Input.is_action_pressed('ui_down'):
Gun.set_rotation_degrees(180)
CurrentDirection = DOWN
velocity.y += Speed
# if the player is holding shift, give us a speedboost
if Input.is_key_pressed(KEY_SHIFT):
velocity *= 2
if Input.is_action_just_pressed("fire"):
fire()
# and finally, we move and collide!
move_and_slide(velocity)
move_and_slide(velocity)
func fire():
var sc = StickyCam.instance()
sc.set_direction(CurrentDirection)
sc.set_position(to_global(GunEnd.position))
BulletParent.add_child(sc)

@ -0,0 +1,27 @@
extends KinematicBody2D
const DirVectors = [
Vector2(-1, 0),
Vector2(1, 0),
Vector2(0, -1),
Vector2(0, 1)
]
export var Speed = 20
var Direction setget set_direction
var Collided = false
func _enter_tree():
position = $"..".to_local(position)
func _physics_process(delta):
if not Collided:
var col = move_and_collide(DirVectors[Direction] * Speed)
Collided = col != null
func set_position(pos):
position = pos
func set_direction(dir):
Direction = dir
Loading…
Cancel
Save