From 735418e6e70d28e27300a799c6ba0a86719ddab3 Mon Sep 17 00:00:00 2001 From: freewu32 <2217332562@qq.com> Date: Thu, 23 Jul 2020 13:20:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=98=E6=A1=A3=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E5=92=8C=E6=A5=BC=E5=B1=82=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainScene.tscn | 17 ++----- export_presets.cfg | 49 ++++++++++++++++-- project.godot | 27 ++++++---- scenes/Player.tscn | 50 +++++++++--------- scenes/UI.tscn | 87 ++++++++++++++++++++++---------- scripts/GameArchive.gd | 10 ---- scripts/NavigationTileMap.gd | 1 + scripts/PlayerKinematicBody2D.gd | 7 +++ scripts/PlayerProperty.gd | 47 ----------------- 9 files changed, 159 insertions(+), 136 deletions(-) delete mode 100644 scripts/GameArchive.gd delete mode 100644 scripts/PlayerProperty.gd diff --git a/MainScene.tscn b/MainScene.tscn index 7182385..b861beb 100644 --- a/MainScene.tscn +++ b/MainScene.tscn @@ -1,11 +1,10 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://scenes/UI.tscn" type="PackedScene" id=1] -[ext_resource path="res://scripts/NavigationTileMap.gd" type="Script" id=2] -[ext_resource path="res://scenes/Player.tscn" type="PackedScene" id=3] +[ext_resource path="res://scenes/floors/Floor1.tscn" type="PackedScene" id=2] [ext_resource path="res://images/mota_tileset.tres" type="TileSet" id=4] -[node name="2D" type="Node2D"] +[node name="Main" type="Node2D"] [node name="BackgroundTileMap" type="TileMap" parent="."] tile_set = ExtResource( 4 ) @@ -16,12 +15,4 @@ tile_data = PoolIntArray( 0, 1, 0, 1, 1, 0, 2, 1, 0, 3, 1, 0, 17, 1, 0, 18, 1, 0 [node name="UI" parent="." instance=ExtResource( 1 )] -[node name="NavigationTileMap" type="TileMap" parent="."] -tile_set = ExtResource( 4 ) -cell_size = Vector2( 32, 32 ) -collision_mask = 2147483649 -format = 1 -tile_data = PoolIntArray( 196618, 2, 0, 262151, 2, 0, 262152, 2, 0, 262153, 2, 0, 262154, 2, 0, 262155, 2, 0, 262156, 2, 0, 262157, 2, 0, 327687, 2, 0, 327690, 2, 0, 327693, 2, 0, 393222, 2, 0, 393223, 2, 0, 393224, 2, 0, 393225, 2, 0, 393226, 2, 0, 393227, 2, 0, 393228, 2, 0, 393229, 2, 0, 393230, 2, 0, 393231, 2, 0, 458759, 2, 0, 458760, 2, 0, 458762, 2, 0, 458765, 2, 0, 524296, 2, 0, 524297, 2, 0, 524298, 2, 0, 524299, 2, 0, 524300, 2, 0, 524301, 2, 0, 589834, 2, 0 ) -script = ExtResource( 2 ) - -[node name="PlayerKinematicBody2D" parent="." instance=ExtResource( 3 )] +[node name="Floor1" parent="." instance=ExtResource( 2 )] diff --git a/export_presets.cfg b/export_presets.cfg index 5a8c33c..05565a0 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -7,7 +7,7 @@ custom_features="" export_filter="all_resources" include_filter="" exclude_filter="" -export_path="export/index.html" +export_path="../../export/mota/index.html" patch_list=PoolStringArray( ) script_export_mode=1 script_encryption_key="" @@ -18,8 +18,8 @@ vram_texture_compression/for_desktop=true vram_texture_compression/for_mobile=true html/custom_html_shell="" html/head_include="" -custom_template/release="" -custom_template/debug="" +custom_template/release="D:/godot/source/godot/bin/godot.javascript.opt.64.zip" +custom_template/debug="D:/godot/source/godot/bin/godot.javascript.opt.64.zip" [preset.1] @@ -221,3 +221,46 @@ permissions/write_sms=false permissions/write_social_stream=false permissions/write_sync_settings=false permissions/write_user_dictionary=false + +[preset.2] + +name="Windows Desktop" +platform="Windows Desktop" +runnable=true +custom_features="" +export_filter="all_resources" +include_filter="" +exclude_filter="" +export_path="export/mota.exe" +patch_list=PoolStringArray( ) +script_export_mode=1 +script_encryption_key="" + +[preset.2.options] + +texture_format/bptc=false +texture_format/s3tc=true +texture_format/etc=false +texture_format/etc2=false +texture_format/no_bptc_fallbacks=true +binary_format/64_bits=true +binary_format/embed_pck=false +custom_template/release="D:/godot/source/godot/bin/godot.windows.opt.64.exe" +custom_template/debug="" +codesign/enable=false +codesign/identity_type=0 +codesign/identity="" +codesign/password="" +codesign/timestamp=true +codesign/timestamp_server_url="" +codesign/digest_algorithm=1 +codesign/description="" +codesign/custom_options=PoolStringArray( ) +application/icon="" +application/file_version="" +application/product_version="" +application/company_name="" +application/product_name="" +application/file_description="" +application/copyright="" +application/trademarks="" diff --git a/project.godot b/project.godot index 64aac38..73ce8d4 100644 --- a/project.godot +++ b/project.godot @@ -14,10 +14,10 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://scripts/ArrayTween.gd" }, { -"base": "Node", -"class": "GameArchive", +"base": "Sprite", +"class": "KeySprite", "language": "GDScript", -"path": "res://scripts/GameArchive.gd" +"path": "res://scripts/KeySprite.gd" }, { "base": "TileMap", "class": "NavigationTileMap", @@ -29,23 +29,23 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://scripts/PlayerKinematicBody2D.gd" }, { -"base": "Object", -"class": "PlayerProperty", -"language": "GDScript", -"path": "res://scripts/PlayerProperty.gd" -}, { "base": "Sprite", "class": "PlayerSprite", "language": "GDScript", "path": "res://scripts/PlayerSprite.gd" +}, { +"base": "Button", +"class": "SaveGameButton", +"language": "GDScript", +"path": "res://scripts/SaveGameButton.gd" } ] _global_script_class_icons={ "ArrayTween": "", -"GameArchive": "", +"KeySprite": "", "NavigationTileMap": "", "PlayerKinematicBody2D": "", -"PlayerProperty": "", -"PlayerSprite": "" +"PlayerSprite": "", +"SaveGameButton": "" } [application] @@ -54,6 +54,11 @@ config/name="mota" run/main_scene="res://MainScene.tscn" config/icon="res://settings/icon.png" +[autoload] + +GameFloorManager="*res://scripts/GameFloorManager.gd" +GameArchiveManager="*res://scripts/GameArchiveManager.gd" + [display] window/size/width=672 diff --git a/scenes/Player.tscn b/scenes/Player.tscn index a329893..ac73af0 100644 --- a/scenes/Player.tscn +++ b/scenes/Player.tscn @@ -8,7 +8,7 @@ [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 8, 8 ) -[sub_resource type="Animation" id=4] +[sub_resource type="Animation" id=2] resource_name = "down" length = 1.2 tracks/0/type = "value" @@ -24,8 +24,7 @@ tracks/0/keys = { "values": [ 0, 1, 2 ] } -[sub_resource type="Animation" id=2] -resource_name = "left" +[sub_resource type="Animation" id=3] length = 1.2 loop = true tracks/0/type = "value" @@ -41,8 +40,7 @@ tracks/0/keys = { "values": [ 6, 7, 8 ] } -[sub_resource type="Animation" id=3] -resource_name = "right" +[sub_resource type="Animation" id=4] length = 1.2 loop = true tracks/0/type = "value" @@ -75,40 +73,42 @@ tracks/0/keys = { "values": [ 3, 4, 5 ] } -[sub_resource type="AnimationNodeTimeScale" id=12] - -[sub_resource type="AnimationNodeAnimation" id=6] -animation = "right" +[sub_resource type="AnimationNodeTimeScale" id=6] [sub_resource type="AnimationNodeAnimation" id=7] -animation = "up" +animation = "right" [sub_resource type="AnimationNodeAnimation" id=8] -animation = "down" +animation = "up" [sub_resource type="AnimationNodeAnimation" id=9] +animation = "down" + +[sub_resource type="AnimationNodeAnimation" id=10] animation = "left" -[sub_resource type="AnimationNodeBlendSpace2D" id=10] -blend_point_0/node = SubResource( 6 ) +[sub_resource type="AnimationNodeBlendSpace2D" id=11] +blend_point_0/node = SubResource( 7 ) blend_point_0/pos = Vector2( 1, 0 ) -blend_point_1/node = SubResource( 7 ) +blend_point_1/node = SubResource( 8 ) blend_point_1/pos = Vector2( 0, -0.9 ) -blend_point_2/node = SubResource( 8 ) +blend_point_2/node = SubResource( 9 ) blend_point_2/pos = Vector2( 0, 1 ) -blend_point_3/node = SubResource( 9 ) +blend_point_3/node = SubResource( 10 ) blend_point_3/pos = Vector2( -1, 0 ) blend_mode = 1 -[sub_resource type="AnimationNodeBlendTree" id=11] -nodes/TimeScale/node = SubResource( 12 ) +[sub_resource type="AnimationNodeBlendTree" id=12] +nodes/TimeScale/node = SubResource( 6 ) nodes/TimeScale/position = Vector2( 340, 40 ) nodes/output/position = Vector2( 580, 60 ) -nodes/player/node = SubResource( 10 ) +nodes/player/node = SubResource( 11 ) nodes/player/position = Vector2( 120, 40 ) -node_connections = [ "TimeScale", 0, "player", "output", 0, "TimeScale" ] +node_connections = [ "output", 0, "TimeScale", "TimeScale", 0, "player" ] -[node name="PlayerKinematicBody2D" type="KinematicBody2D"] +[node name="PlayerKinematicBody2D" type="KinematicBody2D" groups=[ +"player", +]] position = Vector2( 336, 208 ) script = ExtResource( 2 ) __meta__ = { @@ -132,13 +132,13 @@ script = ExtResource( 1 ) shape = SubResource( 1 ) [node name="AnimationPlayer" type="AnimationPlayer" parent="."] -anims/down = SubResource( 4 ) -anims/left = SubResource( 2 ) -anims/right = SubResource( 3 ) +anims/down = SubResource( 2 ) +anims/left = SubResource( 3 ) +anims/right = SubResource( 4 ) anims/up = SubResource( 5 ) [node name="AnimationTree" type="AnimationTree" parent="."] -tree_root = SubResource( 11 ) +tree_root = SubResource( 12 ) anim_player = NodePath("../AnimationPlayer") parameters/TimeScale/scale = 10.0 parameters/player/blend_position = Vector2( -0.0495575, -0.190751 ) diff --git a/scenes/UI.tscn b/scenes/UI.tscn index fbff746..b68f6e3 100644 --- a/scenes/UI.tscn +++ b/scenes/UI.tscn @@ -1,28 +1,30 @@ -[gd_scene load_steps=12 format=2] +[gd_scene load_steps=15 format=2] +[ext_resource path="res://scripts/SaveGameButton.gd" type="Script" id=1] [ext_resource path="res://images/mota.png" type="Texture" id=2] [ext_resource path="res://fonts/Droid Sans Fallback.ttf" type="DynamicFontData" id=3] +[ext_resource path="res://scripts/LoadGameButton.gd" type="Script" id=4] [sub_resource type="DynamicFont" id=1] -size = 14 -font_data = ExtResource( 3 ) - -[sub_resource type="DynamicFont" id=2] -font_data = ExtResource( 3 ) - -[sub_resource type="DynamicFont" id=3] size = 12 font_data = ExtResource( 3 ) -[sub_resource type="Curve" id=4] +[sub_resource type="DynamicFont" id=2] +size = 14 +font_data = ExtResource( 3 ) + +[sub_resource type="DynamicFont" id=3] +font_data = ExtResource( 3 ) + +[sub_resource type="DynamicFont" id=4] +size = 12 +font_data = ExtResource( 3 ) + +[sub_resource type="Curve" id=5] _data = [ Vector2( 0, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0.1 ), 0.0, 0.0, 0, 0 ] -[sub_resource type="CurveTexture" id=5] -curve = SubResource( 4 ) - -[sub_resource type="DynamicFont" id=6] -size = 10 -font_data = ExtResource( 3 ) +[sub_resource type="CurveTexture" id=6] +curve = SubResource( 5 ) [sub_resource type="DynamicFont" id=7] size = 10 @@ -36,6 +38,10 @@ font_data = ExtResource( 3 ) size = 10 font_data = ExtResource( 3 ) +[sub_resource type="DynamicFont" id=10] +size = 10 +font_data = ExtResource( 3 ) + [node name="UI" type="Node2D"] [node name="ItemBackground" type="ColorRect" parent="."] @@ -44,11 +50,36 @@ margin_left = 8.0 margin_top = 224.0 margin_right = 120.0 margin_bottom = 384.0 +rect_pivot_offset = Vector2( 0, 32 ) color = Color( 0.403922, 0.403922, 0.403922, 1 ) __meta__ = { "_edit_use_anchors_": false } +[node name="SaveGameButton" type="Button" parent="ItemBackground"] +margin_left = 8.0 +margin_top = 120.0 +margin_right = 48.0 +margin_bottom = 152.0 +custom_fonts/font = SubResource( 1 ) +text = "存档" +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="LoadGameButton" type="Button" parent="ItemBackground"] +margin_left = 64.0 +margin_top = 120.0 +margin_right = 104.0 +margin_bottom = 152.0 +custom_fonts/font = SubResource( 1 ) +text = "读档" +script = ExtResource( 4 ) +__meta__ = { +"_edit_use_anchors_": false +} + [node name="LevelBackground" type="ColorRect" parent="."] margin_left = 16.0 margin_top = 32.0 @@ -62,7 +93,7 @@ __meta__ = { [node name="LevelLabel" type="Label" parent="LevelBackground"] margin_right = 104.0 margin_bottom = 24.0 -custom_fonts/font = SubResource( 1 ) +custom_fonts/font = SubResource( 2 ) text = "魔塔 第01层" align = 1 valign = 1 @@ -84,7 +115,7 @@ __meta__ = { margin_left = 8.0 margin_right = 56.0 margin_bottom = 40.0 -custom_fonts/font = SubResource( 2 ) +custom_fonts/font = SubResource( 3 ) custom_colors/font_color = Color( 0.952941, 0.776471, 0.658824, 1 ) text = "神圣剑" align = 1 @@ -113,7 +144,7 @@ __meta__ = { margin_left = 8.0 margin_right = 56.0 margin_bottom = 40.0 -custom_fonts/font = SubResource( 2 ) +custom_fonts/font = SubResource( 3 ) custom_colors/font_color = Color( 0.815686, 0.803922, 0.992157, 1 ) text = "神圣盾" align = 1 @@ -150,7 +181,7 @@ margin_left = 28.0 margin_top = 14.0 margin_right = 52.0 margin_bottom = 38.0 -custom_fonts/font = SubResource( 3 ) +custom_fonts/font = SubResource( 4 ) text = "0" valign = 1 autowrap = true @@ -171,7 +202,7 @@ margin_left = 76.0 margin_top = 14.0 margin_right = 100.0 margin_bottom = 38.0 -custom_fonts/font = SubResource( 3 ) +custom_fonts/font = SubResource( 4 ) text = "0" valign = 1 autowrap = true @@ -192,7 +223,7 @@ margin_left = 27.0 margin_top = 48.0 margin_right = 51.0 margin_bottom = 72.0 -custom_fonts/font = SubResource( 3 ) +custom_fonts/font = SubResource( 4 ) text = "0" valign = 1 autowrap = true @@ -213,7 +244,7 @@ margin_left = 78.0 margin_top = 48.0 margin_right = 102.0 margin_bottom = 72.0 -custom_fonts/font = SubResource( 3 ) +custom_fonts/font = SubResource( 4 ) text = "0" valign = 1 autowrap = true @@ -235,7 +266,7 @@ __meta__ = { [node name="MoneySprite" type="Sprite" parent="."] position = Vector2( 24, 184 ) texture = ExtResource( 2 ) -normal_map = SubResource( 5 ) +normal_map = SubResource( 6 ) region_enabled = true region_rect = Rect2( 96, 480, 32, 32 ) @@ -252,7 +283,7 @@ __meta__ = { [node name="MoneyLabel" type="Label" parent="MoneySprite/MoneyBackground"] margin_right = 72.0 margin_bottom = 16.0 -custom_fonts/font = SubResource( 6 ) +custom_fonts/font = SubResource( 7 ) text = "0" align = 2 valign = 1 @@ -279,7 +310,7 @@ __meta__ = { [node name="DefLabel" type="Label" parent="DefSprite/DefBackground"] margin_right = 72.0 margin_bottom = 16.0 -custom_fonts/font = SubResource( 7 ) +custom_fonts/font = SubResource( 8 ) text = "10" align = 2 valign = 1 @@ -306,7 +337,7 @@ __meta__ = { [node name="AtkLabel" type="Label" parent="AtkSprite/AtkBackground"] margin_right = 72.0 margin_bottom = 16.0 -custom_fonts/font = SubResource( 8 ) +custom_fonts/font = SubResource( 9 ) text = "10" align = 2 valign = 1 @@ -333,10 +364,12 @@ __meta__ = { [node name="HpLabel" type="Label" parent="HpSprite/HpBackground"] margin_right = 72.0 margin_bottom = 16.0 -custom_fonts/font = SubResource( 9 ) +custom_fonts/font = SubResource( 10 ) text = "1000" align = 2 valign = 1 __meta__ = { "_edit_use_anchors_": false } +[connection signal="pressed" from="ItemBackground/SaveGameButton" to="ItemBackground/SaveGameButton" method="_on_SaveGameButton_pressed"] +[connection signal="pressed" from="ItemBackground/LoadGameButton" to="ItemBackground/LoadGameButton" method="_on_LoadGameButton_pressed"] diff --git a/scripts/GameArchive.gd b/scripts/GameArchive.gd deleted file mode 100644 index f0cae34..0000000 --- a/scripts/GameArchive.gd +++ /dev/null @@ -1,10 +0,0 @@ -extends Node - -class_name GameArchive - -# 创建存档时间 -var create_time : String - -# 更新存档时间 -var update_time : String - diff --git a/scripts/NavigationTileMap.gd b/scripts/NavigationTileMap.gd index 3e8a54f..b83dec4 100644 --- a/scripts/NavigationTileMap.gd +++ b/scripts/NavigationTileMap.gd @@ -18,6 +18,7 @@ func _ready(): var cells := get_cells() init_nodes(cells) init_edges(cells) + print("rect ", get_used_rect()) # 初始化nodes func init_nodes(cells:Array): diff --git a/scripts/PlayerKinematicBody2D.gd b/scripts/PlayerKinematicBody2D.gd index 411af1e..0922207 100644 --- a/scripts/PlayerKinematicBody2D.gd +++ b/scripts/PlayerKinematicBody2D.gd @@ -7,6 +7,8 @@ export(NodePath) var navigation_tile_map_path : NodePath var navigation_tile_map : NavigationTileMap +var navigation_rect : Rect2 + onready var array_tween : ArrayTween = $ArrayTween onready var animation_tree : AnimationTree = $AnimationTree @@ -15,10 +17,15 @@ onready var animation_tree : AnimationTree = $AnimationTree func _ready(): if not navigation_tile_map_path.is_empty(): navigation_tile_map = get_node(navigation_tile_map_path) + navigation_rect = navigation_tile_map.get_used_rect() + navigation_rect.position *= navigation_tile_map.cell_size + navigation_rect.size *= navigation_tile_map.cell_size # 监听屏幕点击事件 func _input(event): if event is InputEventMouseButton and event.is_pressed() and navigation_tile_map != null: + if not navigation_rect.has_point(event.position): + return var astar = navigation_tile_map.astar var start_id = astar.get_closest_point(position) var end_id = astar.get_closest_point(event.position) diff --git a/scripts/PlayerProperty.gd b/scripts/PlayerProperty.gd deleted file mode 100644 index f79af16..0000000 --- a/scripts/PlayerProperty.gd +++ /dev/null @@ -1,47 +0,0 @@ -extends Object - -class_name PlayerProperty - -# 英雄名称 -var username : String = "hero" - -# 英雄血量 -var hp : int = 1000 - -# 英雄攻击力 -var atk : int = 1 - -# 英雄防御力 -var def : int = 1 - -#默认金钱 -var money : int = 0 - -# 英雄等级 -var level : int = 1 - -# 英雄经验 -var experience : int = 0 - -# 当前楼层 -var now_floor = 1 - -# 去过的最大楼层 -var max_floor = 1 - -# 去过的最小楼层 -var min_floor = 1 - -# 被使用的道具 -var used_items : Dictionary = {} - -# 增加使用过的道具 -func add_used_item(now_floor:int,id:int) -> void: - if not used_items.has(now_floor): - used_items[now_floor] = [] - var items = used_items[now_floor] as Array - items.append(id) - -# 根据楼层查询被使用过的道具 -func get_used_items_by_floor(query_floor:int) -> Array: - return used_items[query_floor]