Skip to content

Commit

Permalink
New rotation system semi
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariasteam committed Dec 29, 2018
1 parent f8f5aa0 commit f4adacf
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 101 deletions.
3 changes: 0 additions & 3 deletions .import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5

This file was deleted.

Binary file not shown.
11 changes: 2 additions & 9 deletions Scenes/Column.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ func _ready():
set_process(true)

func receive_input (rot):
return player._on_set_rotation (rot * 3)
return player._on_set_rotation (rot)

func lock_rot():
player.lock_rot()

func _process(delta):
if (Input.is_action_pressed("ui_left")):
player._on_set_rotation (-0.002)
elif (Input.is_action_pressed("ui_right")):
player._on_set_rotation (0.002)

player.lock_rot()
128 changes: 70 additions & 58 deletions Scenes/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ onready var acceleration_sound = get_node("AccelerationSound")

var colliding = false

var prev_frame_rotation = 0

var decal = preload("res://Scenes/decal.tscn")

onready var rotation = axis.get_rotation_deg()
onready var last_safe_rotation = axis.get_rotation()
onready var collision_rotation = axis.get_rotation()
onready var last_safe_rotation = axis.get_rotation().y

var counter = 0
var rotation_range = Vector2(0,0)
Expand Down Expand Up @@ -82,91 +82,103 @@ func block_camera():
func release_camera():
rigid_2.set_sleeping(false)

func on_platform_passed():
func on_platform_passed():
release_camera()
rigid_2.set_linear_velocity(rigid.get_linear_velocity())
rigid_2.set_linear_velocity(rigid.get_linear_velocity())

global.update_points((counter + 1) * 10)
global.update_progress()

if (counter == 1 and global.sound_enabled):
if (counter == 1 and global.sound_enabled):
acceleration_sound.play(1.5)

counter += 1
if (counter == n_platforms_to_meteorize - 1):
rigid.set_gravity_scale(0)

if (counter >= n_platforms_to_meteorize):
if (counter >= n_platforms_to_meteorize):
meteor_particles.set_emitting(true)
meteorize()


func lock_rot():
last_safe_rotation = axis.get_rotation_deg()
rotation = axis.get_rotation_deg()

func normalize_rot(rot):
var changed = true
while (changed):
changed = false
if (rot >= 360):
rot -= 360
changed = true
elif (rot < 0):
rot += 360
changed = true
func lock_rot():
last_safe_rotation = axis.get_rotation_deg().y

func normalize_rot(rot):
while (rot < 0):
rot += 360
while (rot > 360):
rot -= 360

return rot

func set_player_rotation (value):
axis.set_rotation_deg(Vector3(0,value,0))
camera_axis.set_rotation_deg(Vector3(0,value,0))


func is_in_range (v, r_a, r_b):
# Hay bloqueo
if (r_a - r_b > 40):
if (r_a < r_b):
return (v < r_a or v > r_b)
else:
return (v < r_b or v > r_a)
else:
if (r_a < r_b):
return (v > r_a and v < r_b)
else:
return (v > r_b and v < r_a)
return v > r_a and v < r_b


func _on_set_rotation (rot):
var intent_rotation = rot + last_safe_rotation
var current_rotation = axis.get_rotation_deg().y;

func _on_set_rotation (rot):
var intent_rotation = rot + last_safe_rotation.y
var rot_dir = axis.get_rotation_deg().y;
var has_collided = false
var is_left = true

if (movement_limited):
if (movement_limited):
# "Change basis" so first wall is at 180 degrees
var adjustment_offset = -rotation_range.x
var local_normalized_intent_rotation = normalize_rot(intent_rotation + adjustment_offset)
var local_current_rotation = normalize_rot(current_rotation + adjustment_offset)
var local_rotation_range = Vector2 (0, 0)

