#Copyright (C) 2006 by Han Dao # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #This is the game SpaceAceFighter #You can contact the author at wikipediankiba@gmail.com class Controller def initialize main @main = main @warrior = Fighter.new @weapon = Weapon.new @target = Enemy.new @delete = CollideDetector.new(@weapon,@warrior,@target) controller() end def controller q = Rubygame::Queue.instance() x = 0 while 1 q.get.each do |e| case e when Rubygame::KeyDownEvent case e.key when Rubygame::K_ESCAPE exit when Rubygame::K_LEFT x = -3 when Rubygame::K_RIGHT x = 3 when Rubygame::K_S x = 0 when Rubygame::K_SPACE @weapon.generate(@warrior.x,@warrior.y,true) end end end execute(x) end end def execute x @main.screen.flip() @main.background.blit(@main.screen,[0,0]) @warrior.pos(x) @warrior.draw(@main.screen) @weapon.movement() @weapon.draw(@main.screen) enemy() determine = @delete.detect() if determine == false GameOver.new(@main) exit end end def enemy if rand(51) == 0 @target.generate(rand(801),0) end if rand(21) == 0 x , y = @target.return if Integer === x @weapon.generate(x,y) end end @target.draw(@main.screen) @target.movement() end end