DXRubyFramework0.0.2と弾幕ゲー
高速コマンド処理機能を追加して、アニメーションを強化、メソッドを整理したバージョンとなっている。
性能は上々。
CPUを800MHzにクロックダウンして動かしている画像。
見にくいが35%、2640 Objectsだ。
一応、全ての弾に対して自機との矩形衝突判定をして、当たった弾を消している。
消え方が変なのは弾の軌道を回転させているからで、0.0.1ではこういうことをしようとするとRubyで書く必要があって大変遅かったから、シンプルな弾幕が作れる程度のコマンドをCで処理できるようにした。
ようやく動くようになってきたところなのもあって、公開はもう少し先になる。
続きにソースを置いておく。
使い方は基本的には0.0.1とあまり変わらない。
require 'dxruby' require 'dxrubyfw' require 'command' class Shot < Sprite @@image = Image.load("image/enemyshot1.png") @@command = Command.generate { rotate 0.5 wait 1 } def initialize(x, y, angle, speed) self.x = x - @@image.width / 2 self.y = y - @@image.height / 2 self.angle = angle self.speed = speed self.image = @@image self.start_command @@command self.range = [-20, -20, 640, 480] self.collision = [0,0,15,15] self.collision_enable = true end def out self.delete end def hit(o) self.delete end end class Enemy2 < Sprite @@anime_image = Image.loadToArray("image/enemy2.png", 4, 1) @@anime_pattern = { :start => [15, [0,1,2,3]] } @@command = Command.generate { update wait 1 } def initialize self.x = 100 self.y = 100 self.animation_image = @@anime_image self.animation_pattern = @@anime_pattern self.start_animation(:start) self.start_command(@@command) @angle = 0 end def update 16.times do |i| Objects.push(Shot.new(self.x+64, self.y+32, @angle + i * 22.5, 2)) end @angle += 16 if @angle > 360 @angle = 0 end end end class MyShip < Sprite @@anime_image = Image.load_to_array("image/myship.png", 4, 1) @@command = Command.generate { update wait 1 } def initialize self.x = 300 self.y = 200 self.animation_image = @@anime_image self.start_animation([15, [0,1,2,3]]) self.start_command(@@command) self.collision = [0,0,31,31] self.collision_enable = true end def update self.x += Input.x self.y += Input.y end end Objects = [] Objects.push(Enemy2.new) M = MyShip.new font = Font.new(32) Window.loop do Sprite.update(Objects) Sprite.update([M]) Sprite.check(M, Objects) Sprite.clean(Objects) Sprite.draw(Objects) Sprite.draw([M]) Window.drawFont(0, 0, Window.getLoad.to_i.to_s + " %", font, :z => 100.0) Window.drawFont(0, 32, Objects.size.to_s + " objects", font, :z => 100.0) end