Changeset 13479

Show
Ignore:
Timestamp:
06/08/08 16:39:15 (5 years ago)
Author:
gan2
Message:

マップを左クリックしたときにその位置にあるセルをステータスウィンドウに表示するようにした

Location:
lang/ruby/RogueLike/rogue_like
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/RogueLike/rogue_like/chara.rb

    r12627 r13479  
    66 
    77    def initialize(map_x, map_y) 
    8       @map_x = map_x 
    9       @map_y = map_y 
    10       @mode  = :waiting 
     8      @map_x       = map_x 
     9      @map_y       = map_y 
     10      @mode        = :waiting 
    1111      @walk_pathes = [] 
     12      @strength    = 1 
    1213    end 
    1314 
     
    1617    end 
    1718 
    18     def set_map_pos(mx, my) 
    19       @map_x, @map_y = mx, my 
     19    def set_map_pos(map_x, map_y) 
     20      @map_x, @map_y = map_x, map_y 
    2021    end 
    2122 
     
    3334 
    3435    def x=(val) 
    35       @x = val / CELL_W 
     36      @map_x = val / CELL_W 
    3637    end 
    3738 
    3839    def y=(val) 
    39       @y = val / CELL_H 
     40      @map_y = val / CELL_H 
    4041    end 
    4142  end 
  • lang/ruby/RogueLike/rogue_like/config.rb

    r13281 r13479  
    1717  MIN_RECT_SIZE = MIN_ROOM_SIZE + MARGIN_BETWEEN_RECT_AND_ROOM * 2 
    1818 
    19   SCREEN_W = MAP_WINDOW_W + CELL_W * 2 
    20   SCREEN_H = MAP_WINDOW_H + CELL_H * 2 
     19  STATUS_WINDOW_W = CELL_W * 16 
     20  STATUS_WINDOW_H = CELL_H * 16 
     21  STATUS_WINDOW_X = MAP_WINDOW_X + MAP_WINDOW_W + CELL_W 
     22  STATUS_WINDOW_Y = CELL_H 
     23 
     24  SCREEN_W     = MAP_WINDOW_W + STATUS_WINDOW_W + CELL_W * 3 
     25  SCREEN_H     = MAP_WINDOW_H + CELL_H * 2 
    2126  WINDOW_SCALE = 1 
    22   GAME_TITLE = 'Rogue Like' 
     27  GAME_TITLE   = 'Rogue Like' 
    2328 
    2429  INIT_CHARA_NUM = 4 
  • lang/ruby/RogueLike/rogue_like/controller.rb

    r13074 r13479  
    2323 
    2424    def update_playing(model) 
    25       if Input.triggers(:keyboard).include?(:r) 
     25      if Input.triggers(:keyboard).include?(:r)    # restart 
    2626        update_start(model) 
    27       elsif Input.triggers(:keyboard).include?(:d) 
     27      elsif Input.triggers(:keyboard).include?(:d) # debug 
    2828        model.toggle_debug_mode 
    29         # elsif Input.repeatings(:mouse).include?(:left) 
    30         #    
     29      elsif Input.triggers(:keyboard).include?(:p) # pause 
     30         
     31      elsif Input.triggers(:mouse).include?(:left) 
     32        x, y = Input.mouse_location 
     33        model.map.left_click(x, y) 
    3134      end 
    3235      model.activate_charas 
  • lang/ruby/RogueLike/rogue_like/map.rb

    r13281 r13479  
    22  class Map 
    33    attr_accessor :data 
    4     attr_reader :walk_map 
     4    attr_reader :walk_map, :left_click_cell 
    55 
    66    def initialize 
     
    99      @walkable_poses  = nil # 歩行可能な座標を要素に持つ 
    1010      @buildable_poses = nil # 建築可能な座標を要素に持つ 
     11      @left_click_cell = nil 
    1112    end 
    1213 
     
    1415      (MAP_WINDOW_X <= x and x <= MAP_WINDOW_X + MAP_WINDOW_W ) and 
    1516        (MAP_WINDOW_Y <= y and y <= MAP_WINDOW_Y + MAP_WINDOW_H) 
     17    end 
     18 
     19    def left_click(x, y) 
     20      if in?(x, y) 
     21        map_x = (x - MAP_WINDOW_X) / CELL_W 
     22        map_y = (y - MAP_WINDOW_Y) / CELL_H 
     23        @left_click_cell = @data[map_y][map_x] 
     24      end 
    1625    end 
    1726     
  • lang/ruby/RogueLike/rogue_like/model.rb

    r13281 r13479  
    158158    def activate_charas 
    159159      @charas.each_with_index do |chara, idx| 
    160         p chara.mode 
    161160        case chara.mode 
    162161        when :waiting 
     
    164163          @wp.push do 
    165164            start = chara.get_map_pos 
     165            # このやり方だと別々の AI がかたまって同じ行動をするようになるので 
     166            # 向かう場所の探索と経路の探索は別々にした方がよさそう 
    166167            bss   = BStar::Searcher.new(@map.data, start, :room) 
    167168            chara.walk_pathes = bss.search 
  • lang/ruby/RogueLike/rogue_like/view.rb

    r13281 r13479  
    1313    def initialize 
    1414      @textures = { 
    15         :cursor     => Texture.load('images/cursor'), 
    16         :wall       => Texture.load('images/wall'), 
    17         :rect       => Texture.load('images/rect'), 
    18         :room       => Texture.load('images/room'), 
    19         :road       => Texture.load('images/road'), 
    20         :chara      => Texture.load('images/chara'), 
    21         :home       => Texture.load('images/home'), 
    22         :position   => Texture.load('images/position'), 
    23         :map_window => Texture.new(MAP_WINDOW_W, MAP_WINDOW_H), 
    24         :pause_info => Texture.new(SCREEN_W,     SCREEN_H), 
     15        :cursor        => Texture.load('images/cursor'), 
     16        :wall          => Texture.load('images/wall'), 
     17        :rect          => Texture.load('images/rect'), 
     18        :room          => Texture.load('images/room'), 
     19        :road          => Texture.load('images/road'), 
     20        :chara         => Texture.load('images/chara'), 
     21        :home          => Texture.load('images/home'), 
     22        :position      => Texture.load('images/position'), 
     23        :map_window    => Texture.new(MAP_WINDOW_W,    MAP_WINDOW_H), 
     24        :status_window => Texture.new(STATUS_WINDOW_W, STATUS_WINDOW_H), 
     25        :pause_info    => Texture.new(SCREEN_W,        SCREEN_H), 
    2526      } 
    2627      @font = Font.new('fonts/ORANGEKI', FONT_SIZE) 
     
    4243 
    4344      if [:playing].include?(model.state) 
     45        # マップ 
    4446        window = @textures[:map_window] 
    4547        model.map.data.each_with_index do |row, y| 
     
    5355        end 
    5456 
    55         # 繧ォ繝シ繧ス繝ォ縺ョ謠冗判 
     57        # カーソル 
    5658        x, y = Input.mouse_location 
    5759        if model.map.in?(x, y) 
     
    6062          window.render_texture(@textures[:cursor], x, y) 
    6163        end 
     64 
     65        # ステータス 
     66        window = @textures[:status_window] 
     67        bg_color = Color.new(55, 55, 55) 
     68        window.fill_rect(0, 0, STATUS_WINDOW_W, STATUS_WINDOW_H, bg_color) 
     69        if select_image = @textures[model.map.left_click_cell] 
     70          window.render_texture(select_image, CELL_W, CELL_H, :scale_x => 2, :scale_y => 2) 
     71        end 
    6272      end 
    63  
     73       
    6474      screen.clear 
    6575      screen.render_texture(@textures[:map_window], MAP_WINDOW_X, MAP_WINDOW_Y) 
     76      screen.render_texture(@textures[:status_window], STATUS_WINDOW_X, STATUS_WINDOW_Y) 
    6677 
    6778      case model.state