# "Change basis" so second wall is at 180 degrees
adjustment_offset = -rotation_range.y
var local_normalized_intent_rotation_2 = normalize_rot(intent_rotation + adjustment_offset)
var local_current_rotation_2 = normalize_rot(current_rotation + adjustment_offset)
var local_rotation_range_2 = Vector2(0, 0)

#print ("R ", local_rotation_range, " ", intent_rotation, " ", current_rotation)

if (intent_rotation > prev_frame_rotation):
is_left = false

# CASE IN BETWEEN
if (is_in_range(intent_rotation, rotation_range.x, rotation_range.y)):
var diff_a = abs(rot_dir - rotation_range.x)
var diff_b = abs(rot_dir - rotation_range.y)
if (is_in_range(local_current_rotation, local_rotation_range.x, local_rotation_range.y) and 100 < 8):
var diff_a = abs(local_current_rotation - local_rotation_range.x)
var diff_b = abs(local_current_rotation - local_rotation_range.y)

if (diff_a < diff_b):
intent_rotation = rotation_range.x
else:
intent_rotation = rotation_range.y


if (rotation_range.x < rotation_range.y):
# REGULAR CASE
if (rot_dir <= rotation_range.x and intent_rotation >= rotation_range.x): # PLAYER IS PRE WALL
return false;
elif (rot_dir >= rotation_range.y and intent_rotation <= rotation_range.y): # PLAYER IS POST WALL
return false;
else: # INVERTED CASE
var aux_norm = normalize_rot(intent_rotation)
if (rot_dir <= rotation_range.y and aux_norm <= rotation_range.y): # PLAYER IS POST WALL
return false;
elif (rot_dir <= rotation_range.x and intent_rotation >= rotation_range.x): # PLAYER IS PRE WALL
return false;


if (!is_left):
if (local_normalized_intent_rotation >= local_current_rotation and
local_normalized_intent_rotation < 360):
#print ("GOOD A")
pass
else:
print ("BAD A", rotation_range.x)
intent_rotation = rotation_range.x
has_collided = true
else:
if (local_normalized_intent_rotation_2 > 0 and
local_normalized_intent_rotation_2 <= local_current_rotation_2):
#print ("GOOD B")
pass
else:
print ("BAD B")
intent_rotation = rotation_range.y
has_collided = true

#print ("moviendo a ", intent_rotation, " desde ", current_rotation)

prev_frame_rotation = intent_rotation
set_player_rotation(normalize_rot(intent_rotation))
return true
return !has_collided

func end_animation():
ball.queue_free()
Expand Down Expand Up @@ -238,9 +250,9 @@ func meteorize():
func _on_Timer_timeout():
global.handle_lose()

func _on_Area_body_exit( body ):
func _on_Area_body_exit( body ):
colliding = false

func _on_Area_area_enter( area ):
func _on_Area_area_enter( area ):
if (area.is_in_group("deleter") and !meteor):
block_camera()
4 changes: 2 additions & 2 deletions Scenes/Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ input/ray_pickable = false
input/capture_on_drag = false
shape_count = 1
shapes/0/shape = SubResource( 2 )
shapes/0/transform = Transform( 0.019017, 0, 0, 0, 0.019017, 0, 0, 0, 0.019017, 0, -0.594566, -0.108771 )
shapes/0/transform = Transform( 0.019017, 0, 0, 0, 0.019017, 0, 0, 0, 0.019017, 0, -0.571903, -0.108771 )
shapes/0/trigger = true
space_override = 0
gravity_point = false
Expand All @@ -573,7 +573,7 @@ collision/mask = 3
[node name="CollisionShape" type="CollisionShape" parent="RigidBody/Axis/Group/Area"]

_import_transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
transform/local = Transform( 0.019017, 0, 0, 0, 0.019017, 0, 0, 0, 0.019017, 0, -0.594566, -0.108771 )
transform/local = Transform( 0.019017, 0, 0, 0, 0.019017, 0, 0, 0, 0.019017, 0, -0.571903, -0.108771 )
shape = SubResource( 2 )
trigger = true
_update_shape_index = 0
Expand Down
18 changes: 9 additions & 9 deletions Scenes/decal.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
extends Quad

