免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 25438 | 回复: 10
打印 上一主题 下一主题

ruby 也能开发游戏 [复制链接]

论坛徽章:
27
水瓶座
日期:2014-08-22 21:06:34程序设计版块每日发帖之星
日期:2015-11-25 06:20:0015-16赛季CBA联赛之新疆
日期:2015-12-19 19:05:48IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:3315-16赛季CBA联赛之上海
日期:2016-04-15 19:51:31程序设计版块每日发帖之星
日期:2016-04-17 06:23:29程序设计版块每日发帖之星
日期:2016-04-23 06:20:00程序设计版块每日发帖之星
日期:2016-05-26 06:20:00每日论坛发贴之星
日期:2016-05-26 06:20:0015-16赛季CBA联赛之辽宁
日期:2017-02-16 23:59:47
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-07-11 14:41 |只看该作者 |倒序浏览
https://github.com/belen-albeza/space-shooter
Running
=======

You'll need the gosu gem:
$ gem install gosu

Then run the main.rb file:
$ruby main.rb

论坛徽章:
27
水瓶座
日期:2014-08-22 21:06:34程序设计版块每日发帖之星
日期:2015-11-25 06:20:0015-16赛季CBA联赛之新疆
日期:2015-12-19 19:05:48IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:3315-16赛季CBA联赛之上海
日期:2016-04-15 19:51:31程序设计版块每日发帖之星
日期:2016-04-17 06:23:29程序设计版块每日发帖之星
日期:2016-04-23 06:20:00程序设计版块每日发帖之星
日期:2016-05-26 06:20:00每日论坛发贴之星
日期:2016-05-26 06:20:0015-16赛季CBA联赛之辽宁
日期:2017-02-16 23:59:47
2 [报告]
发表于 2013-07-11 14:45 |只看该作者
  1. require 'singleton'

  2. module Engine
  3.   class Game < Gosu::Window
  4.     include Singleton
  5.    
  6.     ScreenWidth = 550
  7.     ScreenHeight = 600
  8.     FadingTime = 1000

  9.     # Constructor. Setups the video mode and creates a window (60 fps)
  10.     def initialize      
  11.       super(ScreenWidth, ScreenHeight, false)
  12.       self.caption = "Space Shooter"
  13.       @@sprite_collection = SpriteCollection.new
  14.       @@images = Hash.new
  15.       @@fonts = Hash.new      
  16.       load_images
  17.       load_fonts
  18.       
  19.       @@img_fade = @@images["black"]
  20.       @@fading_off = false
  21.       @@fading_on = false
  22.       @@end_fade = 0
  23.       @@start_fade = 0
  24.       
  25.       @@change_game_state = nil
  26.       @@game_state = MenuState.new
  27.     end

  28.     # Returns a hash map with the images collection
  29.     def Game.images
  30.       @@images
  31.     end
  32.    
  33.     # Returns a hash map with the fonts collection
  34.     def Game.fonts
  35.       @@fonts
  36.     end
  37.    
  38.     # Returns a hash map with the sprite lists
  39.     def Game.sprites
  40.       @@sprite_collection.sprites
  41.     end
  42.    
  43.     # Returns the sprite collection
  44.     def Game.sprite_collection
  45.       @@sprite_collection
  46.     end
  47.    
  48.     # Returns the current game state
  49.     def Game.game_state
  50.       @@game_state
  51.     end
  52.    
  53.     # Changes to another game state
  54.     def Game.game_state=(st)
  55.       @@change_game_state = st.new
  56.       Game.fade_off(FadingTime)
  57.     end
  58.    
  59.     # Quits game
  60.     def Game.quit
  61.       self.instance.close
  62.     end
  63.    
  64.     # Starts a fade off transition
  65.     def Game.fade_off(time)
  66.       return if Game.fading?
  67.       @@start_fade = Gosu::milliseconds
  68.       @@end_fade = @@start_fade + time
  69.       @@fading_off = true
  70.     end
  71.    
  72.     # Starts a fade on transition
  73.     def Game.fade_on(time)
  74.       return if Game.fading?
  75.       @@start_fade = Gosu::milliseconds
  76.       @@end_fade = @@start_fade + time
  77.       @@fading_on = true
  78.     end
  79.    
  80.     # Returns whether there is a fade running or not
  81.     def Game.fading?
  82.       @@fading_off or @@fading_on
  83.     end
  84.    
  85.     # Ends fade transitions
  86.     def Game.end_fade!
  87.       @@fading_off = false
  88.       @@fading_on = false
  89.     end

  90.     # Updates the game logic. Gets called automatically by Gosu each frame
  91.     def update
  92.       @@game_state.update unless Game.fading?      
  93.       
  94.       # update fading
  95.       Game.end_fade! if Gosu::milliseconds >= @@end_fade and Game.fading?
  96.       
  97.       #update changing between game states
  98.       if @@change_game_state and not Game.fading?
  99.         @@game_state = @@change_game_state
  100.         @@change_game_state = nil
  101.         Game.fade_on(FadingTime)
  102.       end
  103.     end

  104.     # Draws the game entities on the screen. Gets called automatically by Gosu each frame
  105.     def draw
  106.       @@game_state.draw

  107.       if Game.fading?
  108.         delta = (Gosu::milliseconds - @@start_fade).to_f / (@@end_fade - @@start_fade)
  109.         alpha = @@fading_off ? delta : 1 - delta
  110.         @@img_fade.draw(0, 0, ZOrder::Fade, 1, 1, Gosu::Color.new((alpha * 0xff).to_i, 0xff, 0xff, 0xff))
  111.       end
  112.     end

  113.     # Gets called automatically by Gosu when a button is released
  114.     def button_up(id)
  115.       @@game_state.button_up(id)
  116.     end

  117.     # Gets called automatically by Gosu when a button is pressed
  118.     def button_down(id)
  119.       @@game_state.button_down(id)
  120.     end

  121.     # Loads all the images and stores them into the images hash map
  122.     def load_images
  123.       @@images["black"] = Gosu::Image.new(self, "gfx/black.png", true)
  124.       @@images["background"] = Gosu::Image.new(self, "gfx/background.png", true)
  125.       @@images["captain"] = Gosu::Image.new(self, "gfx/captain.png", false)
  126.       @@images["laser"] = Gosu::Image.new(self, "gfx/laser.png", false)
  127.       @@images["alien"] = Gosu::Image.load_tiles(self, "gfx/alien.png", 48, 42, false)
  128.       @@images["energy full"] = Gosu::Image.new(self, "gfx/energy_full.png", false)
  129.       @@images["energy low"] = Gosu::Image.new(self, "gfx/energy_low.png", false)
  130.       @@images["hud"] = Gosu::Image.new(self, "gfx/hud.png", false)
  131.       @@images["boom"] = Gosu::Image.new(self, "gfx/boom.png", false)
  132.       @@images["gameover"] = Gosu::Image.new(self, "gfx/game_over.png", false)
  133.       @@images["logo"] = Gosu::Image.new(self, "gfx/game_logo.png", false)
  134.       @@images["credits"] = Gosu::Image.new(self, "gfx/credits.png", false)
  135.     end
  136.    
  137.     # Loads all fonts needed and stores them into the fonts hash map
  138.     def load_fonts
  139.       @@fonts["menu"] = Gosu::Font.new(self, "Courier", 40)
  140.       @@fonts["score"] = Gosu::Font.new(self, "Courier", 50)
  141.       @@fonts["small"] = Gosu::Font.new(self, "Courier", 30)
  142.     end

  143.   end

  144. end
