心愿游戏:符合你心愿的游戏!

手机版

Director五子棋游戏制作教程

时间:2017-05-27 00:00:00 | 来源:网络 | 编辑: 互联网 | 阅读:

Director五子棋游戏制作教程

1..介绍一下棋子的布置。

初始时舞台上没有棋子,我们通过puppetsprite 来动态的根据需要把棋子放在舞台上并激活移动用户使用,这样不必在舞台上拖大量的精灵,时游戏显得混乱。我们这里用41及41以后的通道来共摆放棋子。

具体运用时我们在电影脚本里面定义一个函数来完成这一需要多次用到的操作:

根据nowNum的值来设置,为1是设置为黑子用户走子,-1则为白子用户。

on setUser nowNum

if nowNum= 1 then

nextname= "black"

member ( "info" ). text = "黑子走"

else

nextname= "white"

member ( "info" ). text = "白子走"

end if

repeat with o= 41 to the lastchannel

--从41通道开始找到第一个memberNum为空的演员,来对其关联给对应的演员

if sprite (o). memberNum = 0 then

--开始控制该通道

puppetsprite o, true

--设置位置等相关精灵属性

sprite (o). loc = point ( 322 , 390 )

sprite (o). ink = 36

sprite (o). width = 18

sprite (o). height = 18

--设置对应member

sprite (o). member = member (nextname)

--添加按钮脚本

x = script ( "chess" ). new ()

--因为设置scriptInstanceList时,不能覆盖已有的元素,固需要加入 sprite(o).scriptInstanceList=[]

sprite (o). scriptInstanceList =[]

sprite (o). scriptInstanceList . add ( x )

--强迫初始化

sendsprite o, #beginsprite

exit repeat

end if

end repeat

end

每次下完一颗棋子后,当没有玩家获胜时,则调用setUser(num)出现下一颗棋子让玩家移动。

2..后悔按钮,就是把棋盘上的最近放置的一颗棋子去掉,并设置新的当前玩家。

on mouseup me

puppetsound 1 , "regret" --播放音效

repeat with i= the lastchannel down to 42 --从最好一个通道往前面扫描

--找到第一个memberNum不为空的通道,即最近放置的棋子

if sprite (i). memberNum <> 0 then

Pos= sprite (i- 1 ).OnlinePos --得到棋子的位置信息

onlist[Pos[ 1 ]][Pos[ 2 ]]= 0 --将onlist对应位置恢复,表示该位置为空了

--清空最近一颗棋子的脚本和演员

sprite (i). scriptInstanceList =[]

sprite (i). memberNum = 0

--停止对最近一颗棋子所在通道的控制

puppetsprite i, 0

exit repeat

end if

end repeat

setUser(-Pos[ 3 ])

--如果舞台上只剩一颗棋子,则不应由后悔按钮了

if i= 42 then sel. visible = 0

end

到此位置,整个游戏的关键代码就介绍完了,大家在看完本文后,在参考dir源文件分析应该时有所收获的。

类似游戏

热游排行

更多

关于我们  下载声明  加入我们  意见反馈  网站地图

本站为非营利性个人网站,本站所有游戏来自于互联网,版权属原著所有。如有侵犯你的版权,请发邮件给wishdown2023@163.com

湘ICP备2021017279号-3 公安部备案号:13092602000101

Copyright©2006-2019 www.wishdown.com All rights reserved