mirror of
https://gitee.com/freeyz/godot-mota.git
synced 2024-12-22 15:19:19 +08:00
实现商店逻辑
This commit is contained in:
parent
0a0ece085a
commit
95a36343ff
@ -376,6 +376,7 @@ __meta__ = {
|
||||
margin_top = 96.0
|
||||
margin_right = 414.0
|
||||
margin_bottom = 224.0
|
||||
popup_exclusive = true
|
||||
__meta__ = {
|
||||
"_edit_group_": true,
|
||||
"_edit_use_anchors_": false
|
||||
@ -417,6 +418,7 @@ margin_left = -208.0
|
||||
margin_top = -176.0
|
||||
margin_right = 208.0
|
||||
margin_bottom = 240.0
|
||||
popup_exclusive = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=15 format=2]
|
||||
[gd_scene load_steps=16 format=2]
|
||||
|
||||
[ext_resource path="res://src/level/LevelInstance.gd" type="Script" id=1]
|
||||
[ext_resource path="res://src/navigation/NavigationTileMap.gd" type="Script" id=2]
|
||||
@ -14,6 +14,7 @@
|
||||
[ext_resource path="res://src/props/RedGemstone.tscn" type="PackedScene" id=12]
|
||||
[ext_resource path="res://src/stairs/StairsDown.tscn" type="PackedScene" id=13]
|
||||
[ext_resource path="res://src/player/Player.tscn" type="PackedScene" id=14]
|
||||
[ext_resource path="res://src/shop/Shop.tscn" type="PackedScene" id=15]
|
||||
|
||||
[node name="Level4" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
@ -74,54 +75,43 @@ position = Vector2( 80, 144 )
|
||||
|
||||
[node name="MonsterSprite" parent="Items" instance=ExtResource( 6 )]
|
||||
position = Vector2( 112, 336 )
|
||||
frame = 1
|
||||
|
||||
[node name="MonsterSprite4" parent="Items" instance=ExtResource( 6 )]
|
||||
position = Vector2( 144, 464 )
|
||||
frame = 1
|
||||
|
||||
[node name="MonsterSprite6" parent="Items" instance=ExtResource( 6 )]
|
||||
position = Vector2( 272, 464 )
|
||||
frame = 1
|
||||
|
||||
[node name="MonsterSprite7" parent="Items" instance=ExtResource( 6 )]
|
||||
position = Vector2( 272, 400 )
|
||||
animation = "bluePriest"
|
||||
frame = 1
|
||||
|
||||
[node name="MonsterSprite8" parent="Items" instance=ExtResource( 6 )]
|
||||
position = Vector2( 80, 208 )
|
||||
animation = "bluePriest"
|
||||
frame = 1
|
||||
|
||||
[node name="MonsterSprite9" parent="Items" instance=ExtResource( 6 )]
|
||||
position = Vector2( 304, 272 )
|
||||
animation = "skeleton"
|
||||
frame = 1
|
||||
|
||||
[node name="MonsterSprite10" parent="Items" instance=ExtResource( 6 )]
|
||||
position = Vector2( 336, 208 )
|
||||
animation = "skeletonSoilder"
|
||||
frame = 1
|
||||
|
||||
[node name="MonsterSprite5" parent="Items" instance=ExtResource( 6 )]
|
||||
position = Vector2( 112, 432 )
|
||||
frame = 1
|
||||
|
||||
[node name="MonsterSprite11" parent="Items" instance=ExtResource( 6 )]
|
||||
position = Vector2( 144, 400 )
|
||||
animation = "bat"
|
||||
frame = 1
|
||||
|
||||
[node name="MonsterSprite2" parent="Items" instance=ExtResource( 6 )]
|
||||
position = Vector2( 48, 336 )
|
||||
animation = "redSlime"
|
||||
frame = 1
|
||||
|
||||
[node name="MonsterSprite3" parent="Items" instance=ExtResource( 6 )]
|
||||
position = Vector2( 208, 272 )
|
||||
animation = "redSlime"
|
||||
frame = 1
|
||||
|
||||
[node name="PlayerProps4" parent="Items" instance=ExtResource( 10 )]
|
||||
position = Vector2( 306.1, 432 )
|
||||
@ -143,3 +133,5 @@ position = Vector2( 48, 464 )
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource( 14 )]
|
||||
position = Vector2( 368, 437.1 )
|
||||
|
||||
[node name="Shop" parent="." instance=ExtResource( 15 )]
|
||||
|
@ -2,6 +2,8 @@ extends KinematicBody2D
|
||||
|
||||
class_name Player
|
||||
|
||||
const touch_callback_function_name = "on_player_touched"
|
||||
|
||||
export(NodePath) var navigation_tile_map_path : NodePath
|
||||
|
||||
export var hp : int = 1000 setget set_hp
|
||||
@ -81,10 +83,10 @@ func call_collider(collision:KinematicCollision2D):
|
||||
var collider = collision.collider
|
||||
if collider is TileMap:
|
||||
return
|
||||
if collider.has_method("on_player_touched"):
|
||||
if collider.has_method(touch_callback_function_name):
|
||||
array_tween.stop_all()
|
||||
animation_tree.active = false
|
||||
collider.call("on_player_touched",self)
|
||||
collider.call(touch_callback_function_name,self)
|
||||
|
||||
# 保存游戏数据
|
||||
func save_data(data:Dictionary,global:Dictionary):
|
||||
|
74
src/shop/Shop.gd
Normal file
74
src/shop/Shop.gd
Normal file
@ -0,0 +1,74 @@
|
||||
extends Node2D
|
||||
|
||||
onready var dialog : PopupDialog = $"ShopDialog"
|
||||
|
||||
# 文字
|
||||
|
||||
onready var message : Label = $"ShopDialog/Message"
|
||||
|
||||
# 按钮
|
||||
|
||||
onready var close_button : Button = $"ShopDialog/VBoxContainer/CloseDialog"
|
||||
|
||||
onready var add_hp_button : Button = $"ShopDialog/VBoxContainer/AddHp"
|
||||
|
||||
onready var add_atk_button : Button = $"ShopDialog/VBoxContainer/AddAtk"
|
||||
|
||||
onready var add_def_button : Button = $"ShopDialog/VBoxContainer/AddDef"
|
||||
|
||||
# 增加的hp
|
||||
export var added_hp = 100
|
||||
|
||||
# 增加的攻击力
|
||||
export var added_atk = 2
|
||||
|
||||
# 增加的防御力
|
||||
export var added_def = 4
|
||||
|
||||
# 初始金币
|
||||
export var init_money = 20
|
||||
|
||||
# 使用的次数
|
||||
export var used_count = 0
|
||||
|
||||
# 玩家
|
||||
var player : Player
|
||||
|
||||
func _ready():
|
||||
var used_money = get_used_money()
|
||||
message.text = "如果供奉%s金币,便可以增强你的力量,你想要什么呢......" % used_money
|
||||
add_hp_button.text = "生命+%s" % added_hp
|
||||
add_atk_button.text = "攻击力+%s" % added_atk
|
||||
add_def_button.text = "防御力+%s" % added_def
|
||||
|
||||
# 触碰回调
|
||||
func on_player_touched(player):
|
||||
self.player = player
|
||||
dialog.popup_centered()
|
||||
|
||||
func _on_CloseDialog_pressed():
|
||||
dialog.visible = false
|
||||
|
||||
func _on_AddHp_pressed():
|
||||
if enough_money_to_pay():
|
||||
player.hp += added_hp
|
||||
|
||||
func _on_AddAtk_pressed():
|
||||
if enough_money_to_pay():
|
||||
player.atk += added_atk
|
||||
|
||||
func _on_AddDef_pressed():
|
||||
if enough_money_to_pay():
|
||||
player.def += added_def
|
||||
|
||||
func get_used_money() -> int:
|
||||
return init_money * (used_count + 1)
|
||||
|
||||
func enough_money_to_pay() -> bool:
|
||||
var money = get_used_money()
|
||||
if player.money >= money:
|
||||
player.money -= money
|
||||
return true
|
||||
else:
|
||||
Messages.showDialog("金钱不足")
|
||||
return false
|
174
src/shop/Shop.tscn
Normal file
174
src/shop/Shop.tscn
Normal file
@ -0,0 +1,174 @@
|
||||
[gd_scene load_steps=16 format=2]
|
||||
|
||||
[ext_resource path="res://assets/fonts/Droid Sans Fallback.tres" type="DynamicFont" id=1]
|
||||
[ext_resource path="res://assets/images/terrains.png" type="Texture" id=2]
|
||||
[ext_resource path="res://src/shop/Shop.gd" type="Script" id=3]
|
||||
[ext_resource path="res://assets/images/npcs.png" type="Texture" id=4]
|
||||
[ext_resource path="res://assets/fonts/Droid Sans Fallback.ttf" type="DynamicFontData" id=5]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=6]
|
||||
extents = Vector2( 48, 16 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=2]
|
||||
atlas = ExtResource( 4 )
|
||||
region = Rect2( 0, 320, 32, 32 )
|
||||
|
||||
[sub_resource type="AtlasTexture" id=3]
|
||||
atlas = ExtResource( 4 )
|
||||
region = Rect2( 32, 320, 32, 32 )
|
||||
|
||||
[sub_resource type="SpriteFrames" id=4]
|
||||
animations = [ {
|
||||
"frames": [ SubResource( 2 ), SubResource( 3 ) ],
|
||||
"loop": true,
|
||||
"name": "default",
|
||||
"speed": 2.0
|
||||
} ]
|
||||
|
||||
[sub_resource type="DynamicFont" id=5]
|
||||
size = 12
|
||||
font_data = ExtResource( 5 )
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id=7]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id=8]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id=9]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id=10]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id=11]
|
||||
|
||||
[node name="Shop" type="StaticBody2D"]
|
||||
position = Vector2( 176, 144 )
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2( 32, 0 )
|
||||
shape = SubResource( 6 )
|
||||
|
||||
[node name="Left" type="Sprite" parent="."]
|
||||
texture = ExtResource( 2 )
|
||||
region_enabled = true
|
||||
region_rect = Rect2( 0, 704, 32, 32 )
|
||||
|
||||
[node name="Center" type="AnimatedSprite" parent="."]
|
||||
position = Vector2( 32, 0 )
|
||||
frames = SubResource( 4 )
|
||||
frame = 1
|
||||
playing = true
|
||||
|
||||
[node name="Right" type="Sprite" parent="."]
|
||||
position = Vector2( 61.9, 0 )
|
||||
texture = ExtResource( 2 )
|
||||
region_enabled = true
|
||||
region_rect = Rect2( 0, 736, 32, 32 )
|
||||
|
||||
[node name="ShopDialog" type="PopupDialog" parent="."]
|
||||
visible = true
|
||||
margin_left = -80.0
|
||||
margin_top = 16.0
|
||||
margin_right = 146.0
|
||||
margin_bottom = 309.0
|
||||
popup_exclusive = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Title" type="Label" parent="ShopDialog"]
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
margin_left = -20.0
|
||||
margin_top = 23.0
|
||||
margin_right = 20.0
|
||||
margin_bottom = 48.0
|
||||
custom_fonts/font = ExtResource( 1 )
|
||||
custom_colors/font_color = Color( 1, 0.854902, 0, 1 )
|
||||
text = "祭坛"
|
||||
align = 1
|
||||
valign = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Message" type="Label" parent="ShopDialog"]
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
margin_left = -81.0
|
||||
margin_top = 64.0
|
||||
margin_right = 79.0
|
||||
margin_bottom = 104.0
|
||||
custom_fonts/font = SubResource( 5 )
|
||||
custom_colors/font_color = Color( 1, 1, 1, 1 )
|
||||
text = "如果供奉20金币,便可以增强你的力量,你想要什么呢......"
|
||||
align = 1
|
||||
autowrap = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="ShopDialog"]
|
||||
anchor_left = 0.5
|
||||
anchor_top = 1.0
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 1.0
|
||||
margin_left = -81.0
|
||||
margin_top = -165.0
|
||||
margin_right = 79.0
|
||||
margin_bottom = -37.0
|
||||
alignment = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="AddHp" type="Button" parent="ShopDialog/VBoxContainer"]
|
||||
margin_top = 8.0
|
||||
margin_right = 160.0
|
||||
margin_bottom = 30.0
|
||||
custom_styles/hover = SubResource( 7 )
|
||||
custom_styles/pressed = SubResource( 8 )
|
||||
custom_styles/focus = SubResource( 9 )
|
||||
custom_styles/disabled = SubResource( 10 )
|
||||
custom_styles/normal = SubResource( 11 )
|
||||
custom_fonts/font = ExtResource( 1 )
|
||||
text = "生命+100"
|
||||
|
||||
[node name="AddAtk" type="Button" parent="ShopDialog/VBoxContainer"]
|
||||
margin_top = 38.0
|
||||
margin_right = 160.0
|
||||
margin_bottom = 60.0
|
||||
custom_styles/hover = SubResource( 7 )
|
||||
custom_styles/pressed = SubResource( 8 )
|
||||
custom_styles/focus = SubResource( 9 )
|
||||
custom_styles/disabled = SubResource( 10 )
|
||||
custom_styles/normal = SubResource( 11 )
|
||||
custom_fonts/font = ExtResource( 1 )
|
||||
text = "攻击力+2"
|
||||
|
||||
[node name="AddDef" type="Button" parent="ShopDialog/VBoxContainer"]
|
||||
margin_top = 68.0
|
||||
margin_right = 160.0
|
||||
margin_bottom = 90.0
|
||||
custom_styles/hover = SubResource( 7 )
|
||||
custom_styles/pressed = SubResource( 8 )
|
||||
custom_styles/focus = SubResource( 9 )
|
||||
custom_styles/disabled = SubResource( 10 )
|
||||
custom_styles/normal = SubResource( 11 )
|
||||
custom_fonts/font = ExtResource( 1 )
|
||||
text = "防御力+4"
|
||||
|
||||
[node name="CloseDialog" type="Button" parent="ShopDialog/VBoxContainer"]
|
||||
margin_top = 98.0
|
||||
margin_right = 160.0
|
||||
margin_bottom = 120.0
|
||||
custom_styles/hover = SubResource( 7 )
|
||||
custom_styles/pressed = SubResource( 8 )
|
||||
custom_styles/focus = SubResource( 9 )
|
||||
custom_styles/disabled = SubResource( 10 )
|
||||
custom_styles/normal = SubResource( 11 )
|
||||
custom_fonts/font = ExtResource( 1 )
|
||||
text = "离开"
|
||||
[connection signal="pressed" from="ShopDialog/VBoxContainer/AddHp" to="." method="_on_AddHp_pressed"]
|
||||
[connection signal="pressed" from="ShopDialog/VBoxContainer/AddAtk" to="." method="_on_AddAtk_pressed"]
|
||||
[connection signal="pressed" from="ShopDialog/VBoxContainer/AddDef" to="." method="_on_AddDef_pressed"]
|
||||
[connection signal="pressed" from="ShopDialog/VBoxContainer/CloseDialog" to="." method="_on_CloseDialog_pressed"]
|
Loading…
Reference in New Issue
Block a user