Changeset 20291 for lang/ruby

Show
Ignore:
Timestamp:
09/30/08 18:08:13 (2 months ago)
Author:
authorNari
Message:

もっとクリーンなnarioへ...もっとクリーンな日本へ

Location:
lang/ruby/nario
Files:
6 added
5 removed
13 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/nario/nario.rb

    r20276 r20291  
    1616require 'optparse' 
    1717 
    18 @gc_burden_mode = false 
    19 @test_mode = false 
     18$GC_BURDEN_MODE = false 
     19$TEST_MODE = false 
    2020opt = OptionParser.new 
    2121opt.version = "1.0.0" 
    22 opt.on('-g', '--gc', "To stop the world. and gc stop grafical mode :)") {|v| @gc_burden_mode = true} 
    23 opt.on('-t', '--test', "test mode") {|v| @test_mode = true} 
     22opt.on('-g', '--gc', "To stop the world. and gc stop grafical mode :)") {|v| $GC_BURDEN_MODE = true} 
     23opt.on('-t', '--test', "test mode") {|v| $TEST_MODE = true} 
    2424opt.parse!(ARGV) 
    2525 
    2626# burden to nario and gc :) 
    27 if @gc_burden_mode 
     27if $GC_BURDEN_MODE 
    2828  @@arry = [] 
    2929  3000000.times{@@arry << Array.new} 
     
    4141    @@skip += 1 
    4242  end 
    43 else 
    44   def gc_start(screen) 
    45   end 
    4643end 
    4744 
    48 require 'gamestart' unless @test_mode 
    49 require 'test' if @test_mode 
     45require 'gamestart' unless $TEST_MODE 
     46require 'test' if $TEST_MODE 
  • lang/ruby/nario/nario/factor.rb

    r17193 r20291  
    9898    is_or_dead = (@is_dead or collide.is_dead) 
    9999    # debug 
    100     #pp event if event[1].to_s == "collide_nario_head" 
     100    puts "event! #{self}.#{event[0]} <--> #{collide}.#{event[1]}" if $DEBUG 
    101101    collide.send(event[0], self) if collide.methods.map{|a| a.to_s}.include? event[0].to_s and !is_or_dead 
    102102    send(event[1], collide) if methods.map{|b| b.to_s}.include? event[1].to_s and !is_or_dead 
  • lang/ruby/nario/nario/gamestart.rb

    r20276 r20291  
    1616class Input 
    1717  define_key SDL::Key::ESCAPE, :exit 
     18  define_key SDL::Key::Q, :exit 
    1819  define_key SDL::Key::LEFT, :left 
    1920  define_key SDL::Key::RIGHT, :right 
     
    2324  define_key SDL::Key::A, :a 
    2425  define_key SDL::Key::B, :b 
     26  define_key SDL::Key::S, :start 
     27  define_key SDL::Key::G, :go 
    2528end 
    2629 
     
    2932  world = {} 
    3033  world[:title] = ::Scene::Title.new { success :map1_1 } 
    31   world[:title].build_map &Map::TITLE 
     34  world[:title].build_scene &Map::TITLE 
    3235  world[:map1_1] = ::Scene::FlowWorld.new { success :title; miss :title } 
    33   world[:map1_1].build_map &Map::MAP1_1 
     36  world[:map1_1].build_scene &Map::MAP1_1 
    3437  world 
    3538end 
     
    3942  SDL::TTF.init 
    4043  SDL.set_video_mode(Scene::SCREEN_WIDTH, Scene::SCREEN_HIGHT, 16, SDL::HWSURFACE|SDL::DOUBLEBUF) 
     44end 
     45 
     46def stop?(input, screen) 
     47  if input.start 
     48    screen.put(SDL::Surface.load("nario/image/stop.bmp"), 270, 270) 
     49    screen.update_rect(0, 0, Scene::SCREEN_WIDTH, Scene::SCREEN_HIGHT) 
     50    @stop = true 
     51  end 
     52  if input.go 
     53    @stop = false 
     54  end 
     55  return @stop 
    4156end 
    4257 
     
    5469    input.poll 
    5570    break if input[:exit] 
     71    redo if stop?(input, screen) 
    5672 
    5773    s_next = scene.act(input) 
     
    5975    scene = world[s_next].rebuild if s_next 
    6076    timer.wait_frame { 
    61       gc_start(screen) 
     77      gc_start if $GC_BURDEN_MODE 
    6278      screen.update_rect(0, 0, Scene::SCREEN_WIDTH, Scene::SCREEN_HIGHT) 
    6379    } 
  • lang/ruby/nario/nario/life.rb

    r17193 r20291  
    159159  autoload :Nario, "life/nario" 
    160160  autoload :Enemy, "life/enemy" 
    161   autoload :Kuribo, "life/kuribo" 
    162   autoload :NokoNoko, "life/nokonoko" 
     161  autoload :Can, "life/can" 
     162  autoload :Dustbin, "life/dustbin" 
    163163  autoload :Carapace, "life/carapace" 
    164164end 
  • lang/ruby/nario/nario/life/carapace.rb

    r17193 r20291  
    2626 
    2727    # collision parts 
    28     def head_range; {:x_range => (@x+@w/2-10)..(@x+@w/2+10), :y_range => (@y+10)..(@y+@h/2), :event => :collide_kuribo_head}; end 
     28    def head_range; {:x_range => (@x+@w/2-10)..(@x+@w/2+10), :y_range => (@y+10)..(@y+@h/2), :event => :collide_can_head}; end 
    2929 
    3030    # collision event 
     
    3232    def collide_nario_right(m); set_direction(1); end 
    3333    def collide_nario_left(m); set_direction(-1); end 
    34     undef collide_kuribo_left 
    35     undef collide_kuribo_right 
     34    undef collide_can_left 
     35    undef collide_can_right 
    3636    undef collide_nokonoko_left 
    3737    undef collide_nokonoko_right 
  • lang/ruby/nario/nario/life/enemy.rb

    r17193 r20291  
    77    alias collide_weakblock_head collide_floor_head 
    88    alias collide_itembox_head collide_weakblock_head 
    9     alias collide_kuribo_left collide_strongblock_left 
    10     alias collide_kuribo_right collide_strongblock_right 
    11     alias collide_nokonoko_left collide_strongblock_left 
    12     alias collide_nokonoko_right collide_strongblock_right 
     9    alias collide_can_left collide_strongblock_left 
     10    alias collide_can_right collide_strongblock_right 
     11    alias collide_dustbin_left collide_strongblock_left 
     12    alias collide_dustbin_right collide_strongblock_right 
    1313    alias collide_pipe_left collide_strongblock_left 
    1414    alias collide_pipe_right collide_strongblock_right 
  • lang/ruby/nario/nario/life/nario.rb

    r17193 r20291  
    2929 
    3030    # collision event 
    31     def collide_kuribo_right(k); @movie_event = :movie_die; end; 
    32     alias collide_kuribo_left collide_kuribo_right 
    33     alias collide_kuribo_foot collide_kuribo_right 
    34     def collide_kuribo_head(k);  force_jump; end 
    35     alias collide_nokonoko_right collide_kuribo_right 
    36     alias collide_nokonoko_left collide_kuribo_left 
    37     alias collide_nokonoko_foot collide_kuribo_foot 
    38     alias collide_nokonoko_head collide_kuribo_head 
     31    def collide_can_right(k); @movie_event = :movie_die; end; 
     32    alias collide_can_left collide_can_right 
     33    alias collide_can_foot collide_can_right 
     34    def collide_can_head(k);  force_jump; end 
     35    alias collide_dustbin_right collide_can_right 
     36    alias collide_dustbin_left collide_can_left 
     37    alias collide_dustbin_foot collide_can_foot 
     38    alias collide_dustbin_head collide_can_head 
    3939    def collide_carapace_right(c); @movie_event = :movie_die if c.violence?; c.x-=10; end; 
    4040    def collide_carapace_left(c); @movie_event = :movie_die if c.violence?; c.x+=10; end; 
  • lang/ruby/nario/nario/map/map1_1.rb

    r20276 r20291  
    6969    goal 9860 
    7070 
    71     enemy Life::Kuribo.new(900, 550) 
    72     enemy Life::Kuribo.new(2000, 550) 
    73     enemy Life::Kuribo.new(2500, 550) 
    74     enemy Life::Kuribo.new(2560, 550) 
    75     enemy Life::Kuribo.new(3830, 200) 
    76     enemy Life::Kuribo.new(3890, 200) 
    77     enemy Life::Kuribo.new(4670, 550) 
    78     enemy Life::Kuribo.new(4730, 550) 
    79     enemy Life::NokoNoko.new(5100, 550) 
    80     enemy Life::Kuribo.new(5430, 550) 
    81     enemy Life::Kuribo.new(5490, 550) 
    82     enemy Life::Kuribo.new(5750, 550) 
    83     enemy Life::Kuribo.new(5810, 550) 
    84     enemy Life::Kuribo.new(6100, 550) 
    85     enemy Life::Kuribo.new(6160, 550) 
    86     enemy Life::Kuribo.new(8300, 550) 
    87     enemy Life::Kuribo.new(8360, 550) 
     71    enemy Life::Can.new(900, 550) 
     72    enemy Life::Can.new(2000, 550) 
     73    enemy Life::Can.new(2500, 550) 
     74    enemy Life::Can.new(2560, 550) 
     75    enemy Life::Can.new(3830, 200) 
     76    enemy Life::Can.new(3890, 200) 
     77    enemy Life::Can.new(4670, 550) 
     78    enemy Life::Can.new(4730, 550) 
     79    enemy Life::Dustbin.new(5100, 550) 
     80    enemy Life::Can.new(5430, 550) 
     81    enemy Life::Can.new(5490, 550) 
     82    enemy Life::Can.new(5750, 550) 
     83    enemy Life::Can.new(5810, 550) 
     84    enemy Life::Can.new(6100, 550) 
     85    enemy Life::Can.new(6160, 550) 
     86    enemy Life::Can.new(8300, 550) 
     87    enemy Life::Can.new(8360, 550) 
    8888 
    8989    player Life::Nario.new(200, 550) 
  • lang/ruby/nario/nario/material.rb

    r17193 r20291  
    66 
    77    def initialize(x, y, w, h, img=nil, color=nil) 
     8      @fill_mtls = nil 
     9      @img = nil 
    810      img.set_color_key(SDL::SRCCOLORKEY, [255, 255, 255]) if img 
    911      super(x, y, w, h, img) 
  • lang/ruby/nario/nario/material/itemblock.rb

    r17193 r20291  
    2020      @bound_prev_y = @y 
    2121      @frame = 0 
    22       @now_scene.item(@item) 
     22      @now_scene.in(:item, @item) 
    2323      undef :collide_nario_head 
    2424    end 
  • lang/ruby/nario/nario/material/itembox.rb

    r17193 r20291  
    2626      @frame = 0 
    2727      @item = JumpCoin.new(@x + 7, @y - 70) 
    28       @now_scene.item(@item) 
     28      @now_scene.in(:item, @item) 
    2929      @empyt_item = true 
    3030    end 
  • lang/ruby/nario/nario/scene.rb

    r20276 r20291  
    3131      @player = nil 
    3232      @renders = [@flows] 
    33       @deploy_table = [] 
    34     end 
    35  
     33      @lazy_deploys = [] 
     34    end 
     35 
     36    def success(nxt) 
     37      @success = nxt 
     38    end 
     39 
     40    def miss(nxt) 
     41      @miss = nxt 
     42    end 
     43 
     44    def in(type, *args) 
     45      send(type, *args) 
     46    end 
     47     
    3648    def rebuild 
    3749      init 
     
    4052    end 
    4153 
    42     def success(nxt) 
    43       @success = nxt 
    44     end 
    45  
    46     def miss(nxt) 
    47       @miss = nxt 
    48     end 
    49  
    50     def build_map(&block) 
     54    def build_scene(&block) 
    5155      @build_code = block 
    5256      instance_eval(&block) 
     
    5458    end 
    5559 
     60    private 
    5661    def background(bg) 
    5762      code = lambda { 
     
    6065      } 
    6166      @flows << bg 
    62       @deploy_table << [bg, code] 
     67      add_lazydeploy(bg, code) 
    6368    end 
    6469 
     
    7075      @floors << fl 
    7176      @flows << fl 
    72       @deploy_table << [fl, code] 
     77      add_lazydeploy(fl, code) 
    7378    end 
    7479 
     
    8590      } 
    8691      @flows << enemy 
    87       @deploy_table << [enemy, code] 
     92      add_lazydeploy(enemy, code) 
    8893    end 
    8994 
     
    96101      @floors << block 
    97102      @flows << block 
    98       @deploy_table << [block, code] 
     103      add_lazydeploy(block, code) 
    99104    end 
    100105 
     
    105110        @actions << it 
    106111      } 
    107       @deploy_table << [it, code] 
     112      add_lazydeploy(it, code) 
    108113    end 
    109114 
     
    179184    end 
    180185 
    181     def act(input); end 
    182     def render(screen); end 
    183  
    184     private 
    185186    def deploy 
    186       @deploy_table.size.times{|i| 
    187         if @deploy_table[i][0].x < (SCREEN_WIDTH + SCREEN_WIDTH/2) 
    188           @deploy_table[i][1].call 
    189           @deploy_table[i] = nil 
     187      @lazy_deploys.each_with_index {|e, i| 
     188        if e[:object].x < (SCREEN_WIDTH + SCREEN_WIDTH/2) 
     189          e[:deploy_code].call 
     190          @lazy_deploys[i] = nil 
    190191        end 
    191192      } 
    192       @deploy_table.compact! 
     193      @lazy_deploys.compact! 
     194    end 
     195 
     196    def add_lazydeploy(object, deploy_code) 
     197      @lazy_deploys << {:object => object, :deploy_code => deploy_code} 
    193198    end 
    194199 
  • lang/ruby/nario/nario/test.rb

    r17193 r20291  
    103103#  floor Material::Floor.new_color(0, 600, 800, 300, [0xcc, 0x66, 0x66]) 
    104104#  floor Material::Floor.new_color(1000, 600, 800, 300, [0xcc, 0x66, 0x66]) 
    105   enemy Life::Kuribo.new(500, 200) 
     105  enemy Life::Can.new(500, 200) 
    106106  player Life::Nario.new(40, 200) 
    107107} 
     
    121121#  floor Material::Floor.new_color(0, 600, 800, 300, [0xcc, 0x66, 0x66]) 
    122122#  floor Material::Floor.new_color(1000, 600, 800, 300, [0xcc, 0x66, 0x66]) 
    123   enemy Life::Kuribo.new(100, 0) 
    124   enemy Life::Kuribo.new(200, 0) 
    125   enemy Life::Kuribo.new(300, 0) 
    126   enemy Life::Kuribo.new(400, 0) 
    127   enemy Life::Kuribo.new(500, 0) 
    128   enemy Life::Kuribo.new(600, 0) 
    129   enemy Life::Kuribo.new(700, 0) 
     123  enemy Life::Can.new(100, 0) 
     124  enemy Life::Can.new(200, 0) 
     125  enemy Life::Can.new(300, 0) 
     126  enemy Life::Can.new(400, 0) 
     127  enemy Life::Can.new(500, 0) 
     128  enemy Life::Can.new(600, 0) 
     129  enemy Life::Can.new(700, 0) 
    130130  player Life::Nario.new(40, 590) 
    131131} 
     
    152152  block Material::WeakBlock.new(376, 500) 
    153153  block Material::ItemBox.new(420, 500) 
    154   enemy Life::NokoNoko.new(300, 0) 
     154  enemy Life::Dustbin.new(300, 0) 
    155155  player Life::Nario.new(40, 590) 
    156156}