何度も質問してすいません。
今度は"kakikukeko"をおすとokが出るようにしたいのですが、
clicked?(x,y)メゾットの
(KUIZUX <= x <= 650) and (KUIZUY <= y <= 250)
これでは文字の場所の座標の指定をすることはできないのでしょうか。
ちなみにこれを実行すると
window.rb:33:in'clicked': undefined method '<=' for true:TrueClass (NoMethodError)
from main.rb:17:in"main"]
というエラーコードが出てきています。
window.rb
1require "sdl" 2require "./color.rb" 3class Window 4 WINDOW_YOKO = 750 5 WINDOW_TATE = 550 6 BITPIKUSERU = 0 7 KUIZUX = 550 8 KUIZUY = 200 9 10def initialize 11 SDL.init(SDL::INIT_EVERYTHING) 12 @screen = SDL.set_video_mode(WINDOW_YOKO,WINDOW_TATE,BITPIKUSERU,SDL::SWSURFACE) 13 SDL::TTF.init 14 @font = SDL::Kanji.open("font/jiskan24.bdf",24) 15 @font.set_coding_system(SDL::Kanji::SJIS) 16end 17 18def drawBack 19 @screen.fill_rect(0,0,WINDOW_YOKO,WINDOW_TATE,Color::GREEN) 20 @font.put(@screen,"aiueo",230,50,255,255,255) 21end 22 23def refresh 24 @screen.update_rect(0,0,0,0) 25end 26 27def gamestart 28 @font.put(@screen,"kakikuekko",KUIZUX,KUIZUY,255,255,255) 29 @font.put(@screen,"sasisuseso", 570,300,255,255,255) 30end 31 32def clicked?(x,y) 33 if (KUIZUX <= x <= 650) and (KUIZUY <= y <= 250) 34 return true 35 else 36 return false 37 end 38end 39end
main.rb
1#!ruby -Ks 2require "./window.rb" 3 4window = Window.new 5window.drawBack 6window.gamestart 7window.refresh 8 9while true do 10 while event = SDL::Event2.poll do 11 case event 12 when SDL::Event2::Quit 13 exit 14 when SDL::Event2::MouseButtonDown 15 x = event.x 16 y = event.y 17 if window.clicked?(x,y) 18 puts "ok" 19 end 20 end 21 end 22 23end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。