Skip to content

Commit

Permalink
Door + improved Hook
Browse files Browse the repository at this point in the history
  • Loading branch information
RealMelwei committed Sep 15, 2018
1 parent 3ce3c1a commit cbf4bc3
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 35 deletions.
30 changes: 30 additions & 0 deletions Door.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://sprites/Door.png" type="Texture" id=1]

[sub_resource type="RectangleShape2D" id=1]

custom_solver_bias = 0.0
extents = Vector2( 10, 10 )

[node name="Door" type="Area2D"]

input_pickable = true
gravity_vec = Vector2( 0, 1 )
gravity = 98.0
linear_damp = 0.1
angular_damp = 1.0
audio_bus_override = false
audio_bus_name = "Master"

[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="0"]

scale = Vector2( 0.4, 0.8 )
shape = SubResource( 1 )
_sections_unfolded = [ "Transform" ]

[node name="Sprite" type="Sprite" parent="." index="1"]

texture = ExtResource( 1 )


2 changes: 1 addition & 1 deletion entities/Mob1.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[sub_resource type="RectangleShape2D" id=1]

custom_solver_bias = 0.0
extents = Vector2( 32, 44 )
extents = Vector2( 31, 44 )

[node name="Mob1" type="KinematicBody2D"]

Expand Down
70 changes: 37 additions & 33 deletions entities/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,6 @@ func _input(event):
hook_active = false

func _physics_process(delta):
# Beschleunigung berechnen
var acceleration = Vector2(key_force.x * ACCELERATION_X, 0)
var friction = Vector2(-sign(velocity.x) * FRICTION.x, -sign(velocity.y) * FRICTION.y)
var move_velocity = velocity + acceleration + friction + Vector2(0, GRAVITY)

# Anhalten, wenn zu langsam
if abs(move_velocity.x) <= 1.1 * FRICTION.x:
move_velocity.x = 0

# Gravitation
if is_on_floor():
if key_force.y < 0:
move_velocity.y = JUMP_VELOCITY_Y

# Geschwindigkeit begrenzen
if abs(move_velocity.x) > MAX_VELOCITY_X:
move_velocity.x = sign(move_velocity.x) * MAX_VELOCITY_X
if move_velocity.y > MAX_FALL_VELOCITY:
move_velocity.y = MAX_FALL_VELOCITY



# Projektile
if shoot_button_pressed:
shoot_button_pressed = false
Expand All @@ -103,18 +81,18 @@ func _physics_process(delta):

move_hooked(hook)
else:
move(move_velocity)
move_unhooked(false)
else:
var hook = hook_scene.instance()
get_parent().add_child(hook)
hook.position = position + (hook_offset * crosshair_position)
hook.rotation = Vector2(1, 0).angle_to(crosshair_position)
hook.direction = (hook.position - position).normalized()
hook.update_physics()
move(move_velocity)
move_unhooked(false)
else:

move(move_velocity)
move_unhooked(false)
if get_parent().has_node("Hook"):
get_parent().remove_child(get_parent().get_node("Hook"))

Expand Down Expand Up @@ -145,12 +123,38 @@ func get_vertical_comp(of_vector,to_vector):
var x = of_vector-((to_vector.dot(of_vector))/(to_vector.dot(to_vector)))*to_vector
return x

func move_hooked(hook):
var dir = (hook.position-position).normalized()
var dir_scaled = dir*hook.pull_strength
var key_force_dir = Vector2(key_force.x, 0)
var key_force_vert = get_vertical_comp(key_force_dir,dir)*AIRCONTROL_ACCELERATION;
var grav_vert = get_vertical_comp(Vector2(0, AIRCONTROL_GRAVITY),dir);
func move_unhooked(jump_ungrounded):
# Beschleunigung berechnen
var acceleration = Vector2(key_force.x * ACCELERATION_X, 0)
var friction = Vector2(-sign(velocity.x) * FRICTION.x, -sign(velocity.y) * FRICTION.y)
var move_velocity = velocity + acceleration + friction + Vector2(0, GRAVITY)

move_and_slide(dir_scaled)
move_and_slide(key_force_vert+grav_vert)
# Anhalten, wenn zu langsam
if abs(move_velocity.x) <= 1.1 * FRICTION.x:
move_velocity.x = 0