复制代码

论坛徽章:
5
丑牛
日期:2014-01-21 08:26:26卯兔
日期:2014-03-11 06:37:43天秤座
日期:2014-03-25 08:52:52寅虎
日期:2014-04-19 11:39:48午马
日期:2014-08-06 03:56:58
3 [报告]
发表于 2013-07-12 12:25 |只看该作者
最深深深滴支持楼主!

论坛徽章:
27
水瓶座
日期:2014-08-22 21:06:34程序设计版块每日发帖之星
日期:2015-11-25 06:20:0015-16赛季CBA联赛之新疆
日期:2015-12-19 19:05:48IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:31IT运维版块每日发帖之星
日期:2015-12-25 06:20:3315-16赛季CBA联赛之上海
日期:2016-04-15 19:51:31程序设计版块每日发帖之星
日期:2016-04-17 06:23:29程序设计版块每日发帖之星
日期:2016-04-23 06:20:00程序设计版块每日发帖之星
日期:2016-05-26 06:20:00每日论坛发贴之星
日期:2016-05-26 06:20:0015-16赛季CBA联赛之辽宁
日期:2017-02-16 23:59:47
4 [报告]
发表于 2013-07-12 13:03 |只看该作者
pitonas 发表于 2013-07-12 12:25
最深深深滴支持楼主!
老大,你是混哪个场的,到处都看到你

