From 36b60e3b1e92389dafc31c5291df4674fa56bb30 Mon Sep 17 00:00:00 2001 From: Seth Taylor Date: Tue, 2 Apr 2019 13:50:33 -0700 Subject: [PATCH] updated to use Godot 3.1 --- .gitignore | 2 + GameScene.tscn | 57 +++------ engine.cfg | 23 ---- project.godot | 44 +++++++ scene/bubbleEffect.tscn | 28 ++--- scene/explode_star.tscn | 55 ++++----- scene/gradient_White_trans.tres | 5 + scene/tail.tscn | 44 +++---- scripts/GameLayer.gd | 204 +++++++++++++++++--------------- scripts/GameScene.gd | 4 +- scripts/gameLevel.gd | 60 +++++----- scripts/global.gd | 3 +- scripts/parentNode2D.gd | 2 +- 13 files changed, 267 insertions(+), 264 deletions(-) create mode 100644 .gitignore delete mode 100644 engine.cfg create mode 100644 project.godot create mode 100644 scene/gradient_White_trans.tres diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f8f9f93 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.import +*.import diff --git a/GameScene.tscn b/GameScene.tscn index cb0d259..a049691 100644 --- a/GameScene.tscn +++ b/GameScene.tscn @@ -1,61 +1,40 @@ -[gd_scene load_steps=6 format=1] +[gd_scene load_steps=5 format=2] [ext_resource path="res://scripts/parentNode2D.gd" type="Script" id=1] -[ext_resource path="res://textures/Background@2x.png" type="Texture" id=2] -[ext_resource path="res://scripts/GameScene.gd" type="Script" id=3] +[ext_resource path="res://scripts/GameScene.gd" type="Script" id=2] +[ext_resource path="res://textures/Background@2x.png" type="Texture" id=3] [ext_resource path="res://scripts/GameLayer.gd" type="Script" id=4] -[ext_resource path="res://Fonts/foo_shadow_34.fnt" type="BitmapFont" id=5] [node name="ParentNode2D" type="Node"] - -script/script = ExtResource( 1 ) +script = ExtResource( 1 ) __meta__ = { "_edit_lock_": true } -background = ExtResource( 2 ) - -[node name="Background" type="TextureFrame" parent="."] - -focus/ignore_mouse = true -focus/stop_mouse = true -size_flags/horizontal = 2 -size_flags/vertical = 2 -margin/left = -20.0 -margin/top = -56.0 -margin/right = 620.0 -margin/bottom = 1080.0 -texture = ExtResource( 2 ) -stretch_mode = 0 [node name="GameScene" type="Node2D" parent="."] +position = Vector2( 280, 360 ) +script = ExtResource( 2 ) -script/script = ExtResource( 3 ) -jsonFile = "res://Level/Level_1.json" +[node name="Sprite" type="Sprite" parent="GameScene"] +texture = ExtResource( 3 ) [node name="GameLayer" type="Node2D" parent="GameScene"] - -transform/pos = Vector2( 300, 512 ) -script/script = ExtResource( 4 ) +script = ExtResource( 4 ) [node name="TilesLayer" type="Node2D" parent="GameScene/GameLayer"] [node name="CookiesLayer" type="Node2D" parent="GameScene/GameLayer"] [node name="Shuffle" type="Button" parent="GameScene"] - -focus/ignore_mouse = false -focus/stop_mouse = true -size_flags/horizontal = 2 -size_flags/vertical = 2 -margin/left = 202.0 -margin/top = 960.0 -margin/right = 414.0 -margin/bottom = 1016.0 -custom_fonts/font = ExtResource( 5 ) -toggle_mode = false +margin_left = -60.0 +margin_top = 400.0 +margin_right = 60.0 +margin_bottom = 438.0 +rect_min_size = Vector2( 120, 40 ) +hint_tooltip = "Shuffles all pastries on the game board" +focus_mode = 0 +mouse_default_cursor_shape = 2 +custom_colors/font_color_pressed = Color( 0, 0, 0, 1 ) enabled_focus_mode = 0 -shortcut = null text = "Shuffle" -flat = false - diff --git a/engine.cfg b/engine.cfg deleted file mode 100644 index ae7fd6c..0000000 --- a/engine.cfg +++ /dev/null @@ -1,23 +0,0 @@ -[application] - -name="Happy smash" -main_scene="res://GameScene.tscn" -boot_splash="res://splash.png" -icon="res://icon.png" - -[autoload] - -mainRes="*res://scripts/preloadResources.gd" -global="*res://scripts/global.gd" - -[display] - -borderless_window=false -height=1028 -test_height=514 -width=600 -test_width=300 -stretch_mode="2d" -resizable=true -stretch_aspect="keep" -orientation="portrait" diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..95e33e4 --- /dev/null +++ b/project.godot @@ -0,0 +1,44 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=4 + +_global_script_classes=[ ] +_global_script_class_icons={ + +} + +[application] + +config/name="happy crush" +run/main_scene="res://GameScene.tscn" +name="Happy smash" +main_scene="res://GameScene.tscn" +boot_splash="res://splash.png" +icon="res://icon.png" + +[autoload] + +mainRes="*res://scripts/preloadResources.gd" +global="*res://scripts/global.gd" + +[display] + +window/size/width=560 +window/size/height=880 +window/size/resizable=false +window/handheld/orientation="portrait" +borderless_window=false +height=1028 +test_height=514 +width=600 +test_width=300 +stretch_mode="2d" +resizable=true +stretch_aspect="keep" +orientation="portrait" diff --git a/scene/bubbleEffect.tscn b/scene/bubbleEffect.tscn index 068297c..4d18fcf 100644 --- a/scene/bubbleEffect.tscn +++ b/scene/bubbleEffect.tscn @@ -1,33 +1,27 @@ -[gd_scene load_steps=3 format=1] +[gd_scene load_steps=3 format=2] -[ext_resource path="res://FX/player_shield.png" type="Texture" id=1] +[ext_resource path="res://FX/bubble.png" type="Texture" id=1] [sub_resource type="Animation" id=1] - -resource/name = "scaleUpDown" length = 0.4 loop = true -step = 0.1 tracks/0/type = "value" tracks/0/path = NodePath(".:transform/scale") tracks/0/interp = 1 +tracks/0/loop_wrap = true tracks/0/imported = false -tracks/0/keys = { "times":FloatArray( 0, 0.2, 0.4 ), "transitions":FloatArray( 1, 1, 1 ), "update":0, "values":[ Vector2( 0.8, 0.8 ), Vector2( 1, 1 ), Vector2( 0.8, 0.8 ) ] } +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 0.2, 0.4 ), +"transitions": PoolRealArray( 1, 1, 1 ), +"update": 0, +"values": [ Vector2( 0.8, 0.8 ), Vector2( 1, 1 ), Vector2( 0.8, 0.8 ) ] +} [node name="AnimatedSprite" type="Sprite"] - -transform/scale = Vector2( 0.8, 0.8 ) texture = ExtResource( 1 ) [node name="AnimationPlayer" type="AnimationPlayer" parent="."] - -playback/process_mode = 1 -playback/default_blend_time = 0.0 -root/root = NodePath("..") -anims/scaleUpDown = SubResource( 1 ) -playback/active = true -playback/speed = 1.0 -blend_times = [ ] autoplay = "scaleUpDown" - +anims/scaleUpDown = SubResource( 1 ) diff --git a/scene/explode_star.tscn b/scene/explode_star.tscn index 5bb6498..b211596 100644 --- a/scene/explode_star.tscn +++ b/scene/explode_star.tscn @@ -1,37 +1,32 @@ -[gd_scene load_steps=3 format=1] +[gd_scene load_steps=5 format=2] [ext_resource path="res://FX/star_particle01_16.png" type="Texture" id=1] -[sub_resource type="ColorRamp" id=1] +[sub_resource type="Curve" id=1] +_data = [ Vector2( 0.0105601, 0.672666 ), 0.0, 0.0, 0, 0, Vector2( 1, 0.118266 ), 0.0, 0.0, 0, 0 ] -offsets = FloatArray( 0, 1 ) -colors = ColorArray( 1, 1, 1, 1, 1, 1, 1, 0 ) +[sub_resource type="CurveTexture" id=2] +curve = SubResource( 1 ) -[node name="Particles2D" type="Particles2D"] - -config/amount = 8 -config/lifetime = 1.5 -config/preprocess = 0.001 -config/explosiveness = 0.1 -config/texture = ExtResource( 1 ) -params/direction = 180.0 -params/spread = 180.0 -params/linear_velocity = 50.0 -params/spin_velocity = 50.0 -params/orbit_velocity = 0.0 -params/gravity_direction = 0.0 -params/gravity_strength = 0.0 -params/radial_accel = 10.0 -params/tangential_accel = 10.0 -params/damping = 45.0 -params/initial_angle = 0.0 -params/initial_size = 0.6 -params/final_size = 0.2 -params/hue_variation = 0.0 -params/anim_speed_scale = 1.0 -params/anim_initial_pos = 1.0 -randomness/linear_velocity = 0.2 -randomness/spin_velocity = 0.5 -color/color_ramp = SubResource( 1 ) +[sub_resource type="ParticlesMaterial" id=3] +flag_disable_z = true +spread = 180.0 +gravity = Vector3( 0, 0, 0 ) +initial_velocity = 50.0 +angular_velocity = 50.0 +angular_velocity_random = 0.5 +orbit_velocity = 0.0 +orbit_velocity_random = 0.0 +radial_accel = 10.0 +tangential_accel = 10.0 +damping = 45.0 +angle = 180.0 +scale_curve = SubResource( 2 ) +[node name="Particles2D" type="Particles2D"] +lifetime = 1.5 +explosiveness = 0.1 +randomness = 0.5 +process_material = SubResource( 3 ) +texture = ExtResource( 1 ) diff --git a/scene/gradient_White_trans.tres b/scene/gradient_White_trans.tres new file mode 100644 index 0000000..188cbe0 --- /dev/null +++ b/scene/gradient_White_trans.tres @@ -0,0 +1,5 @@ +[gd_resource type="Gradient" format=2] + +[resource] +colors = PoolColorArray( 1, 1, 1, 1, 1, 1, 1, 0 ) + diff --git a/scene/tail.tscn b/scene/tail.tscn index 49764b0..d0b7c68 100644 --- a/scene/tail.tscn +++ b/scene/tail.tscn @@ -1,31 +1,25 @@ -[gd_scene load_steps=3 format=1] +[gd_scene load_steps=5 format=2] [ext_resource path="res://FX/snow-ball-white.png" type="Texture" id=1] -[ext_resource path="res://scene/colorRamp_White_trans.tres" type="ColorRamp" id=2] -[node name="Particles2D" type="Particles2D"] +[sub_resource type="Curve" id=1] +_data = [ Vector2( 0, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0.0733891 ), -2.13179, 0.0, 0, 0 ] + +[sub_resource type="CurveTexture" id=2] +curve = SubResource( 1 ) -visibility/blend_mode = 1 -transform/scale = Vector2( 1, 1.02251 ) -config/amount = 32 -config/lifetime = 2.0 -config/texture = ExtResource( 1 ) -params/direction = 90.0 -params/spread = 0.0 -params/linear_velocity = 30.0 -params/spin_velocity = 0.0 -params/orbit_velocity = 0.0 -params/gravity_direction = 0.0 -params/gravity_strength = 0.0 -params/radial_accel = 0.0 -params/tangential_accel = 0.0 -params/damping = 0.0 -params/initial_angle = 0.0 -params/initial_size = 1.0 -params/final_size = 0.2 -params/hue_variation = 0.0 -params/anim_speed_scale = 1.0 -params/anim_initial_pos = 0.0 -color/color_ramp = ExtResource( 2 ) +[sub_resource type="ParticlesMaterial" id=3] +flag_disable_z = true +gravity = Vector3( 0, 98, 0 ) +initial_velocity = 30.0 +orbit_velocity = 0.0 +orbit_velocity_random = 0.0 +angle = 90.0 +scale_curve = SubResource( 2 ) +[node name="Particles2D" type="Particles2D"] +amount = 32 +lifetime = 2.0 +process_material = SubResource( 3 ) +texture = ExtResource( 1 ) diff --git a/scripts/GameLayer.gd b/scripts/GameLayer.gd index 5bcd28c..9f9457d 100644 --- a/scripts/GameLayer.gd +++ b/scripts/GameLayer.gd @@ -1,7 +1,7 @@ extends Node2D var level -var swap +#var swap var cookiesLayer var tilesLayer @@ -35,10 +35,10 @@ func _enter_tree(): add_child(level, true) tilesLayer = get_node("TilesLayer") - tilesLayer.set_pos(getLayerPos()) + tilesLayer.position = getLayerPos() cookiesLayer = get_node("CookiesLayer") - cookiesLayer.set_pos(getLayerPos()) + cookiesLayer.position = getLayerPos() func removeAllCookies(): for child in cookiesLayer.get_children(): @@ -73,13 +73,13 @@ func preloadResources(): sounds["fallingCookies"]= "Drip" func addTiles(): - for row in range(-1, global.NumRows, 1): - for column in range(global.NumColumns): - if row >= 0 && level.tileAt(column, row) == null: - level.createLighMaskAt(pointFor(column, row), tilesLayer) - elif row == -1 && level.tileAt(column, row) != null: - level.createLighMaskAt(pointFor(column, row), tilesLayer) - + #for row in range(-1, global.NumRows, 1): + # for column in range(global.NumColumns): + # if row >= 0 && level.tileAt(column, row) == null: + # level.createLighMaskAt(pointFor(column, row), tilesLayer) + # elif row == -1 && level.tileAt(column, row) != null: + # level.createLighMaskAt(pointFor(column, row), tilesLayer) + # for row in range(global.NumRows, -1, -1): for column in range(global.NumColumns+1): var topLeft = (column > 0 && row < global.NumRows && level.tileAt(column-1, row)) @@ -97,7 +97,7 @@ func addTiles(): var sprite = Sprite.new() var texture = ResourceLoader.load(path) sprite.set_texture(texture) - sprite.set_pos(pos) + sprite.position = pos tilesLayer.add_child(sprite) @@ -108,21 +108,27 @@ func addSpritesFor(cookies): for cookie in cookies: var sprite = Sprite.new() var tex = cookiesList[int(cookie.cookieType-1)] - sprite.set_z(10) - sprite.set_light_mask(8) - sprite.set_texture(tex) - sprite.set_pos(pointFor(cookie.column, cookie.row)) + sprite.z_index = 10 + sprite.light_mask = 8 + sprite.texture = tex + sprite.position = pointFor(cookie.column, cookie.row) cookiesLayer.add_child(sprite) cookie.sprite = sprite - cookie.sprite.set_opacity(0) - cookie.sprite.set_scale(Vector2(0.5, 0.5)) + cookie.sprite.modulate.a = 1 + cookie.sprite.scale = Vector2(0.5, 0.5) var delay = rand_range(0.25, 0.5) - tween.interpolate_method(cookie.sprite, "set_opacity", 0.0, 1.0, 0.25, Tween.TRANS_LINEAR, \ + tween.interpolate_property(cookie.sprite, "modulate:a", 0.0, 1.0, 0.25, Tween.TRANS_LINEAR, \ Tween.EASE_OUT, delay) - tween.interpolate_method(cookie.sprite, "set_scale", Vector2(0.5, 0.5), Vector2(1.0, 1.0), \ + tween.interpolate_property(cookie.sprite, "scale", Vector2(0.5, 0.5), Vector2(1.0, 1.0), \ 0.25, Tween.TRANS_LINEAR, Tween.EASE_OUT, delay) + + # old 2.0 code + #tween.interpolate_method(cookie.sprite, "set_opacity", 0.0, 1.0, 0.25, Tween.TRANS_LINEAR, \ + #Tween.EASE_OUT, delay) + #tween.interpolate_method(cookie.sprite, "set_scale", Vector2(0.5, 0.5), Vector2(1.0, 1.0), \ + #0.25, Tween.TRANS_LINEAR, Tween.EASE_OUT, delay) tween.interpolate_callback(self, tween.get_runtime(), "removeNode", tween) tween.start() @@ -218,29 +224,29 @@ func animateInvalidSwap(swap): setUserInteraction(true); return - swap.cookieA.sprite.set_z(100) - swap.cookieB.sprite.set_z(90) + swap.cookieA.sprite.z_index = 100 + swap.cookieB.sprite.z_index = 90 var tween = Tween.new() add_child(tween) - #var cookieAPos = swap.cookieA.sprite.get_pos() - #var cookieBPos = swap.cookieB.sprite.get_pos() + #var cookieAPos = swap.cookieA.sprite.position + #var cookieBPos = swap.cookieB.sprite.position var cookieAPos = pointFor(swap.cookieA.column, swap.cookieA.row) var cookieBPos = pointFor(swap.cookieB.column, swap.cookieB.row) var duration = 0.3 - var property = "transform/pos" + #var property = "transform/pos" var bubbleA = Sprite.new() - bubbleA.set_texture(mainRes.bubble) - bubbleA.set_scale(Vector2(1, 1)) - bubbleA.set_pos(swap.cookieA.sprite.get_pos()) + bubbleA.texture = mainRes.bubble + bubbleA.scale = Vector2(1, 1) + bubbleA.position = swap.cookieA.sprite.position var bubbleB = Sprite.new() - bubbleB.set_texture(mainRes.bubble) - bubbleB.set_scale(Vector2(1, 1)) - bubbleB.set_pos(swap.cookieB.sprite.get_pos()) + bubbleB.texture = mainRes.bubble + bubbleB.scale = Vector2(1, 1) + bubbleB.position = swap.cookieB.sprite.position cookiesLayer.add_child(bubbleA) cookiesLayer.add_child(bubbleB) @@ -251,39 +257,37 @@ func animateInvalidSwap(swap): Tween.TRANS_LINEAR, Tween.EASE_OUT) tween.interpolate_callback(self, tween.get_runtime(), "removeNode", bubbleA, bubbleB) - tween.interpolate_method(swap.cookieA.sprite, "set_pos", cookieAPos, cookieBPos, duration,\ + tween.interpolate_method(swap.cookieA.sprite, "set_position", cookieAPos, cookieBPos, duration,\ Tween.TRANS_LINEAR, Tween.EASE_OUT) - tween.interpolate_method(swap.cookieB.sprite, "set_pos", cookieBPos, cookieAPos, duration,\ + tween.interpolate_method(swap.cookieB.sprite, "set_position", cookieBPos, cookieAPos, duration,\ Tween.TRANS_LINEAR, Tween.EASE_OUT) - tween.interpolate_method(swap.cookieA.sprite, "set_pos", cookieBPos, cookieAPos, duration,\ + tween.interpolate_method(swap.cookieA.sprite, "set_position", cookieBPos, cookieAPos, duration,\ Tween.TRANS_LINEAR, Tween.EASE_OUT, duration) - tween.interpolate_method(swap.cookieB.sprite, "set_pos", cookieAPos, cookieBPos, duration,\ + tween.interpolate_method(swap.cookieB.sprite, "set_position", cookieAPos, cookieBPos, duration,\ Tween.TRANS_LINEAR, Tween.EASE_OUT, duration) tween.interpolate_callback(self, tween.get_runtime(), "completeSwap", tween, swap.cookieA.sprite, true) tween.start() pass func animateSwap(swap): - swap.cookieA.sprite.set_z(100) - swap.cookieB.sprite.set_z(90) + swap.cookieA.sprite.z_index = 100 + swap.cookieB.sprite.z_index = 90 - var cookieAPos = swap.cookieA.sprite.get_pos() - var cookieBPos = swap.cookieB.sprite.get_pos() + var cookieAPos = swap.cookieA.sprite.position + var cookieBPos = swap.cookieB.sprite.position var tween = Tween.new() add_child(tween) - var duration = 0.3 - var property = "transform/pos" - + var duration = 0.3 var bubbleA = Sprite.new() - bubbleA.set_texture(mainRes.bubble) - bubbleA.set_scale(Vector2(1, 1)) - bubbleA.set_pos(swap.cookieA.sprite.get_pos()) + bubbleA.texture = mainRes.bubble + bubbleA.scale = Vector2(1, 1) + bubbleA.position = swap.cookieA.sprite.position var bubbleB = Sprite.new() - bubbleB.set_texture(mainRes.bubble) - bubbleB.set_scale(Vector2(1, 1)) - bubbleB.set_pos(swap.cookieB.sprite.get_pos()) + bubbleB.texture = mainRes.bubble + bubbleB.scale = Vector2(1, 1) + bubbleB.position = swap.cookieB.sprite.position cookiesLayer.add_child(bubbleA) cookiesLayer.add_child(bubbleB) @@ -294,9 +298,9 @@ func animateSwap(swap): Tween.TRANS_LINEAR, Tween.EASE_OUT) tween.interpolate_callback(self, tween.get_runtime(), "removeNode", bubbleA, bubbleB) - var moveA = tween.interpolate_property(swap.cookieA.sprite, property, cookieAPos, cookieBPos, \ + var moveA = tween.interpolate_property(swap.cookieA.sprite, "position", cookieAPos, cookieBPos, \ duration, Tween.TRANS_LINEAR, Tween.EASE_OUT) - var moveB = tween.interpolate_property(swap.cookieB.sprite, property, cookieBPos, cookieAPos, \ + var moveB = tween.interpolate_property(swap.cookieB.sprite, "position", cookieBPos, cookieAPos, \ duration, Tween.TRANS_LINEAR, Tween.EASE_OUT) tween.interpolate_callback(self, tween.get_runtime(), "completeSwap", tween, swap.cookieA) @@ -304,7 +308,6 @@ func animateSwap(swap): pass func animateMatched(chains): - var property = "transform/scale" var tween = Tween.new() add_child(tween) @@ -316,15 +319,15 @@ func animateMatched(chains): add_child(expTween) var expA = mainRes.starExp.instance() - expA.set_lifetime(1.0) - expA.set_emitting(true) - expA.set_emit_timeout(0.8) - expA.set_pos(cookie.sprite.get_pos()) + expA.lifetime = 1.0 + expA.emitting = true + #expA.lifetime = 1 + expA.position = cookie.sprite.position var bubbleA = Sprite.new() - bubbleA.set_texture(mainRes.bubble) - bubbleA.set_scale(Vector2(0.4, 0.4)) - bubbleA.set_pos(cookie.sprite.get_pos()) + bubbleA.texture = mainRes.bubble + bubbleA.scale = Vector2(0.4, 0.4) + bubbleA.position = cookie.sprite.position cookiesLayer.add_child(bubbleA) cookiesLayer.add_child(expA) @@ -332,14 +335,22 @@ func animateMatched(chains): tween.interpolate_method(bubbleA, "set_scale", bubbleA.get_scale(), Vector2(1.0, 1.0), \ 0.3, Tween.TRANS_LINEAR, Tween.EASE_OUT) - tween.interpolate_property(cookie.sprite, property, cookie.sprite.get_scale(), \ + tween.interpolate_property(cookie.sprite, "position", cookie.sprite.get_scale(), \ Vector2(0.1, 0.1), 0.3, Tween.TRANS_LINEAR, Tween.EASE_OUT) - tween.interpolate_method(cookie.sprite, "set_opacity", cookie.sprite.get_opacity(), \ + tween.interpolate_property(cookie.sprite, "modulate:a", cookie.sprite.modulate.a, \ 0.3, 0.3, Tween.TRANS_LINEAR, Tween.EASE_OUT) + + # old 2.0 code + #tween.interpolate_method(cookie.sprite, "set_opacity", cookie.sprite.get_opacity(), \ + #0.3, 0.3, Tween.TRANS_LINEAR, Tween.EASE_OUT) tween.interpolate_callback(self, tween.get_runtime(), "removeNode", cookie.sprite, bubbleA) - expTween.interpolate_method(expA, "set_opacity", expA.get_opacity(), \ + expTween.interpolate_property(expA, "modulate:a", expA.modulate.a, \ 0.0, 0.5, Tween.TRANS_LINEAR, Tween.EASE_OUT, 0.3) + + # old 2.0 code + #expTween.interpolate_method(expA, "set_opacity", expA.get_opacity(), \ + #0.0, 0.5, Tween.TRANS_LINEAR, Tween.EASE_OUT, 0.3) expTween.interpolate_callback(self, expTween.get_runtime(), "removeNode", expA, expTween) expTween.start() @@ -350,7 +361,6 @@ func animateMatched(chains): pass func animateFallingCookies(columns): - var property = "transform/pos" var tween = Tween.new() add_child(tween) @@ -358,25 +368,23 @@ func animateFallingCookies(columns): var idx = 0 for cookie in array: var newPosition = pointFor(cookie.column, cookie.row) - var newPosition1 = Vector2(newPosition.x, newPosition.y-3) + var newPosition1 = Vector2(newPosition.x, newPosition.y - 3) - var delay = (0.05 + idx/10.0) * 0.1 - var duration = ((newPosition.y - cookie.sprite.get_pos().y) / global.TILE_HEIGHT) * 0.1 + var delay = (0.05 + idx / 10.0) * 0.1 + var duration = ((newPosition.y - cookie.sprite.position.y) / global.TILE_HEIGHT) * 0.1 - tween.interpolate_property(cookie.sprite, property, cookie.sprite.get_pos(), \ + tween.interpolate_property(cookie.sprite, "position", cookie.sprite.position, \ newPosition, duration, Tween.TRANS_LINEAR, Tween.EASE_OUT, delay) - tween.interpolate_property(cookie.sprite, property, newPosition, newPosition1, \ - 0.1, Tween.TRANS_LINEAR, Tween.EASE_OUT, duration+delay) - tween.interpolate_property(cookie.sprite, property, newPosition1, newPosition, \ - 0.1, Tween.TRANS_LINEAR, Tween.EASE_OUT, duration+delay+0.1) + tween.interpolate_property(cookie.sprite, "position", newPosition, newPosition1, \ + 0.1, Tween.TRANS_LINEAR, Tween.EASE_OUT, duration + delay) + tween.interpolate_property(cookie.sprite, "position", newPosition1, newPosition, \ + 0.1, Tween.TRANS_LINEAR, Tween.EASE_OUT, duration + delay + 0.1) idx += 1 tween.interpolate_callback(self, tween.get_runtime(), "completeFalling", tween) tween.start() func animateNewCookies(columns): - var property = "transform/pos" - var tween = Tween.new() add_child(tween) @@ -386,9 +394,9 @@ func animateNewCookies(columns): array.invert() for cookie in array: var sprite = Sprite.new() - sprite.set_texture(cookiesList[cookie.cookieType-1]) - sprite.set_pos(pointFor(cookie.column, startRow)) - sprite.set_light_mask(global.TILE_MASK) + sprite.texture = cookiesList[cookie.cookieType-1] + sprite.position = pointFor(cookie.column, startRow) + sprite.light_mask = global.TILE_MASK cookiesLayer.add_child(sprite) cookie.sprite = sprite @@ -397,12 +405,12 @@ func animateNewCookies(columns): var delay = (0.05 + (idx/10.0)) var duration = ((cookie.row - startRow) * 0.1) - tween.interpolate_property(cookie.sprite, property, cookie.sprite.get_pos(), \ + tween.interpolate_property(cookie.sprite, "position", cookie.sprite.position, \ newPosition, duration, Tween.TRANS_LINEAR, Tween.EASE_OUT, delay) - tween.interpolate_property(cookie.sprite, property, newPosition, newPosition1, \ + tween.interpolate_property(cookie.sprite, "position", newPosition, newPosition1, \ 0.1, Tween.TRANS_LINEAR, Tween.EASE_OUT, duration+delay) - tween.interpolate_property(cookie.sprite, property, newPosition1, newPosition, \ - 0.1, Tween.TRANS_LINEAR, Tween.EASE_OUT, duration+delay+0.1) + tween.interpolate_property(cookie.sprite, "position", newPosition1, newPosition, \ + 0.1, Tween.TRANS_LINEAR, Tween.EASE_OUT, duration + delay + 0.1) idx += 1 tween.interpolate_callback(self, tween.get_runtime(), "completeAddCookie", tween) @@ -425,25 +433,25 @@ func animateScoreForChain(chain): var cPos = pointFor(column, row) var node = Node2D.new() - node.set_name("ScoreLabelNode") - node.set_pos(cPos) - node.set_z(300) + node.name = "ScoreLabelNode" + node.position = cPos + node.z_index = 300 var scoreLabel = Label.new() scoreLabel.set("custom_fonts/font", preload("res://Fonts/foo_shadow_34.fnt")) scoreLabel.set("custom_colors/font_color", Color8(225, 80.68, 80.68)) - scoreLabel.set_text(str(chain.score)) + scoreLabel.text = str(chain.score) var size = scoreLabel.get_combined_minimum_size() - scoreLabel.set_pos(Vector2(0.0-size.width/2, 0.0-size.height/2)) + scoreLabel.rect_position = Vector2(0.0 - size.x / 2, 0.0 - size.y / 2) - node.set_scale(Vector2(0.8, 0.8)) + node.scale = Vector2(0.8, 0.8) node.add_child(scoreLabel) cookiesLayer.add_child(node) tween.interpolate_method(node, "set_scale", Vector2(0.8, 0.8), Vector2(1.0, 1.0), 0.2, \ Tween.TRANS_LINEAR, Tween.EASE_OUT) - tween.interpolate_method(node, "set_pos", cPos, Vector2(cPos.x, cPos.y-6), 0.7, \ + tween.interpolate_method(node, "set_position", cPos, Vector2(cPos.x, cPos.y-6), 0.7, \ Tween.TRANS_LINEAR, Tween.EASE_OUT) tween.interpolate_method(node, "set_opacity", 1.0, 0.3, 0.3, Tween.TRANS_LINEAR, Tween.EASE_OUT, \ tween.get_runtime()) @@ -454,15 +462,15 @@ func animateBeginEndGame(end = false): var tween = Tween.new() add_child(tween) - var cPos = get_pos() - var pos = Vector2(get_pos().x + (global.NumColumns*global.TILE_WIDTH)*2, get_pos().y) + var cPos = position + var pos = Vector2(position.x + (global.NumColumns*global.TILE_WIDTH)*2, position.y) if end: cPos = pos - pos = get_pos() - else: set_pos(pos) + pos = position + else: position = pos - tween.interpolate_method(self, "set_pos", pos, cPos, 1.0, Tween.TRANS_BACK, \ + tween.interpolate_method(self, "set_position", pos, cPos, 1.0, Tween.TRANS_BACK, \ (Tween.EASE_OUT if not end else Tween.EASE_IN)) tween.interpolate_callback(self, tween.get_runtime(), "removeNode", tween) tween.start() @@ -481,22 +489,22 @@ var touchStartPos var touchCurrentPos func _input(event): - if event.type == InputEvent.MOUSE_BUTTON and event.button_index == BUTTON_LEFT and event.is_pressed(): + if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.is_pressed(): touchStared = true touchBegin(event) - if event.type == InputEvent.MOUSE_BUTTON and event.button_index == BUTTON_LEFT and not event.is_pressed(): + if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and not event.is_pressed(): touchStared = false touchEnded(event) - if event.type == InputEvent.MOUSE_MOTION: + if event is InputEventMouseMotion: if touchStared: touchMoved(event) - if event.type == InputEvent.SCREEN_TOUCH and event.is_pressed(): + if event is InputEventScreenTouch and event.is_pressed(): touchStared = true touchBegin(event) - if event.type == InputEvent.SCREEN_TOUCH and not event.is_pressed(): + if event is InputEventScreenTouch and not event.is_pressed(): touchStared = false touchEnded(event) - if event.type == InputEvent.SCREEN_DRAG and event.is_pressed(): + if event is InputEventScreenDrag and event.is_pressed(): if touchStared: touchMoved(event) var touchInColumn1 @@ -504,7 +512,7 @@ var touchInRow1 func touchBegin(event): if not userInteractionEnabled: return - var location = event.pos - cookiesLayer.get_global_pos() + var location = event.position - cookiesLayer.global_position if convertPoint(location): var cookie = level.cookieAt(touchInColumn1, touchInRow1) @@ -536,7 +544,7 @@ func touchMoved(event): if not userInteractionEnabled: return if swipeFromColumn == null: return - var location = event.pos - cookiesLayer.get_global_pos() + var location = event.position - cookiesLayer.global_position if convertPoint(location, false): var horzDelte = 0 diff --git a/scripts/GameScene.gd b/scripts/GameScene.gd index 1afe2a7..a3e0aa1 100644 --- a/scripts/GameScene.gd +++ b/scripts/GameScene.gd @@ -7,10 +7,10 @@ func set_jsonfile(value): global.jsonLevelFile = jsonFile func _enter_tree(): - jsonFile = "res://Level/Level_1.json" + set_jsonfile("res://Level/Level_1.json") func _ready(): - var winSize = get_parent().get_VisibleSize() + #var winSize = get_parent().get_VisibleSize() get_node("GameLayer").addTiles() beginGame() diff --git a/scripts/gameLevel.gd b/scripts/gameLevel.gd index 6bbe226..7a0768b 100644 --- a/scripts/gameLevel.gd +++ b/scripts/gameLevel.gd @@ -28,9 +28,9 @@ func createLighMaskAt(pos, layer): var light = Light2D.new() light.set_enabled(true) light.set_texture(tileMask) - light.set_item_mask(global.TILE_MASK) - light.set_pos(pos) - light.set_mode(Light2D.MODE_MASK) + #light.set_item_mask(global.TILE_MASK) + light.position = pos + light.mode = Light2D.MODE_MASK layer.add_child(light) @@ -49,12 +49,14 @@ func createCookieAt(column, row, cookieType): return cookie func cookieAt(column, row): - if column == null || row == null: print("Wrong loc"); return null - - assert(column >= 0 && column < global.NumColumns) - assert(row >= 0 && row < global.NumRows) - - return _cookies[column][row] + if column != null && row != null: + assert(column >= 0 && column < global.NumColumns) + assert(row >= 0 && row < global.NumRows) + + return _cookies[column][row] + else: + print("bad loc") + return null func initWithFile(file_path): _tiles.clear() @@ -63,17 +65,17 @@ func initWithFile(file_path): var file = File.new() if file.file_exists(file_path): file.open(file_path, File.READ) - else: print("File Not exists"); return - - var txt = file.get_as_text() + else: + print("File Not exists") + return - var dict = Dictionary() - dict.parse_json(txt) + var txt = file.get_as_text() + var level = parse_json(txt) - var tileset = dict["tiles"] - maximumMoves = dict["moves"] - targetScore = dict["targetScore"] - definedType = dict["definedType"] + var tileset = level["tiles"] + maximumMoves = level["moves"] + targetScore = level["targetScore"] + definedType = level["definedType"] _tiles.resize(global.NumColumns) _tiles.append(Array().resize(global.NumRows)) @@ -85,11 +87,15 @@ func initWithFile(file_path): _tiles[column] = [] _cookies[column] = [] for row in range(global.NumRows): - if tileset[row][column] > 1: _cookies[column].append(gameCookie.new(tileset[row][column]-5)) - else: _cookies[column].append(gameCookie.new()) + if tileset[row][column] > 1: + _cookies[column].append(gameCookie.new(tileset[row][column]-5)) + else: + _cookies[column].append(gameCookie.new()) - if tileset[row][column] != 0: _tiles[column].append(Tile.new()) - else: _tiles[column].append(null) + if tileset[row][column] != 0: + _tiles[column].append(Tile.new()) + else: + _tiles[column].append(null) func performSwap(swap): var columnA = swap.cookieA.column; @@ -306,10 +312,10 @@ func detectTLMatches(hChains, vChains): for cookie in vCookies: var cookieIndex = vCookies.find(cookie) - var match = hCookies.find(cookie) + var matches = hCookies.find(cookie) - if (match == 0 && (cookieIndex == 0 || cookieIndex == vCookies.size()-1)) || \ - (match == hCookies.size()-1 && (cookieIndex == 0 || cookieIndex == vCookies.size()-1)): + if (matches == 0 && (cookieIndex == 0 || cookieIndex == vCookies.size()-1)) || \ + (matches == hCookies.size()-1 && (cookieIndex == 0 || cookieIndex == vCookies.size()-1)): chain.setCookies(vCookies+hCookies) chain.chainType = chain.ChainLShape chain.matchColumn = cookie.column @@ -317,10 +323,10 @@ func detectTLMatches(hChains, vChains): set.append(chain) vChains.erase(vChain) hChains.erase(hChain) - elif (match > 0 && match < hCookies.size()-1 && \ + elif (matches > 0 && matches < hCookies.size()-1 && \ (cookieIndex == 0 || cookieIndex == vCookies.size()-1)) || \ (cookieIndex > 0 && cookieIndex < vCookies.size()-1 && \ - (match == 0 || match == hCookies.size()-1)): + (matches == 0 || matches == hCookies.size()-1)): chain.setCookies(vCookies+hCookies) chain.chainType = chain.ChainTShape chain.matchColumn = cookie.column diff --git a/scripts/global.gd b/scripts/global.gd index 8e74cec..abbe8ca 100644 --- a/scripts/global.gd +++ b/scripts/global.gd @@ -7,7 +7,7 @@ var NumCookieTypes = 6 var score = 0 var targetScore = 0 var movesLeft = 0 -var maxMoves = 0 +#var maxMoves = 0 const TILE_MASK = 8 const TILE_WIDTH = 64.0 @@ -34,7 +34,6 @@ func get_VisibleSize(): func _ready(): currentScene = get_tree().get_root().get_child(get_tree().get_root().get_child_count() -1) - Globals.set("MAX_POWER_LEVEL", 9000) func setScene(scene): currentScene.queue_free() diff --git a/scripts/parentNode2D.gd b/scripts/parentNode2D.gd index b6d15f7..257acd2 100644 --- a/scripts/parentNode2D.gd +++ b/scripts/parentNode2D.gd @@ -6,7 +6,7 @@ func set_background(value): background = value func get_VisibleSize(): - return get_parent().get_rect().size + return get_parent().rectangle.size func get_center(): var vSize = get_VisibleSize()