# Gravitation
if is_on_floor() or jump_ungrounded:
if key_force.y < 0:
move_velocity.y = JUMP_VELOCITY_Y

# Geschwindigkeit begrenzen
if abs(move_velocity.x) > MAX_VELOCITY_X:
move_velocity.x = sign(move_velocity.x) * MAX_VELOCITY_X
if move_velocity.y > MAX_FALL_VELOCITY:
move_velocity.y = MAX_FALL_VELOCITY
move(move_velocity);

func move_hooked(hook):
if key_force.y==0:
var dir = (hook.position-position).normalized()
var dir_scaled = dir*hook.pull_strength
var key_force_dir = Vector2(key_force.x, 0)
var key_force_vert = get_vertical_comp(key_force_dir,dir)*AIRCONTROL_ACCELERATION;
var grav_vert = get_vertical_comp(Vector2(0, AIRCONTROL_GRAVITY),dir);

move_and_slide(dir_scaled)
move_and_slide(key_force_vert+grav_vert)
else:
move_unhooked(true)
hook_active=false
3 changes: 2 additions & 1 deletion main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

[node name="TileMap" type="TileMap" parent="Environment" index="0"]

position = Vector2( -53.1857, -33.241 )
scale = Vector2( 8, 8 )
mode = 0
tile_set = ExtResource( 1 )
Expand All @@ -28,7 +29,7 @@ collision_layer = 1
collision_mask = 1
occluder_light_mask = 1
format = 1
tile_data = PoolIntArray( 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 65536, 0, 0, 65537, 1, 0, 65538, 1, 0, 65539, 1, 0, 65540, 1, 0, 65541, 1, 0, 65542, 1, 0, 65543, 1, 0, 65544, 1, 0, 65545, 1, 0, 65546, 1, 0, 65547, 1, 0, 65548, 1, 0, 65549, 1, 0, 65550, 1, 0, 65551, 0, 0, 131072, 0, 0, 131073, 1, 0, 131074, 1, 0, 131075, 1, 0, 131076, 1, 0, 131077, 1, 0, 131078, 1, 0, 131079, 1, 0, 131080, 1, 0, 131081, 1, 0, 131082, 1, 0, 131083, 1, 0, 131084, 1, 0, 131085, 1, 0, 131086, 1, 0, 131087, 0, 0, 196608, 0, 0, 196609, 1, 0, 196610, 1, 0, 196611, 1, 0, 196612, 1, 0, 196613, 1, 0, 196614, 1, 0, 196615, 1, 0, 196616, 1, 0, 196617, 1, 0, 196618, 1, 0, 196619, 1, 0, 196620, 1, 0, 196621, 1, 0, 196622, 1, 0, 196623, 0, 0, 262144, 0, 0, 262145, 1, 0, 262146, 1, 0, 262147, 1, 0, 262148, 1, 0, 262149, 1, 0, 262150, 1, 0, 262151, 1, 0, 262152, 1, 0, 262153, 1, 0, 262154, 1, 0, 262155, 1, 0, 262156, 1, 0, 262157, 1, 0, 262158, 1, 0, 262159, 0, 0, 327680, 0, 0, 327681, 1, 0, 327682, 1, 0, 327683, 1, 0, 327684, 1, 0, 327685, 0, 0, 327686, 1, 0, 327687, 0, 0, 327688, 0, 0, 327689, 0, 0, 327690, 1, 0, 327691, 1, 0, 327692, 1, 0, 327693, 1, 0, 327694, 1, 0, 327695, 0, 0, 393216, 0, 0, 393217, 1, 0, 393218, 1, 0, 393219, 1, 0, 393220, 1, 0, 393221, 1, 0, 393222, 1, 0, 393223, 1, 0, 393224, 1, 0, 393225, 1, 0, 393226, 1, 0, 393227, 1, 0, 393228, 1, 0, 393229, 1, 0, 393230, 1, 0, 393231, 0, 0, 458752, 0, 0, 458753, 1, 0, 458754, 1, 0, 458755, 1, 0, 458756, 1, 0, 458757, 1, 0, 458758, 1, 0, 458759, 1, 0, 458760, 1, 0, 458761, 1, 0, 458762, 1, 0, 458763, 1, 0, 458764, 1, 0, 458765, 1, 0, 458766, 1, 0, 458767, 0, 0, 524288, 0, 0, 524289, 0, 0, 524290, 0, 0, 524291, 0, 0, 524292, 0, 0, 524293, 0, 0, 524294, 0, 0, 524295, 0, 0, 524296, 0, 0, 524297, 0, 0, 524298, 0, 0, 524299, 0, 0, 524300, 0, 0, 524301, 0, 0, 524302, 0, 0, 524303, 0, 0, 589824, 1, 0, 589825, 1, 0, 589826, 1, 0, 589827, 1, 0, 589828, 1, 0, 589829, 1, 0, 589830, 1, 0, 589831, 1, 0, 589832, 1, 0, 589833, 1, 0, 589834, 1, 0, 589835, 1, 0, 589836, 1, 0, 589837, 1, 0, 589838, 1, 0, 589839, 1, 0 )
tile_data = PoolIntArray( -131055, 0, 0, -131054, 0, 0, -131053, 0, 0, -131052, 0, 0, -131051, 0, 0, -131050, 0, 0, -131049, 0, 0, -131048, 0, 0, -65519, 0, 0, -65518, 1, 0, -65517, 1, 0, -65516, 1, 0, -65515, 1, 0, -65514, 1, 0, -65513, 1, 0, -65512, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 16, 0, 0, 17, 0, 0, 18, 1, 0, 19, 1, 0, 20, 1, 0, 21, 1, 0, 22, 1, 0, 23, 1, 0, 24, 0, 0, 65536, 0, 0, 65537, 1, 0, 65538, 1, 0, 65539, 1, 0, 65540, 1, 0, 65541, 1, 0, 65542, 1, 0, 65543, 1, 0, 65544, 1, 0, 65545, 1, 0, 65546, 1, 0, 65547, 1, 0, 65548, 1, 0, 65549, 1, 0, 65550, 1, 0, 65551, 0, 0, 65552, 0, 0, 65553, 0, 0, 65554, 1, 0, 65555, 1, 0, 65556, 1, 0, 65557, 1, 0, 65558, 1, 0, 65559, 1, 0, 65560, 0, 0, 131072, 0, 0, 131073, 1, 0, 131074, 1, 0, 131075, 1, 0, 131076, 1, 0, 131077, 1, 0, 131078, 1, 0, 131079, 1, 0, 131080, 1, 0, 131081, 1, 0, 131082, 1, 0, 131083, 1, 0, 131084, 1, 0, 131085, 1, 0, 131086, 1, 0, 131087, 0, 0, 131088, 0, 0, 131089, 0, 0, 131090, 1, 0, 131091, 1, 0, 131092, 1, 0, 131093, 0, 0, 131094, 1, 0, 131095, 1, 0, 131096, 0, 0, 131097, 0, 0, 131098, 0, 0, 131099, 0, 0, 131100, 0, 0, 196608, 0, 0, 196609, 1, 0, 196610, 1, 0, 196611, 1, 0, 196612, 1, 0, 196613, 1, 0, 196614, 1, 0, 196615, 1, 0, 196616, 1, 0, 196617, 1, 0, 196618, 1, 0, 196619, 1, 0, 196620, 1, 0, 196621, 1, 0, 196622, 1, 0, 196623, 1, 0, 196624, 1, 0, 196625, 1, 0, 196626, 1, 0, 196627, 1, 0, 196628, 1, 0, 196629, 0, 0, 196630, 1, 0, 196631, 1, 0, 196632, 1, 0, 196633, 1, 0, 196634, 1, 0, 196635, 1, 0, 196636, 0, 0, 262144, 0, 0, 262145, 1, 0, 262146, 1, 0, 262147, 1, 0, 262148, 1, 0, 262149, 1, 0, 262150, 1, 0, 262151, 1, 0, 262152, 1, 0, 262153, 1, 0, 262154, 1, 0, 262155, 1, 0, 262156, 1, 0, 262157, 1, 0, 262158, 1, 0, 262159, 1, 0, 262160, 1, 0, 262161, 1, 0, 262162, 1, 0, 262163, 1, 0, 262164, 1, 0, 262165, 0, 0, 262166, 1, 0, 262167, 1, 0, 262168, 1, 0, 262169, 1, 0, 262170, 1, 0, 262171, 1, 0, 262172, 0, 0, 327680, 0, 0, 327681, 1, 0, 327682, 1, 0, 327683, 1, 0, 327684, 1, 0, 327685, 0, 0, 327686, 1, 0, 327687, 0, 0, 327688, 0, 0, 327689, 0, 0, 327690, 1, 0, 327691, 1, 0, 327692, 1, 0, 327693, 1, 0, 327694, 1, 0, 327695, 1, 0, 327696, 1, 0, 327697, 1, 0, 327698, 1, 0, 327699, 1, 0, 327700, 1, 0, 327701, 0, 0, 327702, 1, 0, 327703, 1, 0, 327704, 1, 0, 327705, 1, 0, 327706, 1, 0, 327707, 1, 0, 327708, 0, 0, 393216, 0, 0, 393217, 1, 0, 393218, 1, 0, 393219, 1, 0, 393220, 1, 0, 393221, 1, 0, 393222, 1, 0, 393223, 1, 0, 393224, 1, 0, 393225, 1, 0, 393226, 1, 0, 393227, 1, 0, 393228, 1, 0, 393229, 1, 0, 393230, 1, 0, 393231, 0, 0, 393232, 1, 0, 393233, 1, 0, 393234, 0, 0, 393235, 0, 0, 393236, 0, 0, 393237, 0, 0, 393238, 1, 0, 393239, 1, 0, 393240, 0, 0, 393241, 0, 0, 393242, 0, 0, 393243, 0, 0, 393244, 0, 0, 458752, 0, 0, 458753, 1, 0, 458754, 1, 0, 458755, 1, 0, 458756, 1, 0, 458757, 1, 0, 458758, 1, 0, 458759, 1, 0, 458760, 1, 0, 458761, 1, 0, 458762, 1, 0, 458763, 1, 0, 458764, 1, 0, 458765, 1, 0, 458766, 1, 0, 458767, 0, 0, 458768, 1, 0, 458769, 1, 0, 458770, 1, 0, 458771, 1, 0, 458772, 1, 0, 458773, 1, 0, 458774, 1, 0, 458775, 1, 0, 458776, 0, 0, 524288, 0, 0, 524289, 0, 0, 524290, 0, 0, 524291, 0, 0, 524292, 0, 0, 524293, 0, 0, 524294, 0, 0, 524295, 0, 0, 524296, 0, 0, 524297, 0, 0, 524298, 0, 0, 524299, 0, 0, 524300, 0, 0, 524301, 0, 0, 524302, 0, 0, 524303, 0, 0, 524304, 1, 0, 524305, 1, 0, 524306, 1, 0, 524307, 1, 0, 524308, 1, 0, 524309, 1, 0, 524310, 1, 0, 524311, 1, 0, 524312, 0, 0, 589824, 1, 0, 589825, 1, 0, 589826, 1, 0, 589827, 1, 0, 589828, 1, 0, 589829, 1, 0, 589830, 1, 0, 589831, 1, 0, 589832, 1, 0, 589833, 1, 0, 589834, 1, 0, 589835, 1, 0, 589836, 1, 0, 589837, 1, 0, 589838, 1, 0, 589839, 0, 0, 589840, 1, 0, 589841, 1, 0, 589842, 1, 0, 589843, 1, 0, 589844, 1, 0, 589845, 1, 0, 589846, 1, 0, 589847, 1, 0, 589848, 0, 0, 655375, 0, 0, 655376, 0, 0, 655377, 0, 0, 655378, 0, 0, 655379, 0, 0, 655380, 0, 0, 655381, 0, 0, 655382, 0, 0, 655383, 0, 0, 655384, 0, 0 )
_sections_unfolded = [ "Cell", "Material", "Transform", "Visibility" ]

[node name="Player" parent="." index="1" instance=ExtResource( 2 )]
Expand Down
Binary file added sprites/Door.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions sprites/Door.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/Door.png-ddeb0145a149080288083efa11e3e2d7.stex"

[deps]

source_file="res://sprites/Door.png"
dest_files=[ "res://.import/Door.png-ddeb0145a149080288083efa11e3e2d7.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

0 comments on commit cbf4bc3

Please sign in to comment.