论坛徽章:
7
戌狗
日期:2013-12-15 20:43:38技术图书徽章
日期:2014-03-05 01:33:12技术图书徽章
日期:2014-03-15 20:31:17未羊
日期:2014-03-25 23:48:20丑牛
日期:2014-04-07 22:37:44巳蛇
日期:2014-04-11 21:58:0915-16赛季CBA联赛之青岛
日期:2016-03-17 20:36:13
5 [报告]
发表于 2013-07-16 00:12 |只看该作者
支持楼主!

论坛徽章:
31
CU大牛徽章
日期:2013-03-13 15:15:08CU大牛徽章
日期:2013-05-20 10:46:18CU大牛徽章
日期:2013-05-20 10:46:25CU大牛徽章
日期:2013-05-20 10:46:31CU大牛徽章
日期:2013-05-20 10:46:38CU大牛徽章
日期:2013-05-20 10:46:44CU大牛徽章
日期:2013-09-18 15:16:55CU大牛徽章
日期:2013-09-18 15:18:22CU大牛徽章
日期:2013-09-18 15:18:43CU十二周年纪念徽章
日期:2013-10-24 15:41:34丑牛
日期:2013-12-01 10:11:07水瓶座
日期:2014-01-15 08:47:25
6 [报告]
发表于 2014-01-28 10:30 |只看该作者
这倒是个新鲜领域。。

论坛徽章:
42
19周年集字徽章-周
日期:2019-10-14 14:35:31平安夜徽章
日期:2015-12-26 00:06:30数据库技术版块每日发帖之星
日期:2015-12-01 06:20:002015亚冠之首尔
日期:2015-11-04 22:25:43IT运维版块每日发帖之星
日期:2015-08-17 06:20:00寅虎
日期:2014-06-04 16:25:27狮子座
日期:2014-05-12 11:00:00辰龙
日期:2013-12-20 17:07:19射手座
日期:2013-10-24 21:01:23CU十二周年纪念徽章
日期:2013-10-24 15:41:34IT运维版块每日发帖之星
日期:2016-01-27 06:20:0015-16赛季CBA联赛之新疆
日期:2016-06-07 14:10:01
7 [报告]
发表于 2014-06-04 10:34 |只看该作者
大名鼎鼎的RPGmaker系列都是用的RGSS引擎
ruby的方言

论坛徽章:
3
寅虎
日期:2013-11-27 07:53:29申猴
日期:2014-09-12 09:24:152015年迎新春徽章
日期:2015-03-04 09:48:31
8 [报告]
发表于 2014-06-05 17:22 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
1
狮子座
日期:2014-08-08 13:42:18
9 [报告]
发表于 2014-06-17 13:16 |只看该作者
支持,赞一个!:wink:

论坛徽章:
1
狮子座
日期:2014-08-08 13:42:18
10 [报告]
发表于 2014-06-17 13:18 |只看该作者
回复 8# Sevk


    大侠,你在Ubuntu上装成功了没?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP