设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1249|回复: 0
打印 上一主题 下一主题

[已经过期] 情哥哥姐姐 帮忙做一个在地图上显示第2种货币图片的范例

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
59 小时
注册时间
2012-4-9
帖子
24
跳转到指定楼层
1
发表于 2012-5-5 19:25:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 忧雪の伤 于 2012-5-5 19:36 编辑
  1. module RPG
  2. class Weapon
  3. def price2
  4. arr = @description.split(/@/)
  5. return arr[1].to_i if arr[1] != nil
  6. return 0
  7. end
  8. def description
  9. arr = @description.split(/@/)
  10. return arr[0] if arr[1] != nil
  11. return @description
  12. end
  13. end
  14. class Armor
  15. def price2
  16. arr = @description.split(/@/)
  17. return arr[1].to_i if arr[1] != nil
  18. return 0
  19. end
  20. def description
  21. arr = @description.split(/@/)
  22. return arr[0] if arr[1] != nil
  23. return @description
  24. end
  25. end
  26. class Item
  27. def price2
  28. arr = @description.split(/@/)
  29. return arr[1].to_i if arr[1] != nil
  30. return 0
  31. end
  32. def description
  33. arr = @description.split(/@/)
  34. return arr[0] if arr[1] != nil
  35. return @description
  36. end
  37. end
  38. end
  39. #==============================================================================
  40. # ■ Window_Gold
  41. #------------------------------------------------------------------------------
  42. #  显示金钱的窗口。
  43. #==============================================================================
  44. class Window_Gold2 < Window_Base
  45. #--------------------------------------------------------------------------
  46. # ● 初始化窗口
  47. #--------------------------------------------------------------------------
  48. def initialize
  49. super(0, 0, 160, 128)
  50. self.contents = Bitmap.new(width - 32, height - 32)
  51. refresh
  52. end
  53. #--------------------------------------------------------------------------
  54. # ● 刷新
  55. #--------------------------------------------------------------------------
  56. def refresh
  57. self.contents.clear
  58. cx = contents.text_size($data_system.words.gold).width
  59. self.contents.font.color = normal_color
  60. self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)
  61. self.contents.font.color = system_color
  62. self.contents.draw_text(124-cx, 0, cx, 32, $data_system.words.gold, 2)
  63. self.contents.font.color = Color.new(255, 128, 255, 255)
  64. self.contents.draw_text(4, 32, 54, 32, $game_variables[1].to_s, 2)
  65. self.contents.font.color = system_color
  66. self.contents.draw_text(60, 32, 64, 32, "元宝", 2)
  67. end
  68. end
  69. #==============================================================================
  70. # ■ Window_Help
  71. #------------------------------------------------------------------------------
  72. #  特技及物品的说明、角色的状态显示的窗口。
  73. #==============================================================================
  74. class Window_Help < Window_Base
  75. #--------------------------------------------------------------------------
  76. # ● 初始化对像
  77. #--------------------------------------------------------------------------
  78. def initialize
  79. if $scene.is_a?(Scene_Shop)
  80. super(0, 0, 480, 64)
  81. else
  82. super(0, 0, 640, 64)
  83. end
  84. self.contents = Bitmap.new(width - 32, height - 32)
  85. end
  86. end
  87. #==============================================================================
  88. # ■ Window_ShopBuy
  89. #------------------------------------------------------------------------------
  90. #  商店画面、浏览显示可以购买的商品的窗口。
  91. #==============================================================================
  92. class Window_ShopBuy < Window_Selectable
  93. def draw_item(index)
  94. item = @data[index]
  95. # 获取物品所持数
  96. case item
  97. when RPG::Item
  98. number = $game_party.item_number(item.id)
  99. when RPG::Weapon
  100. number = $game_party.weapon_number(item.id)
  101. when RPG::Armor
  102. number = $game_party.armor_number(item.id)
  103. end
  104. # 价格在所持金以下、并且所持数不是 99 的情况下为普通文字颜色
  105. # 除此之外的情况设置为无效文字色
  106. if item.price <= $game_party.gold and number < 99
  107. self.contents.font.color = normal_color
  108. else
  109. self.contents.font.color = disabled_color
  110. end
  111. x = 4
  112. y = index * 32
  113. self.contents.font.color = normal_color
  114. rect = Rect.new(x, y, self.width - 32, 32)
  115. self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  116. bitmap = RPG::Cache.icon(item.icon_name)
  117. opacity = self.contents.font.color == normal_color ? 255 : 128
  118. self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  119. self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  120. self.contents.draw_text(x + 160, y, 88, 32, item.price.to_s, 2)
  121. if item.price2 <= $game_variables[1]
  122. self.contents.font.color = Color.new(255, 128, 255, 255)
  123. else
  124. self.contents.font.color = disabled_color
  125. end
  126. self.contents.draw_text(x + 240, y, 88, 32, item.price2.to_s, 2)
  127. end
  128. end
  129. class Window_ShopNumber < Window_Base
  130. #--------------------------------------------------------------------------
  131. # ● 初始化对像
  132. #--------------------------------------------------------------------------
  133. def initialize
  134. super(0, 128, 368, 352)
  135. self.contents = Bitmap.new(width - 32, height - 32)
  136. @item = nil
  137. @max = 1
  138. @price = 0
  139. @price2 = 0
  140. @number = 1
  141. end
  142. #--------------------------------------------------------------------------
  143. # ● 设置物品、最大个数、价格、價格2
  144. #--------------------------------------------------------------------------
  145. def set(item, max, price, price2)
  146. @item = item
  147. @max = max
  148. @price = price
  149. @number = 1
  150. @price2 = price2
  151. refresh
  152. end
  153. #--------------------------------------------------------------------------
  154. # ● 被输入的件数设置
  155. #--------------------------------------------------------------------------
  156. def number
  157. return @number
  158. end
  159. #--------------------------------------------------------------------------
  160. # ● 刷新
  161. #--------------------------------------------------------------------------
  162. def refresh
  163. self.contents.clear
  164. draw_item_name(@item, 4, 96)
  165. self.contents.font.color = normal_color
  166. self.contents.draw_text(272, 96, 32, 32, "×")
  167. self.contents.draw_text(308, 96, 24, 32, @number.to_s, 2)
  168. self.cursor_rect.set(304, 96, 32, 32)
  169. # 描绘合计价格和货币单位
  170. domination = $data_system.words.gold
  171. cx = contents.text_size(domination).width
  172. total_price = @price * @number
  173. total_price2 = @price2 * @number
  174. self.contents.font.color = normal_color
  175. self.contents.draw_text(4, 160, 328-cx-2, 32, total_price.to_s, 2)
  176. self.contents.font.color = system_color
  177. self.contents.draw_text(332-cx, 160, cx, 32, domination, 2)
  178. self.contents.font.color = Color.new(255, 128, 255, 255)
  179. self.contents.draw_text(4, 192, 260, 32, total_price2.to_s, 2)
  180. self.contents.font.color = system_color
  181. self.contents.draw_text(268, 192, 64, 32, "元宝", 2)
  182. end
  183. end
  184. #==============================================================================
  185. # ■ Scene_Shop
  186. #------------------------------------------------------------------------------
  187. #  处理商店画面的类。
  188. #==============================================================================
  189. class Scene_Shop
  190. #--------------------------------------------------------------------------
  191. # ● 主处理
  192. #--------------------------------------------------------------------------
  193. def main
  194. # 生成帮助窗口
  195. @help_window = Window_Help.new
  196. # 生成指令窗口
  197. @command_window = Window_ShopCommand.new
  198. # 生成金钱窗口
  199. @gold_window = Window_Gold2.new
  200. @gold_window.x = 480
  201. @gold_window.y = 0
  202. # 生成时间窗口
  203. @dummy_window = Window_Base.new(0, 128, 640, 352)
  204. # 生成购买窗口
  205. @buy_window = Window_ShopBuy.new($game_temp.shop_goods)
  206. @buy_window.active = false
  207. @buy_window.visible = false
  208. @buy_window.help_window = @help_window
  209. # 生成卖出窗口
  210. @sell_window = Window_ShopSell.new
  211. @sell_window.active = false
  212. @sell_window.visible = false
  213. @sell_window.help_window = @help_window
  214. # 生成数量输入窗口
  215. @number_window = Window_ShopNumber.new
  216. @number_window.active = false
  217. @number_window.visible = false
  218. # 生成状态窗口
  219. @status_window = Window_ShopStatus.new
  220. @status_window.visible = false
  221. # 执行过渡
  222. Graphics.transition
  223. # 主循环
  224. loop do
  225. # 刷新游戏画面
  226. Graphics.update
  227. # 刷新输入信息
  228. Input.update
  229. # 刷新画面
  230. update
  231. # 如果画面切换的话就中断循环
  232. if $scene != self
  233. break
  234. end
  235. end
  236. # 准备过渡
  237. Graphics.freeze
  238. # 释放窗口
  239. @help_window.dispose
  240. @command_window.dispose
  241. @gold_window.dispose
  242. @dummy_window.dispose
  243. @buy_window.dispose
  244. @sell_window.dispose
  245. @number_window.dispose
  246. @status_window.dispose
  247. end
  248. #--------------------------------------------------------------------------
  249. # ● 刷新画面
  250. #--------------------------------------------------------------------------
  251. def update
  252. # 刷新窗口
  253. @help_window.update
  254. @command_window.update
  255. @gold_window.update
  256. @dummy_window.update
  257. @buy_window.update
  258. @sell_window.update
  259. @number_window.update
  260. @status_window.update
  261. # 指令窗口激活的情况下: 调用 update_command
  262. if @command_window.active
  263. update_command
  264. return
  265. end
  266. # 购买窗口激活的情况下: 调用 update_buy
  267. if @buy_window.active
  268. update_buy
  269. return
  270. end
  271. # 卖出窗口激活的情况下: 调用 update_sell
  272. if @sell_window.active
  273. update_sell
  274. return
  275. end
  276. # 个数输入窗口激活的情况下: 调用 update_number
  277. if @number_window.active
  278. update_number
  279. return
  280. end
  281. end
  282. #--------------------------------------------------------------------------
  283. # ● 刷新画面 (指令窗口激活的情况下)
  284. #--------------------------------------------------------------------------
  285. def update_command
  286. # 按下 B 键的情况下
  287. if Input.trigger?(Input::B)
  288. # 演奏取消 SE
  289. $game_system.se_play($data_system.cancel_se)
  290. # 切换到地图画面
  291. $scene = Scene_Map.new
  292. return
  293. end
  294. # 按下 C 键的情况下
  295. if Input.trigger?(Input::C)
  296. # 命令窗口光标位置分支
  297. case @command_window.index
  298. when 0 # 购买
  299. # 演奏确定 SE
  300. $game_system.se_play($data_system.decision_se)
  301. # 窗口状态转向购买模式
  302. @command_window.active = false
  303. @dummy_window.visible = false
  304. @buy_window.active = true
  305. @buy_window.visible = true
  306. @buy_window.refresh
  307. @status_window.visible = true
  308. when 1 # 卖出
  309. # 演奏确定 SE
  310. $game_system.se_play($data_system.decision_se)
  311. # 窗口状态转向卖出模式
  312. @command_window.active = false
  313. @dummy_window.visible = false
  314. @sell_window.active = true
  315. @sell_window.visible = true
  316. @sell_window.refresh
  317. when 2 # 取消
  318. # 演奏确定 SE
  319. $game_system.se_play($data_system.decision_se)
  320. # 切换到地图画面
  321. $scene = Scene_Map.new
  322. end
  323. return
  324. end
  325. end
  326. #--------------------------------------------------------------------------
  327. # ● 刷新画面 (购买窗口激活的情况下)
  328. #--------------------------------------------------------------------------
  329. def update_buy
  330. # 设置状态窗口的物品
  331. @status_window.item = @buy_window.item
  332. # 按下 B 键的情况下
  333. if Input.trigger?(Input::B)
  334. # 演奏取消 SE
  335. $game_system.se_play($data_system.cancel_se)
  336. # 窗口状态转向初期模式
  337. @command_window.active = true
  338. @dummy_window.visible = true
  339. @buy_window.active = false
  340. @buy_window.visible = false
  341. @status_window.visible = false
  342. @status_window.item = nil
  343. # 删除帮助文本
  344. @help_window.set_text("")
  345. return
  346. end
  347. # 按下 C 键的情况下
  348. if Input.trigger?(Input::C)
  349. # 获取物品
  350. @item = @buy_window.item
  351. # 物品无效的情况下、或者价格在所持金以上的情况下
  352. if @item == nil or @item.price > $game_party.gold or @item.price2 > $game_variables[1]
  353. # 演奏冻结 SE
  354. $game_system.se_play($data_system.buzzer_se)
  355. return
  356. end
  357. # 获取物品所持数
  358. case @item
  359. when RPG::Item
  360. number = $game_party.item_number(@item.id)
  361. when RPG::Weapon
  362. number = $game_party.weapon_number(@item.id)
  363. when RPG::Armor
  364. number = $game_party.armor_number(@item.id)
  365. end
  366. # 如果已经拥有了 99 个情况下
  367. if number == 99
  368. # 演奏冻结 SE
  369. $game_system.se_play($data_system.buzzer_se)
  370. return
  371. end
  372. # 演奏确定 SE
  373. $game_system.se_play($data_system.decision_se)
  374. # 计算可以最多购买的数量
  375. max = @item.price == 0 ? 99 : $game_party.gold / @item.price
  376. max2 = @item.price2 == 0 ? 99 : $game_variables[1] / @item.price2
  377. if max2 > max
  378. max = [max, 99 - number].min
  379. else
  380. max = [max2, 99 - number].min
  381. end
  382. # 窗口状态转向数值输入模式
  383. @buy_window.active = false
  384. @buy_window.visible = false
  385. @number_window.set(@item, max, @item.price, @item.price2)
  386. @number_window.active = true
  387. @number_window.visible = true
  388. end
  389. end
  390. #--------------------------------------------------------------------------
  391. # ● 画面更新 (卖出窗口激活的情况下)
  392. #--------------------------------------------------------------------------
  393. def update_sell
  394. # 按下 B 键的情况下
  395. if Input.trigger?(Input::B)
  396. # 演奏取消 SE
  397. $game_system.se_play($data_system.cancel_se)
  398. # 窗口状态转向初期模式
  399. @command_window.active = true
  400. @dummy_window.visible = true
  401. @sell_window.active = false
  402. @sell_window.visible = false
  403. @status_window.item = nil
  404. # 删除帮助文本
  405. @help_window.set_text("")
  406. return
  407. end
  408. # 按下 C 键的情况下
  409. if Input.trigger?(Input::C)
  410. # 获取物品
  411. @item = @sell_window.item
  412. # 设置状态窗口的物品
  413. @status_window.item = @item
  414. # 物品无效的情况下、或者价格为 0 (不能卖出) 的情况下
  415. if @item == nil or @item.price == 0
  416. # 演奏冻结 SE
  417. $game_system.se_play($data_system.buzzer_se)
  418. return
  419. end
  420. # 演奏确定 SE
  421. $game_system.se_play($data_system.decision_se)
  422. # 获取物品的所持数
  423. case @item
  424. when RPG::Item
  425. number = $game_party.item_number(@item.id)
  426. when RPG::Weapon
  427. number = $game_party.weapon_number(@item.id)
  428. when RPG::Armor
  429. number = $game_party.armor_number(@item.id)
  430. end
  431. # 最大卖出个数 = 物品的所持数
  432. max = number
  433. # 窗口状态转向个数输入模式
  434. @sell_window.active = false
  435. @sell_window.visible = false
  436. @number_window.set(@item, max, @item.price / 2, @item.price2 / 2)
  437. @number_window.active = true
  438. @number_window.visible = true
  439. @status_window.visible = true
  440. end
  441. end
  442. #--------------------------------------------------------------------------
  443. # ● 刷新画面 (个数输入窗口激活的情况下)
  444. #--------------------------------------------------------------------------
  445. def update_number
  446. # 按下 B 键的情况下
  447. if Input.trigger?(Input::B)
  448. # 演奏取消 SE
  449. $game_system.se_play($data_system.cancel_se)
  450. # 设置个数输入窗口为不活动·非可视状态
  451. @number_window.active = false
  452. @number_window.visible = false
  453. # 命令窗口光标位置分支
  454. case @command_window.index
  455. when 0 # 购买
  456. # 窗口状态转向购买模式
  457. @buy_window.active = true
  458. @buy_window.visible = true
  459. when 1 # 卖出
  460. # 窗口状态转向卖出模式
  461. @sell_window.active = true
  462. @sell_window.visible = true
  463. @status_window.visible = false
  464. end
  465. return
  466. end
  467. # 按下 C 键的情况下
  468. if Input.trigger?(Input::C)
  469. # 演奏商店 SE
  470. $game_system.se_play($data_system.shop_se)
  471. # 设置个数输入窗口为不活动·非可视状态
  472. @number_window.active = false
  473. @number_window.visible = false
  474. # 命令窗口光标位置分支
  475. case @command_window.index
  476. when 0 # 购买
  477. # 购买处理
  478. $game_party.lose_gold(@number_window.number * @item.price)
  479. $game_variables[1] -= (@number_window.number * @item.price2)
  480. case @item
  481. when RPG::Item
  482. $game_party.gain_item(@item.id, @number_window.number)
  483. when RPG::Weapon
  484. $game_party.gain_weapon(@item.id, @number_window.number)
  485. when RPG::Armor
  486. $game_party.gain_armor(@item.id, @number_window.number)
  487. end
  488. # 刷新各窗口
  489. @gold_window.refresh
  490. @buy_window.refresh
  491. @status_window.refresh
  492. # 窗口状态转向购买模式
  493. @buy_window.active = true
  494. @buy_window.visible = true
  495. when 1 # 卖出
  496. # 卖出处理
  497. $game_party.gain_gold(@number_window.number * (@item.price / 2))
  498. $game_variables[1] += (@number_window.number * (@item.price2 / 2))
  499. case @item
  500. when RPG::Item
  501. $game_party.lose_item(@item.id, @number_window.number)
  502. when RPG::Weapon
  503. $game_party.lose_weapon(@item.id, @number_window.number)
  504. when RPG::Armor
  505. $game_party.lose_armor(@item.id, @number_window.number)
  506. end
  507. # 刷新各窗口
  508. @gold_window.refresh
  509. @sell_window.refresh
  510. @status_window.refresh
  511. # 窗口状态转向卖出模式
  512. @sell_window.active = true
  513. @sell_window.visible = true
  514. @status_window.visible = false
  515. end
  516. return
  517. end
  518. end
  519. end
复制代码


‘‘──[email protected]于2012-5-5 19:50补充以下内容

我是莱鸟,可怜可怜吧 ~~~~~~~~~~我是脚本盲,
’’


‘‘──[email protected]于2012-5-5 19:56补充以下内容

变量的话是$game_variables,i是变量的序号,将相应地方进行更改就可以了
我找了一个多小时也没找到
’’

评分

参与人数 1星屑 -10 收起 理由
忧雪の伤 -10 code 费用

查看全部评分

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-11-30 12:02

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表