# class member variables go here, for example:
# var a = 2
# var b = "textvar"
onready var color = Color (get_tree().get_nodes_in_group("player")[0].color)

func _ready():
var color = get_tree().get_nodes_in_group("player")[0].color
func _ready():
var mat = get_material_override().duplicate()
set_material_override(mat)
get_material_override().set_parameter(FixedMaterial.PARAM_DIFFUSE, color)
pass


func _on_Timer_timeout():
queue_free()
func _on_OpacityTimer_timeout():
if (color.a <= 0):
queue_free()
color.a -= 0.001
get_material_override().set_parameter(FixedMaterial.PARAM_DIFFUSE, color)
8 changes: 4 additions & 4 deletions Scenes/decal.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ quad/offset = Vector2( 0, 0 )
quad/centered = true
script/script = ExtResource( 2 )

[node name="Timer" type="Timer" parent="."]
[node name="OpacityTimer" type="Timer" parent="."]

process_mode = 1
wait_time = 10.0
one_shot = true
wait_time = 0.01
one_shot = false
autostart = true

[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
[connection signal="timeout" from="OpacityTimer" to="." method="_on_OpacityTimer_timeout"]


2 changes: 1 addition & 1 deletion Scenes/platform.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func _ready():

for i in range(0, 14):
var aux = null
var rand = (randi()%20+1)
var rand = (randi()% 20+1)
var rot = ((offset * i) + angle_offset) + 7

if (rand >= 17):
Expand Down
1 change: 1 addition & 0 deletions engine.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ motion_fix_enabled=true

[rasterizer]

low_memory_2d_mode=true
anisotropic_filter_level=2.0
shadow_filter=1

Expand Down
4 changes: 2 additions & 2 deletions export.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ architecture/x86=false
command_line/extra_args=""
custom_package/debug=""
custom_package/release=""
debug/debugging_enabled=false
debug/debugging_enabled=true
keystore/release=""
keystore/release_password=""
keystore/release_user=""
one_click_deploy/clear_previous_install=true
package/icon="res://icon.png"
package/name="TowerJumper"
package/signed=false
package/signed=true
package/unique_name="org.pipoypipagames.towerjumper"
permissions/access_checkin_properties=false
permissions/access_coarse_location=false
Expand Down
24 changes: 11 additions & 13 deletions input_handler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,29 @@ var touchs_vec = {}

func _ready():
get_node("LevelLabel").set_text("Level " + str(global.level))
set_process_input(true)
set_process_input(true)

func handle_pos (pos):
if (!game.receive_input (pos)):
last_pos = get_local_mouse_pos().x
game.lock_rot();

func _input(event):
if (event.type==InputEvent.SCREEN_TOUCH):
if (!game.receive_input (pos)):
game.lock_rot();
last_pos = get_local_mouse_pos().x
func _input(event):
if (event.type==InputEvent.SCREEN_TOUCH):
if (event.pressed):
touchs_vec[event.index] = event.pos.x
if (touchs_vec.size() == 1):
last_pos = event.pos.x
game.lock_rot();

else:
touchs_vec.erase(event.index)
if (touchs_vec.size() == 1):
last_pos = touchs_vec.values()[0]
game.lock_rot();

elif (event.type==InputEvent.SCREEN_DRAG):
touchs_vec[event.index] = event.pos.x
var a = event.pos.x
if (touchs_vec.size() == 1):
handle_pos (float(-(event.pos.x - last_pos) * 100) / width)
else:
touchs_vec[event.index] = event.pos.x



handle_pos (stepify(((-(event.pos.x - last_pos) * 300) / width), 0.01))

0 comments on commit f4adacf

Please sign in to comment.