Advertisement
Guest User

IME Sprite Collision by dxruby

a guest
Dec 5th, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.53 KB | None | 0 0
  1. #! ruby -Ku
  2.  
  3. #IME&衝突判定プログラム
  4. #作者 mireiyu
  5.  
  6. require "kconv"
  7. require_relative "dxruby"
  8.  
  9. $xpoint = 0
  10. $ypoint = 0
  11. $font = Font.new( 20,'HGP行書体')
  12.  
  13. class Main_page
  14.  
  15.  def init
  16.   Input::IME.enable=true
  17.  
  18.   @step  = 0
  19.   @step2 = 0
  20.   @step3 = 0
  21.   @step4 = 0
  22.   @step5 = 0
  23.   @imput_sprite = nil
  24.  
  25.  
  26.   @player_image1 = Image.new( 20, 20, [255,255,255,255] )
  27.   @player_image2 = Image.new( 20, 20, [255,66,66,255] )
  28.   @player_sprite = Sprite.new( 320,240,@player_image1)
  29.  
  30.   @str = "あ"
  31.   @image_font = Image.new( $font.getWidth(@str), 20, [66,66,66,66] )
  32.   @image_font.draw_font(0, 0,  @str, $font)
  33.   @imput_sprite = Sprite.new( 100,100,@image_font)
  34.  
  35.   @player_sprite.center_x= 10
  36.   @player_sprite.center_y= 10
  37.  
  38.  end
  39.  
  40.  def run
  41.   t = Input::IME.get_comp_info
  42.   x = 0
  43.   sx = nil
  44.   t.comp_str.each_char.with_index do |s, i|
  45.    case t.comp_attr[i]
  46.     when Input::IME::ATTR_INPUT # 入力中
  47.     Window.draw_font(x, 24, s, $font)
  48.     sx ||= x
  49.     when Input::IME::ATTR_TARGET_CONVERTED # 選択されてて変換されてる
  50.     Window.draw_font(x, 24, s, $font, color:C_YELLOW)
  51.     sx ||= x
  52.     when Input::IME::ATTR_CONVERTED # 選択されてなくて変換されてる
  53.     Window.draw_font(x, 24, s, $font, color:C_RED)  
  54.     when Input::IME::ATTR_TARGET_NOTCONVERTED # 選択されてて変換されてない
  55.     Window.draw_font(x, 24, s, $font, color:C_GREEN)
  56.     sx ||= x
  57.    end
  58.    x += $font.get_width(s)
  59.   end
  60.  
  61.   @str += Input::IME.get_string
  62.   @image_font = Image.new( $font.getWidth(@str), 20, [66,66,66,66] )
  63.   @image_font.draw_font(0, 0,  @str, $font)
  64.   @imput_sprite.image = @image_font
  65.  end
  66.  
  67.  def render
  68.   if @player_sprite.===(@imput_sprite) == true
  69.    @player_sprite.image = @player_image2
  70.    else
  71.    @player_sprite.image = @player_image1
  72.   end
  73.  
  74.   @imput_sprite.x = $xpoint
  75.   @imput_sprite.y = $ypoint
  76.  
  77.  
  78.   @imput_sprite.draw
  79.   @player_sprite.draw
  80.  
  81.   @imput_sprite.update
  82.   @player_sprite.update
  83.  end
  84.  
  85.  def update
  86.   @str = "あ" if Input.keyPush?(K_F1) and @str.length > 2
  87.   if Input.keyPush?(K_F5)
  88.   Window.windowed = false
  89.   end
  90.  
  91.   if Input.keyPush?(K_F4)
  92.   Window.windowed = true
  93.   end
  94.  end
  95.  
  96.  def exit
  97.   if Input.keyPush?(K_ESCAPE) #ESCキー
  98.    $end = true
  99.   end
  100.  end
  101. end
  102.  
  103. module Main
  104.  main_page = Main_page.new
  105.  main_page.init
  106.  Window.loop do
  107.   $xpoint = Input.mousePosX
  108.   $ypoint = Input.mousePosY
  109.   main_page.run
  110.   main_page.render
  111.   main_page.update
  112.   main_page.exit
  113.   Window.draw_font(0, 460, "F1 To Reflesh Word", $font, color:C_RED)
  114.  end
  115. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement