Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
elephant
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
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
elephant
Commits
2aaf7c55
Commit
2aaf7c55
authored
Dec 12, 2021
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
第一版
parent
9462ca1c
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
11070 additions
and
2273 deletions
+11070
-2273
cocos_generator.fire
assets/cocos_generator/scene/cocos_generator.fire
+10436
-2080
cocos_generator.ts
assets/cocos_generator/scene/cocos_generator.ts
+405
-167
config.ts
assets/cocos_generator/scene/config/config.ts
+106
-6
item.ts
assets/cocos_generator/scene/model/item.ts
+4
-0
kitchen.ts
assets/cocos_generator/scene/model/kitchen.ts
+32
-0
kitchen.ts.meta
assets/cocos_generator/scene/model/kitchen.ts.meta
+9
-0
user.ts
assets/cocos_generator/scene/model/user.ts
+28
-2
api.ts
assets/cocos_generator/scene/net/api.ts
+39
-0
api.ts.meta
assets/cocos_generator/scene/net/api.ts.meta
+0
-0
http.ts
assets/cocos_generator/scene/net/http.ts
+0
-16
pg.ts
assets/cocos_generator/scene/pg.ts
+9
-0
bg_progress.png.meta
assets/cocos_generator/textures/home/bg_progress.png.meta
+2
-2
No files found.
assets/cocos_generator/scene/cocos_generator.fire
View file @
2aaf7c55
This source diff could not be displayed because it is too large. You can
view the blob
instead.
assets/cocos_generator/scene/cocos_generator.ts
View file @
2aaf7c55
...
@@ -2,13 +2,33 @@ import { asyncDelay, onHomeworkFinish } from "../script/util";
...
@@ -2,13 +2,33 @@ import { asyncDelay, onHomeworkFinish } from "../script/util";
import
{
MyCocosSceneComponent
}
from
"
../script/MyCocosSceneComponent
"
;
import
{
MyCocosSceneComponent
}
from
"
../script/MyCocosSceneComponent
"
;
import
shop
from
"
./model/shop
"
;
import
shop
from
"
./model/shop
"
;
import
pg
from
"
./pg
"
;
import
pg
from
"
./pg
"
;
import
Api
from
"
./net/
http
"
;
import
Api
from
"
./net/
api
"
;
import
user
from
"
./model/user
"
;
import
user
from
"
./model/user
"
;
import
Item
from
"
./model/item
"
;
import
kitchen
from
"
./model/kitchen
"
;
import
{
ITEM_TYPE
}
from
"
./config/config
"
;
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
@
ccclass
@
ccclass
export
default
class
SceneComponent
extends
MyCocosSceneComponent
{
export
default
class
SceneComponent
extends
MyCocosSceneComponent
{
@
property
(
cc
.
SpriteFrame
)
icon_1
:
cc
.
SpriteFrame
=
null
;
@
property
(
cc
.
SpriteFrame
)
icon_2
:
cc
.
SpriteFrame
=
null
;
@
property
(
cc
.
SpriteFrame
)
icon_3
:
cc
.
SpriteFrame
=
null
;
@
property
(
cc
.
SpriteFrame
)
icon_4
:
cc
.
SpriteFrame
=
null
;
@
property
(
cc
.
SpriteFrame
)
icon_5
:
cc
.
SpriteFrame
=
null
;
@
property
(
cc
.
SpriteFrame
)
icon_6
:
cc
.
SpriteFrame
=
null
;
@
property
(
cc
.
SpriteFrame
)
icon_7
:
cc
.
SpriteFrame
=
null
;
@
property
(
cc
.
SpriteFrame
)
icon_8
:
cc
.
SpriteFrame
=
null
;
addPreloadImage
()
{
addPreloadImage
()
{
// TODO 根据自己的配置预加载图片资源
// TODO 根据自己的配置预加载图片资源
...
@@ -26,29 +46,23 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -26,29 +46,23 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
}
onLoadEnd
()
{
onLoadEnd
()
{
this
.
initGame
();
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this
.
login
().
then
(()
=>
{
Api
.
askUser
().
then
(()
=>
{
this
.
initData
();
this
.
initData
();
this
.
initView
();
this
.
initView
();
this
.
initEvent
();
this
.
initEvent
();
this
.
initTipSys
();
})
})
}
}
login
()
{
initGame
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
//基础效果 需要隐藏的内容处理。 首屏展示
Api
.
askUser
().
then
(()
=>
{
resolve
(
''
);
})
});
}
}
_cantouch
=
null
;
_cantouch
=
null
;
initData
()
{
initData
()
{
// 所有全局变量 默认都是null
// 所有全局变量 默认都是null
this
.
_cantouch
=
true
;
this
.
_cantouch
=
true
;
// this._shop.list[0]
user
.
coin
;
}
}
private
home
:
cc
.
Node
;
private
home
:
cc
.
Node
;
...
@@ -58,59 +72,406 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -58,59 +72,406 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
home
=
pg
.
view
.
find
(
this
,
"
home
"
);
this
.
home
=
pg
.
view
.
find
(
this
,
"
home
"
);
this
.
kitchen
=
pg
.
view
.
find
(
this
,
"
kitchen
"
);
this
.
kitchen
=
pg
.
view
.
find
(
this
,
"
kitchen
"
);
this
.
shop
=
pg
.
view
.
find
(
this
,
"
shop
"
);
this
.
shop
=
pg
.
view
.
find
(
this
,
"
shop
"
);
// this.initBg();
this
.
elephant
=
pg
.
view
.
find
(
this
.
home
,
"
elephant
"
);
// this.initPic();
// this.initBtn();
// this.initIcon();
// let scroll = pg.view.find(this, "scroll");
this
.
elephentState
(
0
);
// let svt = scroll.getComponent("svt");
// // svt.items =
// svt.list = [1, 2, 3, 4, 5, 6, 76, 7];
// svt.updateItem = this.updateItem;
// svt.target = this;
// svt.addNum = 1;
// svt.flush();
}
}
initEvent
()
{
initEvent
()
{
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
home
,
"
btn_kitchen
"
),
this
.
onTouchKitchen
,
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
home
,
"
btn_kitchen
"
),
this
.
onTouchKitchen
,
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
,
"
kitchen/btn_close
"
),
this
.
onTouchKitchenClose
,
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
home
,
"
btn_shop
"
),
this
.
onTouchShop
,
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
home
,
"
btn_shop
"
),
this
.
onTouchShop
,
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
,
"
shop/btn_close
"
),
this
.
onTouchShopClose
,
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
elephant
,
"
walk
"
),
this
.
onTouchElephent
,
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
elephant
,
"
panel_info/btn_close
"
),
this
.
onTouchPanel
,
this
);
}
}
//冰箱按钮
onTouchKitchen
()
{
//----------------------------商店部分--------------------------------------
this
.
kitchen
.
active
=
true
;
}
//商店按钮
//商店按钮
private
shopType
=
0
;
onTouchShop
()
{
onTouchShop
()
{
this
.
shop
.
active
=
true
;
this
.
shop
.
active
=
true
;
}
this
.
updateShopCoin
();
let
btns
=
pg
.
view
.
find
(
this
.
shop
,
"
btns
"
);
let
btn_food_wait
=
pg
.
view
.
find
(
btns
,
"
btn_food_wait
"
);
let
btn_house_wait
=
pg
.
view
.
find
(
btns
,
"
btn_house_wait
"
);
let
btn_clothes_wait
=
pg
.
view
.
find
(
btns
,
"
btn_clothes_wait
"
);
pg
.
view
.
touchOn
(
btn_food_wait
,
this
.
onTouchShopFood
,
this
);
pg
.
view
.
touchOn
(
btn_house_wait
,
this
.
onTouchShopHouse
,
this
);
pg
.
view
.
touchOn
(
btn_clothes_wait
,
this
.
onTouchShopClothes
,
this
);
this
.
shopType
=
ITEM_TYPE
.
FOOD
;
this
.
updateShopList
();
this
.
updateShopBtns
();
}
onTouchShopClose
()
{
this
.
shop
.
active
=
false
;
}
onTouchShopFood
()
{
this
.
shopType
=
ITEM_TYPE
.
FOOD
;
this
.
updateShopList
();
this
.
updateShopBtns
();
}
onTouchShopHouse
()
{
this
.
openTipEmpty
(()
=>
{
this
.
closeTipEmpty
();
})
// this.shopType = ITEM_TYPE.HOUSE;
// this.updateShopList();
// this.updateShopBtns();
}
onTouchShopClothes
()
{
this
.
openTipEmpty
(()
=>
{
this
.
closeTipEmpty
();
})
// this.shopType = ITEM_TYPE.CLOTHES;
// this.updateShopList();
// this.updateShopBtns();
}
updateShopCoin
()
{
let
coin
=
pg
.
view
.
find
(
this
.
shop
,
"
coin/num
"
);
pg
.
view
.
setString
(
coin
,
user
.
coin
);
}
updateShopList
()
{
let
scroll
=
pg
.
view
.
find
(
this
.
shop
,
"
scrollview
"
);
let
svt
=
scroll
.
getComponent
(
"
svt
"
);
let
list
=
kitchen
.
getListByType
(
this
.
shopType
);
svt
.
list
=
list
;
svt
.
updateItem
=
this
.
updateShopItems
;
svt
.
target
=
this
;
svt
.
addNum
=
4
;
svt
.
flush
();
}
updateShopBtns
()
{
let
btns
=
pg
.
view
.
find
(
this
.
shop
,
"
btns
"
);
let
btn_food_wait
=
pg
.
view
.
find
(
btns
,
"
btn_food_wait
"
);
let
btn_food_active
=
pg
.
view
.
find
(
btns
,
"
btn_food_active
"
);
let
btn_house_wait
=
pg
.
view
.
find
(
btns
,
"
btn_house_wait
"
);
let
btn_house_active
=
pg
.
view
.
find
(
btns
,
"
btn_house_active
"
);
let
btn_clothes_wait
=
pg
.
view
.
find
(
btns
,
"
btn_clothes_wait
"
);
let
btn_clothes_active
=
pg
.
view
.
find
(
btns
,
"
btn_clothes_active
"
);
btn_food_wait
.
active
=
this
.
shopType
!=
ITEM_TYPE
.
FOOD
;
btn_food_active
.
active
=
this
.
shopType
==
ITEM_TYPE
.
FOOD
;
btn_house_wait
.
active
=
this
.
shopType
!=
ITEM_TYPE
.
HOUSE
;
btn_house_active
.
active
=
this
.
shopType
==
ITEM_TYPE
.
HOUSE
;
btn_clothes_wait
.
active
=
this
.
shopType
!=
ITEM_TYPE
.
CLOTHES
;
btn_clothes_active
.
active
=
this
.
shopType
==
ITEM_TYPE
.
CLOTHES
;
}
updateShopItems
(
item
,
datas
)
{
item
.
children
.
forEach
(
it
=>
it
.
active
=
false
);
for
(
let
i
=
0
;
i
<
datas
.
length
;
i
++
)
{
let
it
=
item
.
children
[
i
];
let
dt
=
datas
[
i
];
this
.
updateShopItem
(
it
,
dt
);
}
}
updateShopItem
(
item
,
data
:
Item
)
{
item
.
active
=
true
;
let
growth
=
pg
.
view
.
find
(
item
,
"
growth
"
);
let
txt
=
pg
.
view
.
find
(
item
,
"
txt
"
);
let
name
=
pg
.
view
.
find
(
item
,
"
name
"
);
let
icon
=
pg
.
view
.
find
(
item
,
"
icon
"
);
let
discount
=
pg
.
view
.
find
(
item
,
"
discount
"
);
let
btn_buy
=
pg
.
view
.
find
(
item
,
"
btn_buy
"
);
pg
.
view
.
setString
(
txt
,
`可增加 个成长值`
)
pg
.
view
.
setString
(
growth
,
data
.
growthValue
)
pg
.
view
.
setString
(
name
,
data
.
name
)
icon
.
getComponent
(
cc
.
Sprite
).
spriteFrame
=
this
[
data
.
icon
];
let
dis
=
Math
.
round
((
1
-
data
.
discount
)
*
100
);
if
(
dis
>
0
)
{
pg
.
view
.
setString
(
discount
,
`
${
dis
}
%`
)
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
"
bg_sale
"
),
true
);
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
"
discount
"
),
true
);
}
else
{
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
"
bg_sale
"
),
false
);
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
"
discount
"
),
false
);
}
pg
.
view
.
setString
(
pg
.
view
.
find
(
btn_buy
,
"
num
"
),
data
.
cost
)
pg
.
view
.
touchOn
(
btn_buy
,
this
.
onTouchShopItem
,
this
);
item
.
data
=
data
;
}
onTouchShopItem
(
e
)
{
let
item
=
e
.
target
.
parent
;
let
data
:
Item
=
item
.
data
;
if
(
data
.
type
==
1
)
{
//弹出购买弹窗
if
(
user
.
coin
>=
data
.
cost
*
data
.
discount
)
{
this
.
openTipNormal
(
data
,
()
=>
{
this
.
buy
(
data
);
this
.
closeTipNormal
();
},
()
=>
{
this
.
closeTipNormal
();
})
}
else
{
this
.
openTipFail
(
data
,
()
=>
{
this
.
closeTipFail
();
},
()
=>
{
this
.
closeTipFail
();
})
}
}
else
if
(
data
.
type
==
2
)
{
//物品已购买
if
(
data
.
num
>=
0
)
return
;
}
else
if
(
data
.
type
==
3
)
{
//物品已购买
if
(
data
.
num
>=
0
)
return
;
}
}
buy
(
data
)
{
Api
.
askBuyItem
(
data
).
then
(()
=>
{
this
.
updateShopCoin
();
this
.
openTipBuy
(
data
,
()
=>
{
this
.
closeTipBuy
();
})
})
}
//----------------------------冰箱部分--------------------------------------
onTouchKitchen
()
{
this
.
kitchen
.
active
=
true
;
let
coin
=
pg
.
view
.
find
(
this
.
kitchen
,
"
coin/num
"
);
pg
.
view
.
setString
(
coin
,
user
.
coin
);
let
scroll
=
pg
.
view
.
find
(
this
.
kitchen
,
"
scrollview
"
);
let
svt
=
scroll
.
getComponent
(
"
svt
"
);
svt
.
list
=
kitchen
.
list
;
svt
.
updateItem
=
this
.
updateChickenItems
;
svt
.
target
=
this
;
svt
.
addNum
=
4
;
svt
.
flush
();
}
onTouchKitchenClose
()
{
this
.
kitchen
.
active
=
false
;
}
updateChickenItems
(
item
,
datas
)
{
item
.
children
.
forEach
(
it
=>
it
.
active
=
false
);
for
(
let
i
=
0
;
i
<
datas
.
length
;
i
++
)
{
let
it
=
item
.
children
[
i
];
let
dt
=
datas
[
i
];
this
.
updateChickenItem
(
it
,
dt
);
}
}
updateChickenItem
(
item
,
data
:
Item
)
{
item
.
active
=
true
;
let
growth
=
pg
.
view
.
find
(
item
,
"
growth
"
);
let
name
=
pg
.
view
.
find
(
item
,
"
name
"
);
let
icon
=
pg
.
view
.
find
(
item
,
"
icon
"
);
let
num
=
pg
.
view
.
find
(
item
,
"
num
"
);
pg
.
view
.
setString
(
growth
,
`成长值+
${
data
.
growthValue
}
`
)
pg
.
view
.
setString
(
name
,
data
.
name
)
pg
.
view
.
setString
(
num
,
data
.
num
)
icon
.
getComponent
(
cc
.
Sprite
).
spriteFrame
=
this
[
data
.
icon
];
pg
.
view
.
touchOn
(
item
,
this
.
onTouchChickenItem
,
this
);
item
.
data
=
data
;
}
onTouchChickenItem
(
e
)
{
let
item
=
e
.
target
;
let
data
:
Item
=
item
.
data
;
//吃东西。 关闭界面,并展示吃东西的画面,如果不足的情况提示不足。
if
(
data
.
num
<=
0
)
return
;
if
(
data
.
type
==
1
)
{
this
.
eating
(
data
);
}
else
if
(
data
.
type
==
2
)
{
//物品使用
}
}
eating
(
data
)
{
Api
.
askUseItem
(
data
).
then
(()
=>
{
this
.
elephentState
(
3
);
this
.
onTouchKitchenClose
();
})
//可以检测是否升级等---升级说明之类的
}
//----------------------------主界面部分--------------------------------------
//打开提示面板
onTouchElephent
()
{
this
.
elephentState
(
user
.
mood
==
0
?
1
:
2
);
let
panel_info
=
pg
.
view
.
find
(
this
.
elephant
,
"
panel_info
"
);
panel_info
.
active
=
true
;
//刷新内容
let
label_name
=
pg
.
view
.
find
(
panel_info
,
"
label_name
"
);
pg
.
view
.
setString
(
label_name
,
user
.
name
);
let
label_level
=
pg
.
view
.
find
(
panel_info
,
"
label_level
"
);
pg
.
view
.
setString
(
label_level
,
`LV.
${
user
.
level
}
`
);
let
icon_happy
=
pg
.
view
.
find
(
panel_info
,
"
icon_happy
"
);
let
icon_hungry
=
pg
.
view
.
find
(
panel_info
,
"
icon_hungry
"
);
icon_happy
.
active
=
user
.
mood
==
0
;
icon_hungry
.
active
=
user
.
mood
==
1
;
let
percent
=
user
.
growth
/
user
.
growthLevel
;
let
progress
=
pg
.
view
.
find
(
panel_info
,
"
progress
"
);
progress
.
getComponent
(
cc
.
ProgressBar
).
progress
=
percent
;
}
//关闭提示面板
onTouchPanel
()
{
let
panel_info
=
pg
.
view
.
find
(
this
.
elephant
,
"
panel_info
"
);
panel_info
.
active
=
false
;
this
.
elephentState
(
0
);
}
//小象的动作管理。
private
elephant
:
cc
.
Node
;
private
_timer
:
number
;
elephentState
(
state
)
{
switch
(
state
)
{
case
0
:
this
.
elephantWalk
();
break
;
case
1
:
this
.
elephantHappy
();
break
;
case
2
:
this
.
elephantHungry
();
break
;
case
3
:
this
.
elephantEating
();
break
;
}
}
elephantWalk
()
{
let
walkAni
=
pg
.
view
.
find
(
this
.
elephant
,
"
walk
"
);
let
eatAni
=
pg
.
view
.
find
(
this
.
elephant
,
"
eat
"
);
walkAni
.
active
=
true
;
eatAni
.
active
=
false
;
pg
.
view
.
playDBAnimation
(
walkAni
,
"
walking
"
,
0
);
cc
.
Tween
.
stopAllByTarget
(
this
.
elephant
);
walkAni
.
scaleX
=
1
;
cc
.
tween
(
this
.
elephant
)
.
to
(
4
,
{
x
:
400
,
y
:
Math
.
random
()
*
100
})
.
call
(()
=>
{
walkAni
.
scaleX
=
-
1
;
})
.
to
(
4
,
{
x
:
0
,
y
:
Math
.
random
()
*
100
})
.
to
(
4
,
{
x
:
-
400
,
y
:
Math
.
random
()
*
100
})
.
call
(()
=>
{
walkAni
.
scaleX
=
1
;
})
.
to
(
4
,
{
x
:
0
,
y
:
Math
.
random
()
*
100
})
.
call
(()
=>
{
this
.
elephentState
(
0
);
})
.
start
();
}
elephantHappy
()
{
let
walkAni
=
pg
.
view
.
find
(
this
.
elephant
,
"
walk
"
);
let
eatAni
=
pg
.
view
.
find
(
this
.
elephant
,
"
eat
"
);
walkAni
.
active
=
true
;
eatAni
.
active
=
false
;
pg
.
view
.
playDBAnimation
(
walkAni
,
"
happy
"
,
0
);
cc
.
Tween
.
stopAllByTarget
(
this
.
elephant
);
walkAni
.
scaleX
=
1
;
}
elephantHungry
()
{
let
walkAni
=
pg
.
view
.
find
(
this
.
elephant
,
"
walk
"
);
let
eatAni
=
pg
.
view
.
find
(
this
.
elephant
,
"
eat
"
);
walkAni
.
active
=
true
;
eatAni
.
active
=
false
;
pg
.
view
.
playDBAnimation
(
walkAni
,
"
hungry
"
,
0
);
cc
.
Tween
.
stopAllByTarget
(
this
.
elephant
);
walkAni
.
scaleX
=
1
;
}
elephantEating
()
{
let
walkAni
=
pg
.
view
.
find
(
this
.
elephant
,
"
walk
"
);
let
eatAni
=
pg
.
view
.
find
(
this
.
elephant
,
"
eat
"
);
walkAni
.
active
=
false
;
eatAni
.
active
=
true
;
pg
.
view
.
playDBAnimation
(
eatAni
,
"
eating
"
,
0
);
cc
.
Tween
.
stopAllByTarget
(
this
.
elephant
);
setTimeout
(()
=>
{
this
.
elephentState
(
0
);
},
4000
);
}
//-----------------------------提示面板部分-----------------------------------------
private
tip_normal
:
cc
.
Node
;
private
tip_buy
:
cc
.
Node
;
private
tip_fail
:
cc
.
Node
;
private
tip_empty
:
cc
.
Node
;
private
tipSuccess
:
Function
;
private
tipCancel
:
Function
;
private
tipBuySuccess
:
Function
;
private
tipFailSuccess
:
Function
;
private
tipFailCancel
:
Function
;
private
tipEmptySuccess
:
Function
;
initTipSys
()
{
this
.
tip_normal
=
pg
.
view
.
find
(
this
,
"
tip_normal
"
);
this
.
tip_buy
=
pg
.
view
.
find
(
this
,
"
tip_buy
"
);
this
.
tip_fail
=
pg
.
view
.
find
(
this
,
"
tip_fail
"
);
this
.
tip_empty
=
pg
.
view
.
find
(
this
,
"
tip_empty
"
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
tip_normal
,
"
btn_sure
"
),
()
=>
{
this
.
tipSuccess
&&
this
.
tipSuccess
()
},
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
tip_normal
,
"
btn_cancel
"
),
()
=>
{
this
.
tipCancel
&&
this
.
tipCancel
()
},
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
tip_buy
,
"
btn_cancel
"
),
()
=>
{
this
.
tipBuySuccess
&&
this
.
tipBuySuccess
()
},
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
tip_fail
,
"
btn_sure
"
),
()
=>
{
this
.
tipFailSuccess
&&
this
.
tipFailSuccess
()
},
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
tip_fail
,
"
btn_cancel
"
),
()
=>
{
this
.
tipFailCancel
&&
this
.
tipFailCancel
()
},
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
tip_empty
,
"
btn_cancel
"
),
()
=>
{
this
.
tipEmptySuccess
&&
this
.
tipEmptySuccess
()
},
this
);
}
openTipNormal
(
data
:
Item
,
success
,
cancel
)
{
this
.
tip_normal
.
active
=
true
;
this
.
tipSuccess
=
success
;
this
.
tipCancel
=
cancel
;
if
(
data
)
{
pg
.
view
.
setString
(
pg
.
view
.
find
(
this
.
tip_normal
,
"
desc
"
),
`确定花
${
data
.
cost
*
data
.
discount
}
金币购买
${
data
.
name
}
吗?`
);
let
icon
=
pg
.
view
.
find
(
this
.
tip_normal
,
"
icon
"
);
icon
.
getComponent
(
cc
.
Sprite
).
spriteFrame
=
this
[
data
.
icon
];
}
}
closeTipNormal
()
{
this
.
tip_normal
.
active
=
false
;
this
.
tipSuccess
=
null
;
this
.
tipCancel
=
null
;
}
openTipFail
(
data
:
Item
,
success
,
cancel
)
{
this
.
tip_fail
.
active
=
true
;
this
.
tipFailSuccess
=
success
;
this
.
tipFailCancel
=
cancel
;
}
closeTipFail
()
{
this
.
tip_fail
.
active
=
false
;
this
.
tipFailSuccess
=
null
;
this
.
tipFailCancel
=
null
;
}
openTipBuy
(
data
:
Item
,
success
)
{
this
.
tip_buy
.
active
=
true
;
this
.
tipBuySuccess
=
success
;
if
(
data
)
{
let
icon
=
pg
.
view
.
find
(
this
.
tip_normal
,
"
icon
"
);
icon
.
getComponent
(
cc
.
Sprite
).
spriteFrame
=
this
[
data
.
icon
];
}
}
closeTipBuy
()
{
this
.
tip_buy
.
active
=
false
;
this
.
tipBuySuccess
=
null
;
}
updateItem
(
items
,
datas
)
{
openTipEmpty
(
success
)
{
console
.
log
(
items
);
this
.
tip_empty
.
active
=
true
;
console
.
log
(
datas
);
this
.
tipEmptySuccess
=
success
;
}
closeTipEmpty
()
{
this
.
tip_empty
.
active
=
false
;
}
}
initBg
()
{
initBg
()
{
const
bgNode
=
cc
.
find
(
'
Canvas/bg
'
);
const
bgNode
=
cc
.
find
(
'
Canvas/bg
'
);
bgNode
.
scale
=
this
.
_mapScaleMax
;
bgNode
.
scale
=
this
.
_mapScaleMax
;
}
}
playLocalAudio
(
audioName
)
{
playLocalAudio
(
audioName
)
{
const
audio
=
cc
.
find
(
`Canvas/res/audio/
${
audioName
}
`
).
getComponent
(
cc
.
AudioSource
);
const
audio
=
cc
.
find
(
`Canvas/res/audio/
${
audioName
}
`
).
getComponent
(
cc
.
AudioSource
);
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
@@ -120,139 +481,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
...
@@ -120,139 +481,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
});
});
})
})
}
}
// pic1 = null;
// pic2 = null;
// initPic() {
// const canvas = cc.find('Canvas');
// const maxW = canvas.width * 0.7;
// this.getSprNodeByUrl(this.data.pic_url, (sprNode) => {
// const picNode1 = sprNode;
// picNode1.scale = maxW / picNode1.width;
// picNode1.baseX = picNode1.x;
// canvas.addChild(picNode1);
// this.pic1 = picNode1;
// const labelNode = new cc.Node();
// labelNode.color = cc.Color.YELLOW;
// const label = labelNode.addComponent(cc.Label);
// label.string = this.data.text;
// label.fontSize = 60;
// label.lineHeight = 60;
// label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent('cc.Label').font;
// picNode1.addChild(labelNode);
// });
// this.getSprNodeByUrl(this.data.pic_url_2, (sprNode) => {
// const picNode2 = sprNode;
// picNode2.scale = maxW / picNode2.width;
// canvas.addChild(picNode2);
// picNode2.x = canvas.width;
// picNode2.baseX = picNode2.x;
// this.pic2 = picNode2;
// const labelNode = new cc.Node();
// const label = labelNode.addComponent(cc.RichText);
// const size = 60
// label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent(cc.Label).font;
// label.string = `<outline color=#751e00 width=4><size=${size}><color=#ffffff>${this.data.text}</color></size></outline>`
// label.lineHeight = size;
// picNode2.addChild(labelNode);
// });
// }
// initIcon() {
// const iconNode = this.getSprNode('icon');
// iconNode.zIndex = 5;
// iconNode.anchorX = 1;
// iconNode.anchorY = 1;
// iconNode.parent = cc.find('Canvas');
// iconNode.x = iconNode.parent.width / 2 - 10;
// iconNode.y = iconNode.parent.height / 2 - 10;
// iconNode.on(cc.Node.EventType.TOUCH_START, () => {
// this.playAudioByUrl(this.data.audio_url);
// })
// }
// curPage = null;
// initBtn() {
// this.curPage = 0;
// const bottomPart = cc.find('Canvas/bottomPart');
// bottomPart.zIndex = 5; // 提高层级
// bottomPart.x = bottomPart.parent.width / 2;
// bottomPart.y = -bottomPart.parent.height / 2;
// const leftBtnNode = bottomPart.getChildByName('btn_left');
// //节点中添加了button组件 则可以添加click事件监听
// leftBtnNode.on('click', () => {
// if (!this._cantouch) {
// return;
// }
// if (this.curPage == 0) {
// return;
// }
// this.curPage = 0
// this.leftMove();
// this.playLocalAudio('btn');
// })
// const rightBtnNode = bottomPart.getChildByName('btn_right');
// //节点中添加了button组件 则可以添加click事件监听
// rightBtnNode.on('click', () => {
// if (!this._cantouch) {
// return;
// }
// if (this.curPage == 1) {
// return;
// }
// this.curPage = 1
// this.rightMove();
// // 游戏结束时需要调用这个方法通知系统作业完成
// onHomeworkFinish();
// this.playLocalAudio('btn');
// })
// }
// leftMove() {
// this._cantouch = false;
// const len = this.pic1.parent.width;
// cc.tween(this.pic1)
// .to(1, { x: this.pic1.baseX }, { easing: 'cubicInOut' })
// .start();
// cc.tween(this.pic2)
// .to(1, { x: this.pic2.baseX }, { easing: 'cubicInOut' })
// .call(() => {
// this._cantouch = true;
// })
// .start();
// }
// rightMove() {
// this._cantouch = false;
// const len = this.pic1.parent.width;
// cc.tween(this.pic1)
// .to(1, { x: this.pic1.baseX - len }, { easing: 'cubicInOut' })
// .start();
// cc.tween(this.pic2)
// .to(1, { x: this.pic2.baseX - len }, { easing: 'cubicInOut' })
// .call(() => {
// this._cantouch = true;
// })
// .start();
// }
// update (dt) {},
}
}
//未完成功能。
//1.商城购买流程。 不足提示框
//2.商城切换流程。 空提示框
//3.物品使用http请求。
//未确定功能
// 1.所有的家具使用
// 2.所有的衣服使用
assets/cocos_generator/scene/config/config.ts
View file @
2aaf7c55
const
I
tems
=
[
const
I
TEMS
=
[
{
{
id
:
1001
,
id
:
1001
,
name
:
"
西瓜
"
type
:
1
,
//食物
name
:
"
苹果
"
,
icon
:
"
icon_1
"
,
growthValue
:
10
,
cost
:
100
,
discount
:
0.8
,
num
:
3
,
levelLimite
:
1
,
},
{
id
:
1002
,
type
:
1
,
//食物
name
:
"
香蕉
"
,
icon
:
"
icon_2
"
,
growthValue
:
15
,
cost
:
120
,
discount
:
1
,
num
:
5
,
levelLimite
:
2
,
},
{
id
:
1003
,
type
:
1
,
//食物
name
:
"
面包
"
,
icon
:
"
icon_3
"
,
growthValue
:
20
,
cost
:
150
,
discount
:
1
,
num
:
8
,
levelLimite
:
1
,
},
{
id
:
1004
,
type
:
1
,
//食物
name
:
"
胡萝卜
"
,
icon
:
"
icon_4
"
,
growthValue
:
30
,
cost
:
200
,
discount
:
1
,
num
:
9
,
levelLimite
:
1
,
},
{
id
:
1005
,
type
:
1
,
//食物
name
:
"
奶酪
"
,
icon
:
"
icon_5
"
,
growthValue
:
40
,
cost
:
230
,
discount
:
1
,
num
:
13
,
levelLimite
:
1
,
},
{
id
:
1006
,
type
:
1
,
//食物
name
:
"
橙子
"
,
icon
:
"
icon_6
"
,
growthValue
:
50
,
cost
:
270
,
discount
:
1
,
num
:
1
,
levelLimite
:
1
,
},
{
id
:
1007
,
type
:
1
,
//食物
name
:
"
披萨
"
,
icon
:
"
icon_7
"
,
growthValue
:
90
,
cost
:
400
,
discount
:
1
,
num
:
0
,
levelLimite
:
1
,
},
{
id
:
1008
,
type
:
1
,
//食物
name
:
"
西红柿
"
,
icon
:
"
icon_8
"
,
growthValue
:
100
,
cost
:
600
,
discount
:
1
,
num
:
0
,
levelLimite
:
1
,
}
}
]
]
const
Shops
=
[];
const
LEVEL
=
{
const
Kitchen
=
[];
level_1
:
{
growth
:
100
,
},
level_2
:
{
growth
:
300
,
},
level_3
:
{
growth
:
600
,
},
level_4
:
{
growth
:
1000
,
},
level_5
:
{
growth
:
1500
,
},
level_6
:
{
growth
:
2100
,
}
}
const
USER
=
{
const
USER
=
{
name
:
"
小小香香
"
,
name
:
"
小小香香
"
,
coin
:
100023
,
coin
:
100023
,
...
@@ -19,4 +114,9 @@ const USER = {
...
@@ -19,4 +114,9 @@ const USER = {
useClothes
:
[],
useClothes
:
[],
mood
:
"
开心
"
mood
:
"
开心
"
}
}
export
{
USER
}
enum
ITEM_TYPE
{
\ No newline at end of file
FOOD
=
1
,
HOUSE
=
2
,
CLOTHES
=
3
}
export
{
USER
,
LEVEL
,
ITEMS
,
ITEM_TYPE
}
\ No newline at end of file
assets/cocos_generator/scene/model/item.ts
View file @
2aaf7c55
class
Item
{
class
Item
{
public
id
:
number
;
//id
public
type
:
number
;
//商品类型
public
type
:
number
;
//商品类型
public
name
:
string
;
//商品名称
public
name
:
string
;
//商品名称
public
icon
:
string
;
//商品图片--可用type生成
public
icon
:
string
;
//商品图片--可用type生成
...
@@ -8,12 +9,15 @@ class Item {
...
@@ -8,12 +9,15 @@ class Item {
public
num
:
number
;
//拥有数量
public
num
:
number
;
//拥有数量
public
levelLimite
:
number
;
//等级限制
public
levelLimite
:
number
;
//等级限制
constructor
(
obj
:
any
)
{
constructor
(
obj
:
any
)
{
this
.
id
=
obj
.
id
;
this
.
type
=
obj
.
type
;
this
.
type
=
obj
.
type
;
this
.
name
=
obj
.
name
;
this
.
name
=
obj
.
name
;
this
.
icon
=
obj
.
icon
;
this
.
icon
=
obj
.
icon
;
this
.
growthValue
=
obj
.
growthValue
;
this
.
growthValue
=
obj
.
growthValue
;
this
.
cost
=
obj
.
cost
;
this
.
cost
=
obj
.
cost
;
this
.
discount
=
obj
.
discount
;
this
.
discount
=
obj
.
discount
;
this
.
num
=
obj
.
num
;
this
.
levelLimite
=
obj
.
levelLimite
;
}
}
}
}
...
...
assets/cocos_generator/scene/model/kitchen.ts
0 → 100644
View file @
2aaf7c55
import
Item
from
"
./item
"
class
Kitchen
{
private
_list
:
Array
<
Item
>
constructor
()
{
this
.
_list
=
[];
}
use
(
id
)
{
this
.
_list
=
this
.
_list
.
map
(
li
=>
{
if
(
li
.
id
==
id
)
li
.
num
-=
1
;
return
li
;
})
}
buy
(
id
)
{
this
.
_list
=
this
.
_list
.
map
(
li
=>
{
if
(
li
.
id
==
id
)
li
.
num
+=
1
;
return
li
;
})
}
getListByType
(
type
:
number
)
{
return
this
.
_list
.
filter
(
li
=>
li
.
type
==
type
)
}
parse
(
list
:
any
)
{
if
(
!
list
)
return
;
this
.
_list
=
list
.
map
(
li
=>
{
return
new
Item
(
li
);
})
}
get
list
()
{
return
this
.
_list
;
}
}
let
kitchen
=
new
Kitchen
();
export
default
kitchen
;
assets/cocos_generator/scene/model/kitchen.ts.meta
0 → 100644
View file @
2aaf7c55
{
"ver": "1.0.8",
"uuid": "1ab727dc-af13-4539-a98a-4ec85d8981c9",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
assets/cocos_generator/scene/model/user.ts
View file @
2aaf7c55
import
{
LEVEL
}
from
"
../config/config
"
;
class
User
{
class
User
{
public
name
:
string
;
public
name
:
string
;
public
coin
:
number
;
public
coin
:
number
;
public
level
:
number
;
public
level
:
number
;
public
growth
:
number
;
public
growth
:
number
;
//当前成长值
public
growthDaily
:
number
;
public
growthDaily
:
number
;
public
growthDailyMax
:
number
;
public
growthDailyMax
:
number
;
public
eatTime
:
number
;
public
eatTime
:
number
;
public
useFurniture
:
Array
<
number
>
;
public
useFurniture
:
Array
<
number
>
;
public
useClothes
:
Array
<
number
>
;
public
useClothes
:
Array
<
number
>
;
public
mood
:
string
;
public
mood
:
number
;
//0开心 1不开心
constructor
()
{
constructor
()
{
}
}
...
@@ -23,6 +25,30 @@ class User {
...
@@ -23,6 +25,30 @@ class User {
this
.
eatTime
=
data
.
eatTime
;
this
.
eatTime
=
data
.
eatTime
;
this
.
useFurniture
=
data
.
useFurniture
;
this
.
useFurniture
=
data
.
useFurniture
;
this
.
useClothes
=
data
.
useClothes
;
this
.
useClothes
=
data
.
useClothes
;
this
.
mood
=
1
;
}
isDailyMax
()
{
return
this
.
growthDailyMax
>=
this
.
growthDaily
}
addGrowth
(
val
)
{
this
.
growth
+=
val
;
this
.
growthDaily
+=
val
;
user
.
mood
=
0
;
}
useCoin
(
val
)
{
this
.
coin
-=
val
;
}
//当前等级成长值最大值
public
get
growthLevel
():
number
{
let
max
=
1
;
for
(
let
i
=
1
;
i
<
100
;
i
++
)
{
let
val
=
LEVEL
[
`level_
${
i
}
`
].
growth
;
if
(
this
.
growth
<
val
)
{
max
=
val
break
;
}
}
return
max
}
}
}
}
let
user
=
new
User
();
let
user
=
new
User
();
...
...
assets/cocos_generator/scene/net/api.ts
0 → 100644
View file @
2aaf7c55
import
pg
from
"
../pg
"
;
import
{
ITEMS
,
USER
}
from
"
../config/config
"
import
user
from
"
../model/user
"
;
import
kitchen
from
"
../model/kitchen
"
;
//获取信息,购买物品,使用物品(吃东西),穿戴衣服/更换家具
class
Api
{
static
askUser
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
pg
.
http
.
send
(
"
GET
"
,
"
http://www.baidu.com
"
,
{}).
then
((
data
:
any
)
=>
{
let
userInfo
=
USER
;
user
.
parse
(
userInfo
);
let
kitchenInfo
=
ITEMS
;
kitchen
.
parse
(
kitchenInfo
);
resolve
(
''
);
})
});
}
static
askUseItem
(
data
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
pg
.
http
.
send
(
"
GET
"
,
"
http://www.baidu.com
"
,
{}).
then
((
data
:
any
)
=>
{
user
.
addGrowth
(
data
.
growthValue
);
kitchen
.
use
(
data
.
id
);
resolve
(
''
);
})
});
}
static
askBuyItem
(
data
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
data
.
id
;
data
.
type
;
pg
.
http
.
send
(
"
GET
"
,
"
http://www.baidu.com
"
,
{}).
then
((
data
:
any
)
=>
{
user
.
useCoin
(
data
.
cost
*
data
.
discount
);
kitchen
.
buy
(
data
.
id
);
resolve
(
''
);
})
});
}
}
export
default
Api
;
\ No newline at end of file
assets/cocos_generator/scene/net/
http
.ts.meta
→
assets/cocos_generator/scene/net/
api
.ts.meta
View file @
2aaf7c55
File moved
assets/cocos_generator/scene/net/http.ts
deleted
100644 → 0
View file @
9462ca1c
import
pg
from
"
../pg
"
;
import
{
USER
}
from
"
../config/config
"
import
user
from
"
../model/user
"
;
//获取信息,购买物品,使用物品(吃东西),穿戴衣服/更换家具
class
Api
{
static
askUser
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
pg
.
http
.
send
(
"
GET
"
,
"
http://www.baidu.com
"
,
{}).
then
((
data
:
any
)
=>
{
let
info
=
USER
;
user
.
parse
(
info
);
resolve
(
''
);
})
});
}
}
export
default
Api
;
\ No newline at end of file
assets/cocos_generator/scene/pg.ts
View file @
2aaf7c55
...
@@ -245,6 +245,15 @@ let pg = {
...
@@ -245,6 +245,15 @@ let pg = {
skl
.
setAnimation
(
0
,
aniName
,
loop
);
skl
.
setAnimation
(
0
,
aniName
,
loop
);
return
skl
;
return
skl
;
},
},
playDBAnimation
(
item
:
any
,
aniName
:
string
,
loop
?:
number
)
{
if
(
!
item
||
!
cc
.
isValid
(
item
))
return
pg
.
logger
.
w
(
"
动画播放失败,传入了错误的item
"
);
if
(
!
aniName
)
return
pg
.
logger
.
w
(
"
动画播放失败,传入了错误的aniName
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
cc
.
isValid
(
node
))
return
pg
.
logger
.
w
(
"
节点已销毁
"
);
let
skl
:
dragonBones
.
ArmatureDisplay
=
node
.
getComponent
(
dragonBones
.
ArmatureDisplay
);
skl
.
playAnimation
(
aniName
,
loop
);
return
skl
;
},
},
},
load
:
{
load
:
{
//资源加载
//资源加载
...
...
assets/cocos_generator/textures/home/bg_progress.png.meta
View file @
2aaf7c55
...
@@ -28,8 +28,8 @@
...
@@ -28,8 +28,8 @@
"rawHeight": 20,
"rawHeight": 20,
"borderTop": 0,
"borderTop": 0,
"borderBottom": 0,
"borderBottom": 0,
"borderLeft":
0
,
"borderLeft":
6.5
,
"borderRight":
0
,
"borderRight":
8.5
,
"subMetas": {}
"subMetas": {}
}
}
}
}
...
...
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