Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
tetra-tower
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Oenos
tetra-tower
Commits
3b2061fb
Commit
3b2061fb
authored
Feb 25, 2019
by
18손재민
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
상점 대충 구현함. 이제 스테이지에 맞는 아이템이 상점에서 가격을 가지고 등장함.
parent
427adab1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
83 additions
and
28 deletions
+83
-28
DroppedItem.cs
Assets/Scripts/Item/DroppedItem.cs
+9
-4
InventoryManager.cs
Assets/Scripts/Item/InventoryManager.cs
+42
-8
GoldRoomInGame.cs
Assets/Scripts/TetrisMap/Rooms/GoldRoomInGame.cs
+6
-5
ItemRoomInGame.cs
Assets/Scripts/TetrisMap/Rooms/ItemRoomInGame.cs
+8
-10
DroppedLifeStone.cs
...Scripts/UI/In-game UI/LifeStoneScript/DroppedLifeStone.cs
+10
-1
LifeStoneManager.cs
...Scripts/UI/In-game UI/LifeStoneScript/LifeStoneManager.cs
+8
-0
No files found.
Assets/Scripts/Item/DroppedItem.cs
View file @
3b2061fb
...
...
@@ -13,6 +13,7 @@ public class DroppedItem : MonoBehaviour, IPlayerInteraction
Rigidbody2D
rb2D
;
BoxCollider2D
bc2D
;
SpriteRenderer
sprt
;
public
int
price
=
0
;
public
void
Init
(
Item
_item
,
Vector3
pos
)
{
inventoryManager
=
GameObject
.
Find
(
"InventoryManager"
).
GetComponent
<
InventoryManager
>();
...
...
@@ -28,9 +29,6 @@ public class DroppedItem : MonoBehaviour, IPlayerInteraction
highlight
.
SetActive
(
false
);
bc2D
.
size
=
sprt
.
size
;
transform
.
localScale
=
new
Vector3
((
item
.
sizeInventory
.
x
*
itemSizeMultiplier
)
/
sprt
.
size
.
x
,
(
item
.
sizeInventory
.
y
*
itemSizeMultiplier
)
/
sprt
.
size
.
y
,
1
);
}
public
void
Init
(
Addon
_addon
,
Vector3
pos
)
{
...
...
@@ -50,12 +48,19 @@ public class DroppedItem : MonoBehaviour, IPlayerInteraction
}
public
void
Apply
()
{
if
(!
itemAddon
&&
inventoryManager
.
PushItem
(
item
))
if
(
LifeStoneManager
.
Instance
.
CountType
(
LifeStoneType
.
Gold
)
<
price
)
{
Debug
.
Log
(
"Not enough gold"
);
return
;
}
else
if
(!
itemAddon
&&
inventoryManager
.
PushItem
(
item
))
{
LifeStoneManager
.
Instance
.
ChangeToNormal
(
LifeStoneType
.
Gold
,
price
);
Destroy
(
gameObject
);
}
else
if
(
itemAddon
&&
inventoryManager
.
PushAddon
(
addon
))
{
LifeStoneManager
.
Instance
.
ChangeToNormal
(
LifeStoneType
.
Gold
,
price
);
Destroy
(
gameObject
);
}
}
...
...
Assets/Scripts/Item/InventoryManager.cs
View file @
3b2061fb
...
...
@@ -22,10 +22,10 @@ public class InventoryManager : Singleton<InventoryManager> {
player
=
GameObject
.
Find
(
"Player"
);
SetPool
();
ItemInstantiate
(
"Dagger"
,
player
.
transform
.
position
,
0f
);
/*
ItemInstantiate("Dagger", player.transform.position, 0f);
AddonInstantiate("ParchmentPiece", player.transform.position, 0f);
AddonInstantiate("Gluttony", player.transform.position, 0f);
ItemInstantiate
(
"Bow"
,
player
.
transform
.
position
,
0f
);
ItemInstantiate("Bow", player.transform.position, 0f);
*/
StartCoroutine
(
TestCoroutine
());
}
...
...
@@ -133,7 +133,6 @@ public class InventoryManager : Singleton<InventoryManager> {
if
(
itemPool
[(
int
)
quality
].
Count
>
0
)
{
ItemInstantiate
(
itemPool
[(
int
)
quality
][
0
],
pos
,
popoutStrength
);
itemPool
[(
int
)
quality
].
RemoveAt
(
0
);
}
}
/// <summary>
...
...
@@ -141,7 +140,7 @@ public class InventoryManager : Singleton<InventoryManager> {
/// </summary>
/// <param name="str"></param>
/// <param name="pos"></param>
public
void
ItemInstantiate
(
string
str
,
Vector3
pos
,
float
popoutStrength
)
public
GameObject
ItemInstantiate
(
string
str
,
Vector3
pos
,
float
popoutStrength
)
{
GameObject
tmpItem
=
Instantiate
(
droppedPrefab
);
tmpItem
.
GetComponent
<
DroppedItem
>().
Init
((
Item
)
System
.
Activator
.
CreateInstance
(
System
.
Type
.
GetType
(
str
)),
pos
);
...
...
@@ -152,18 +151,36 @@ public class InventoryManager : Singleton<InventoryManager> {
tmpItem
.
transform
.
SetParent
(
MapManager
.
currentRoom
.
roomInGame
.
transform
);
PopoutGenerator
(
tmpItem
,
popoutStrength
);
return
tmpItem
;
}
/// <summary>
/// Instantiate item by Item Instance on pos
/// </summary>
/// <param name="item"></param>
/// <param name="pos"></param>
public
void
ItemInstantiate
(
Item
item
,
Vector3
pos
,
float
popoutStrength
)
public
GameObject
ItemInstantiate
(
Item
item
,
Vector3
pos
,
float
popoutStrength
)
{
GameObject
tmpItem
=
Instantiate
(
droppedPrefab
);
tmpItem
.
GetComponent
<
DroppedItem
>().
Init
(
item
,
pos
);
tmpItem
.
transform
.
SetParent
(
MapManager
.
currentRoom
.
roomInGame
.
transform
);
PopoutGenerator
(
tmpItem
,
popoutStrength
);
return
tmpItem
;
}
/// <summary>
/// Instantiate random item by quality and assign price.
/// </summary>
/// <param name="quality"></param>
/// <param name="pos"></param>
/// <param name="price"></param>
/// <param name="popoutStrength">0:no popout, 1:normal popout</param>
public
void
ItemInstantiate
(
ItemQuality
quality
,
Vector3
pos
,
int
price
,
float
popoutStrength
)
{
if
(
itemPool
[(
int
)
quality
].
Count
>
0
)
{
GameObject
tmpItem
=
ItemInstantiate
(
itemPool
[(
int
)
quality
][
0
],
pos
,
popoutStrength
);
tmpItem
.
GetComponent
<
DroppedItem
>().
price
=
price
;
}
}
/// <summary>
...
...
@@ -176,7 +193,6 @@ public class InventoryManager : Singleton<InventoryManager> {
if
(
addonPool
[(
int
)
quality
].
Count
>
0
)
{
AddonInstantiate
(
addonPool
[(
int
)
quality
][
0
],
pos
,
popoutStrength
);
addonPool
[(
int
)
quality
].
RemoveAt
(
0
);
}
}
/// <summary>
...
...
@@ -184,7 +200,7 @@ public class InventoryManager : Singleton<InventoryManager> {
/// </summary>
/// <param name="str"></param>
/// <param name="pos"></param>
public
void
AddonInstantiate
(
string
str
,
Vector3
pos
,
float
popoutStrength
)
public
GameObject
AddonInstantiate
(
string
str
,
Vector3
pos
,
float
popoutStrength
)
{
GameObject
tmpItem
=
Instantiate
(
droppedPrefab
);
tmpItem
.
GetComponent
<
DroppedItem
>().
Init
((
Addon
)
System
.
Activator
.
CreateInstance
(
System
.
Type
.
GetType
(
str
)),
pos
);
...
...
@@ -195,18 +211,36 @@ public class InventoryManager : Singleton<InventoryManager> {
tmpItem
.
transform
.
SetParent
(
MapManager
.
currentRoom
.
roomInGame
.
transform
);
PopoutGenerator
(
tmpItem
,
popoutStrength
);
return
tmpItem
;
}
/// <summary>
/// Instantiate addon by Addon Instance on pos
/// </summary>
/// <param name="item"></param>
/// <param name="pos"></param>
public
void
AddonInstantiate
(
Addon
addon
,
Vector3
pos
,
float
popoutStrength
)
public
GameObject
AddonInstantiate
(
Addon
addon
,
Vector3
pos
,
float
popoutStrength
)
{
GameObject
tmpItem
=
Instantiate
(
droppedPrefab
);
tmpItem
.
GetComponent
<
DroppedItem
>().
Init
(
addon
,
pos
);
tmpItem
.
transform
.
SetParent
(
MapManager
.
currentRoom
.
roomInGame
.
transform
);
PopoutGenerator
(
tmpItem
,
popoutStrength
);
return
tmpItem
;
}
/// <summary>
/// Instantiate random addon by quality and assign price.
/// </summary>
/// <param name="addon">The addon.</param>
/// <param name="pos">The position.</param>
/// <param name="price">The price.</param>
/// <param name="popoutStrength">The popout strength.</param>
/// <returns></returns>
public
void
AddonInstantiate
(
ItemQuality
quality
,
Vector3
pos
,
int
price
,
float
popoutStrength
)
{
if
(
addonPool
[(
int
)
quality
].
Count
>
0
)
{
GameObject
tmpItem
=
AddonInstantiate
(
addonPool
[(
int
)
quality
][
0
],
pos
,
popoutStrength
);
tmpItem
.
GetComponent
<
DroppedItem
>().
price
=
price
;
}
}
/// <summary>
...
...
Assets/Scripts/TetrisMap/Rooms/GoldRoomInGame.cs
View file @
3b2061fb
...
...
@@ -29,6 +29,7 @@ public class GoldRoomInGame : RoomInGame {
/// Each index means stage.
/// </summary>
public
static
RoomItemInfo
<
GoldRoomItemInfo
>[]
goldRoomInformation
=
new
RoomItemInfo
<
GoldRoomItemInfo
>[
5
];
GameObject
[]
itemGoods
;
/// <summary>
/// Loads data from gold room's item spawn data.
...
...
@@ -66,7 +67,6 @@ public class GoldRoomInGame : RoomInGame {
Room
room
=
transform
.
parent
.
GetComponent
<
Room
>();
InventoryManager
inventoryManager
=
InventoryManager
.
Instance
;
LifeStoneManager
lifeStoneManager
=
LifeStoneManager
.
Instance
;
float
probability
=
Random
.
Range
(
0f
,
100f
);
Vector3
[]
itemPosition
=
new
Vector3
[
6
];
int
j
=
0
;
foreach
(
Transform
child
in
transform
.
Find
(
"item spot"
))
...
...
@@ -74,19 +74,20 @@ public class GoldRoomInGame : RoomInGame {
int
goldRoomIndex
=
room
.
stage
;
int
random
=
Random
.
Range
(
0
,
goldRoomInformation
[
goldRoomIndex
].
itemSpawnInfo
.
Count
);
GoldRoomItemInfo
itemInfo
=
goldRoomInformation
[
goldRoomIndex
].
itemSpawnInfo
[
random
];
itemGoods
=
new
GameObject
[
itemInfo
.
itemType
.
Length
];
int
itemCount
=
0
;
for
(
int
i
=
0
;
i
<
itemInfo
.
itemType
.
Length
;
i
++)
{
if
(
itemInfo
.
itemType
[
i
]
==
ItemSpawnType
.
Item
)
{
Debug
.
Log
(
"type"
+
itemInfo
.
itemType
[
i
]
+
" quality"
+
itemInfo
.
itemQuality
[
i
]
+
" price"
+
itemInfo
.
price
[
i
]);
inventoryManager
.
ItemInstantiate
(
itemInfo
.
itemQuality
[
i
],
itemPosition
[
itemCount
++],
0
);
inventoryManager
.
ItemInstantiate
(
itemInfo
.
itemQuality
[
i
],
itemPosition
[
itemCount
++],
itemInfo
.
price
[
i
],
0
);
Debug
.
Log
(
"done"
);
}
else
if
(
itemInfo
.
itemType
[
i
]
==
ItemSpawnType
.
Addon
)
{
Debug
.
Log
(
"type"
+
itemInfo
.
itemType
[
i
]
+
" quality"
+
itemInfo
.
itemQuality
[
i
]
+
" price"
+
itemInfo
.
price
[
i
]);
inventoryManager
.
AddonInstantiate
(
itemInfo
.
itemQuality
[
i
],
itemPosition
[
itemCount
++],
0
);
inventoryManager
.
AddonInstantiate
(
itemInfo
.
itemQuality
[
i
],
itemPosition
[
itemCount
++],
itemInfo
.
price
[
i
],
0
);
Debug
.
Log
(
"done"
);
}
else
if
(
itemInfo
.
itemType
[
i
]
==
ItemSpawnType
.
GoldPotion
)
...
...
@@ -100,13 +101,13 @@ public class GoldRoomInGame : RoomInGame {
if
(
itemInfo
.
itemQuality
[
i
]
==
ItemQuality
.
Gold
)
{
Debug
.
Log
(
"type"
+
itemInfo
.
itemType
[
i
]
+
" quality"
+
itemInfo
.
itemQuality
[
i
]
+
" price"
+
itemInfo
.
price
[
i
]);
lifeStoneManager
.
InstantiateDroppedLifeStone
(
6
,
1
,
0
,
itemPosition
[
itemCount
++
],
0
);
lifeStoneManager
.
InstantiateDroppedLifeStone
(
new
Vector2Int
(
3
,
2
),
1
,
0
,
itemPosition
[
itemCount
++],
itemInfo
.
price
[
i
],
0
);
Debug
.
Log
(
"done"
);
}
else
{
Debug
.
Log
(
"type"
+
itemInfo
.
itemType
[
i
]
+
" quality"
+
itemInfo
.
itemQuality
[
i
]
+
" price"
+
itemInfo
.
price
[
i
]);
lifeStoneManager
.
InstantiateDroppedLifeStone
(
6
,
0
,
0
,
itemPosition
[
itemCount
++
],
0
);
lifeStoneManager
.
InstantiateDroppedLifeStone
(
new
Vector2Int
(
3
,
2
),
0
,
0
,
itemPosition
[
itemCount
++],
itemInfo
.
price
[
i
],
0
);
Debug
.
Log
(
"done"
);
}
}
...
...
Assets/Scripts/TetrisMap/Rooms/ItemRoomInGame.cs
View file @
3b2061fb
...
...
@@ -74,10 +74,8 @@ public class ItemRoomInGame : RoomInGame {
int
j
=
0
;
foreach
(
Transform
child
in
transform
.
Find
(
"item spot"
))
itemPosition
[
j
++]
=
child
.
transform
.
position
;
int
itemRoomIndex
=
room
.
itemRoomType
;
if
(
itemRoomIndex
>
5
)
itemRoomIndex
=
5
;
for
(
int
index
=
0
;
index
<
itemRoomInformation
[
itemRoomIndex
-
1
].
itemSpawnInfo
.
Count
;
index
++)
int
itemRoomIndex
=
room
.
itemRoomType
>
5
?
5
:
room
.
itemRoomType
;
for
(
int
index
=
0
;
index
<
itemRoomInformation
[
itemRoomIndex
-
1
].
itemSpawnInfo
.
Count
;
index
++)
{
ItemRoomItemInfo
itemInfo
=
itemRoomInformation
[
itemRoomIndex
-
1
].
itemSpawnInfo
[
index
];
probability
-=
itemInfo
.
probability
;
...
...
@@ -92,19 +90,19 @@ public class ItemRoomInGame : RoomInGame {
for
(
int
_amount
=
0
;
_amount
<
itemInfo
.
amount
[
i
];
_amount
++)
{
Debug
.
Log
(
"type"
+
itemInfo
.
itemType
[
i
]
+
" quality"
+
itemInfo
.
itemQuality
[
i
]
+
" amount"
+
itemInfo
.
amount
[
i
]);
inventoryManager
.
ItemInstantiate
(
itemInfo
.
itemQuality
[
i
],
itemPosition
[
itemCount
++],
1
);
inventoryManager
.
ItemInstantiate
(
itemInfo
.
itemQuality
[
i
],
itemPosition
[
itemCount
++],
0
);
}
else
if
(
itemInfo
.
itemType
[
i
]
==
ItemSpawnType
.
Addon
)
for
(
int
_amount
=
0
;
_amount
<
itemInfo
.
amount
[
i
];
_amount
++)
{
Debug
.
Log
(
"type"
+
itemInfo
.
itemType
[
i
]
+
" quality"
+
itemInfo
.
itemQuality
[
i
]
+
" amount"
+
itemInfo
.
amount
[
i
]);
inventoryManager
.
AddonInstantiate
(
itemInfo
.
itemQuality
[
i
],
itemPosition
[
itemCount
++],
1
);
inventoryManager
.
AddonInstantiate
(
itemInfo
.
itemQuality
[
i
],
itemPosition
[
itemCount
++],
0
);
}
else
if
(
itemInfo
.
itemType
[
i
]
==
ItemSpawnType
.
GoldPotion
)
for
(
int
_amount
=
0
;
_amount
<
itemInfo
.
amount
[
i
];
_amount
++)
{
Debug
.
Log
(
"type"
+
itemInfo
.
itemType
[
i
]
+
" quality"
+
itemInfo
.
itemQuality
[
i
]
+
" amount"
+
itemInfo
.
amount
[
i
]);
lifeStoneManager
.
InstantiatePotion
(
itemPosition
[
itemCount
++],
1
);
lifeStoneManager
.
InstantiatePotion
(
itemPosition
[
itemCount
++],
0
);
}
else
if
(
itemInfo
.
itemType
[
i
]
==
ItemSpawnType
.
LifeStone
)
{
...
...
@@ -114,18 +112,18 @@ public class ItemRoomInGame : RoomInGame {
if
(
itemInfo
.
itemQuality
[
i
]
==
ItemQuality
.
Gold
)
{
Debug
.
Log
(
"type"
+
itemInfo
.
itemType
[
i
]
+
" quality"
+
itemInfo
.
itemQuality
[
i
]
+
" amount"
+
itemInfo
.
amount
[
i
]);
lifeStoneManager
.
InstantiateDroppedLifeStone
(
4
,
1
,
0
,
itemPosition
[
itemCount
++],
1
);
lifeStoneManager
.
InstantiateDroppedLifeStone
(
new
Vector2Int
(
3
,
2
),
4
,
1
,
0
,
itemPosition
[
itemCount
++],
0
);
}
else
{
Debug
.
Log
(
"type"
+
itemInfo
.
itemType
[
i
]
+
" quality"
+
itemInfo
.
itemQuality
[
i
]
+
" amount"
+
itemInfo
.
amount
[
i
]);
lifeStoneManager
.
InstantiateDroppedLifeStone
(
3
,
0
,
0
,
itemPosition
[
itemCount
++],
1
);
lifeStoneManager
.
InstantiateDroppedLifeStone
(
new
Vector2Int
(
3
,
2
),
0
,
0
,
itemPosition
[
itemCount
++],
0
);
}
}
else
{
Debug
.
Log
(
"type"
+
itemInfo
.
itemType
[
i
]
+
" quality"
+
itemInfo
.
itemQuality
[
i
]
+
" amount"
+
itemInfo
.
amount
[
i
]);
lifeStoneManager
.
InstantiateDroppedLifeStone
(
3
*
(
room
.
itemRoomType
-
4
),
1
,
0
,
itemPosition
[
itemCount
++],
1
);
lifeStoneManager
.
InstantiateDroppedLifeStone
(
new
Vector2Int
(
3
,
room
.
itemRoomType
-
4
),
1
,
0
,
itemPosition
[
itemCount
++],
0
);
}
}
else
if
(
itemInfo
.
itemType
[
i
]
==
ItemSpawnType
.
LifeStoneFrame
)
...
...
Assets/Scripts/UI/In-game UI/LifeStoneScript/DroppedLifeStone.cs
View file @
3b2061fb
...
...
@@ -19,6 +19,7 @@ public class DroppedLifeStone : MonoBehaviour, IPlayerInteraction
/// highlightSprite Objects
/// </summary>
GameObject
[]
highObj
;
public
int
price
=
0
;
public
void
Init
(
LifeStoneInfo
_info
,
Vector3
pos
)
{
...
...
@@ -52,8 +53,16 @@ public class DroppedLifeStone : MonoBehaviour, IPlayerInteraction
}
public
void
Apply
()
{
if
(
LifeStoneManager
.
Instance
.
PushLifeStone
(
info
))
if
(
LifeStoneManager
.
Instance
.
CountType
(
LifeStoneType
.
Gold
)
<
price
)
{
Debug
.
Log
(
"Not enough gold"
);
return
;
}
else
if
(
LifeStoneManager
.
Instance
.
PushLifeStone
(
info
))
{
LifeStoneManager
.
Instance
.
ChangeToNormal
(
LifeStoneType
.
Gold
,
price
);
Destroy
(
gameObject
);
}
}
public
void
HighlightSwitch
(
bool
enabled
)
{
...
...
Assets/Scripts/UI/In-game UI/LifeStoneScript/LifeStoneManager.cs
View file @
3b2061fb
...
...
@@ -153,6 +153,14 @@ public class LifeStoneManager : Singleton<LifeStoneManager> {
tmpObj
.
GetComponent
<
DroppedLifeStone
>().
Init
(
info
,
pos
);
PopoutGenerator
(
tmpObj
,
popoutStrength
);
}
public
void
InstantiateDroppedLifeStone
(
Vector2Int
size
,
float
goldPer
,
int
ameNum
,
Vector3
pos
,
int
price
,
float
popoutStrength
)
{
GameObject
tmpObj
=
Instantiate
(
droppedLifeStonePrefab
);
tmpObj
.
transform
.
SetParent
(
MapManager
.
currentRoom
.
roomInGame
.
transform
);
tmpObj
.
GetComponent
<
DroppedLifeStone
>().
Init
(
CreateLifeStoneInfo
(
size
,
goldPer
,
ameNum
),
pos
);
PopoutGenerator
(
tmpObj
,
popoutStrength
);
tmpObj
.
GetComponent
<
DroppedLifeStone
>().
price
=
price
;
}
/// <summary>
/// Randomize LifeStone by size, num, gold probablity, number of ametyst
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment