Changeset 20294 for lang/ruby

Show
Ignore:
Timestamp:
09/30/08 19:16:43 (2 months ago)
Author:
authorNari
Message:

refactoring. add DEBUG_PLAYER_MODE.

Location:
lang/ruby/nario
Files:
7 modified

Legend:

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

    r20291 r20294  
    1818$GC_BURDEN_MODE = false 
    1919$TEST_MODE = false 
     20$DEBUG_EVENT_WATCH_MODE = false 
     21$DEBUG_PLAYER_WATCH_MODE = false 
    2022opt = OptionParser.new 
    2123opt.version = "1.0.0" 
    2224opt.on('-g', '--gc', "To stop the world. and gc stop grafical mode :)") {|v| $GC_BURDEN_MODE = true} 
    2325opt.on('-t', '--test', "test mode") {|v| $TEST_MODE = true} 
     26opt.on('--debug-event', "debug: event watch mode") {|v| $DEBUG_EVENT_WATCH_MODE = true} 
     27opt.on('--debug-player', "debug: player watch mode") {|v| $DEBUG_PLAYER_WATCH_MODE = true} 
    2428opt.parse!(ARGV) 
    2529 
  • lang/ruby/nario/nario/factor.rb

    r20291 r20294  
    2424    event = nil 
    2525    return event unless collision_maybe? collide 
    26     return event_call(event, collide) if event = is_collision(foot_range, collide.head_range) 
    27     return event_call(event, collide) if event = is_collision(head_range, collide.foot_range) 
    28     return event_call(event, collide) if event = is_collision(leftside_range, collide.rightside_range) 
    29     return event_call(event, collide) if event = is_collision(rightside_range, collide.leftside_range) 
     26    return event_call(event, collide) if event = have_event_range(foot_range, collide.head_range) 
     27    return event_call(event, collide) if event = have_event_range(head_range, collide.foot_range) 
     28    return event_call(event, collide) if event = have_event_range(leftside_range, collide.rightside_range) 
     29    return event_call(event, collide) if event = have_event_range(rightside_range, collide.leftside_range) 
    3030  end 
    3131 
     
    9595  end 
    9696 
    97   def event_call(event, collide) 
    98     is_or_dead = (@is_dead or collide.is_dead) 
    99     # debug 
    100     puts "event! #{self}.#{event[0]} <--> #{collide}.#{event[1]}" if $DEBUG 
    101     collide.send(event[0], self) if collide.methods.map{|a| a.to_s}.include? event[0].to_s and !is_or_dead 
    102     send(event[1], collide) if methods.map{|b| b.to_s}.include? event[1].to_s and !is_or_dead 
     97  def event_call(event, other) 
     98    is_or_dead = (@is_dead or other.is_dead) 
     99    puts "event! #{self.class}\##{event[:self_event]} <--> #{other.class}\##{event[:other_event]}" if $DEBUG_EVENT_WATCH_MODE 
     100    other.send(event[:self_event], self) if other.methods.map{|a| a.to_s}.include? event[:self_event].to_s and !is_or_dead 
     101    send(event[:other_event], other) if methods.map{|b| b.to_s}.include? event[:other_event].to_s and !is_or_dead 
    103102  end 
    104103 
    105   def is_collision(self_r, collide_r) 
     104  def have_event_range(self_range, other_range) 
    106105    e = false 
    107     return e unless self_r and collide_r 
    108     self_r[:x_range].each{|i| break e = true if collide_r[:x_range].include? i} 
     106    return e unless self_range and other_range 
     107    self_range[:x_range].each{|i| break e = true if other_range[:x_range].include? i} 
    109108    return e unless e 
    110109    e = false 
    111     self_r[:y_range].each{|i| break e = true if collide_r[:y_range].include? i} 
    112     [self_r[:event], collide_r[:event]] if e 
     110    self_range[:y_range].each{|i| break e = true if other_range[:y_range].include? i} 
     111    {:self_event => self_range[:event], :other_event => other_range[:event]} if e 
    113112  end 
    114113 
  • lang/ruby/nario/nario/gamestart.rb

    r20291 r20294  
    4444end 
    4545 
     46@stop = false 
    4647def stop?(input, screen) 
    4748  if input.start 
  • lang/ruby/nario/nario/life.rb

    r20291 r20294  
    9191 
    9292    #collision event 
    93     def collide_floor_head(f); stand_up(f); end 
    94     def collide_floor_left(f); @x = (f.x - @w); @dash_speed = 0; end 
    95     def collide_floor_right(f); @x = f.x + f.w; @dash_speed = 0; end 
     93    def collide_floor_head(f) stand_up(f) end 
     94    def collide_floor_left(f) @x = (f.x - @w); @dash_speed = 0; end 
     95    def collide_floor_right(f) @x = f.x + f.w; @dash_speed = 0; end 
    9696    alias collide_weakblock_head collide_floor_head 
    9797    alias collide_weakblock_left collide_floor_left 
     
    109109 
    110110    private 
    111     # frame % ? == 0;  get ? parameter 
     111    # frame % ? == 0:  get ? parameter 
    112112    def get_dash_frame(dash_speed) 
    113113      step_rate = 4 
  • lang/ruby/nario/nario/life/enemy.rb

    r20291 r20294  
    22  class Enemy < Life 
    33    #collision events 
    4     def collide_strongblock_left(s); set_direction(-1); end 
    5     def collide_strongblock_right(s); set_direction(1); end 
    6     def collide_floor_head(f); stand_up(f); end 
     4    def collide_strongblock_left(s)  set_direction(-1) end 
     5    def collide_strongblock_right(s) set_direction(1)  end 
     6    def collide_floor_head(f)        stand_up(f)       end 
     7 
     8    def collide_carapace_left(c) 
     9      return clash(c) if c.violence? 
     10      collide_strongblock_left(c) 
     11    end 
     12 
     13    def collide_carapace_right(c) 
     14      return clash(c) if c.violence? 
     15      collide_strongblock_right(c) 
     16    end 
     17 
    718    alias collide_weakblock_head collide_floor_head 
    819    alias collide_itembox_head collide_weakblock_head 
     
    1324    alias collide_pipe_left collide_strongblock_left 
    1425    alias collide_pipe_right collide_strongblock_right 
    15     def collide_carapace_left(c); return clash(c) if c.violence?; collide_strongblock_left(c); end; 
    16     def collide_carapace_right(c); return clash(c) if c.violence?; collide_strongblock_right(c); end; 
    1726 
    1827    def clash(carapace) 
  • lang/ruby/nario/nario/life/nario.rb

    r20291 r20294  
    2929 
    3030    # collision event 
    31     def collide_can_right(k); @movie_event = :movie_die; end; 
     31    def collide_can_right(k) @movie_event = :movie_die end 
    3232    alias collide_can_left collide_can_right 
    3333    alias collide_can_foot collide_can_right 
    34     def collide_can_head(k);  force_jump; end 
     34    def collide_can_head(k)  force_jump end 
    3535    alias collide_dustbin_right collide_can_right 
    3636    alias collide_dustbin_left collide_can_left 
    3737    alias collide_dustbin_foot collide_can_foot 
    3838    alias collide_dustbin_head collide_can_head 
    39     def collide_carapace_right(c); @movie_event = :movie_die if c.violence?; c.x-=10; end; 
    40     def collide_carapace_left(c); @movie_event = :movie_die if c.violence?; c.x+=10; end; 
    41     def collide_weakblock_foot(w); force_fall(w); end 
     39    def collide_carapace_right(c) @movie_event = :movie_die if c.violence?; c.x-=10; end 
     40    def collide_carapace_left(c) @movie_event = :movie_die if c.violence?; c.x+=10; end 
     41    def collide_weakblock_foot(w) force_fall(w) end 
    4242    alias collide_itembox_foot collide_weakblock_foot 
    43     def collide_goal_right(c); @is_goal = true; end 
     43    def collide_goal_right(c) @is_goal = true end 
    4444    alias collide_goal_left collide_goal_right 
    4545    alias collide_goal_head collide_goal_right 
    4646    alias collide_goal_foot collide_goal_right 
    47     def collide_pole_left(p); @movie_event = :movie_goal unless @movie_event; @x = p.x-40; end 
     47    def collide_pole_left(p) @movie_event = :movie_goal unless @movie_event; @x = p.x-40; end 
    4848 
    4949    # collision range 
    50     def foot_range; {:x_range => (@x+@w/4)..(@x+@w-@w/4), :y_range => (@y+@h-@h/6)..(@y+@h), :event => :collide_nario_foot}; end 
     50    def foot_range 
     51      {:x_range => (@x+@w/6)..(@x+@w-@w/6), :y_range => (@y+@h-@h/6)..(@y+@h), :event => :collide_nario_foot} 
     52    end 
    5153 
    5254    # relation controller 
  • lang/ruby/nario/nario/scene/flowworld.rb

    r17193 r20294  
    1717    def render(screen) 
    1818      @renders.each{|re| re.each{|o| o.put_screen(screen) if o.x < SCREEN_WIDTH } } 
     19      puts "player: x -> #{@player.x} y -> #{@player.y}" if $DEBUG_PLAYER_WATCH_MODE 
    1920      @player.put_screen(screen) 
    2021    end