class Main::MultiMap::Map::Plane
Constants
- Down
- InitialState
- Left
- ReadyState
- Right
- Up
Public Class Methods
new(nx,ny)
click to toggle source
# File bin/tactical_fighter, line 44 def initialize(nx,ny) @state=InitialState @nx=nx @ny=ny @head_x=rand(@nx-7).to_i+4 @head_y=rand(@ny-7).to_i+4 @direction=rand(4).to_i+1 #torso direction from head end
Public Instance Methods
body?(x,y)
click to toggle source
# File bin/tactical_fighter, line 55 def body?(x,y) case @direction when Down then @head_x-2 <= x && x <= @head_x+2 && y == @head_y+1 || @head_x-1 <= x && x <= @head_x+1 && y == @head_y+3 || x == @head_x && y == @head_y+2 when Up then @head_x-2 <= x && x <= @head_x+2 && y == @head_y-1 || @head_x-1 <= x && x <= @head_x+1 && y == @head_y-3 || x == @head_x && y == @head_y-2 when Left then @head_y-2 <= y && y <= @head_y+2 && x == @head_x-1 || @head_y-1 <= y && y <= @head_y+1 && x == @head_x-3 || y == @head_y && x == @head_x-2 when Right then @head_y-2 <= y && y <= @head_y+2 && x == @head_x+1 || @head_y-1 <= y && y <= @head_y+1 && x == @head_x+3 || y == @head_y && x == @head_x+2 end end
draw(cr,xroot,yroot,bs)
click to toggle source
# File bin/tactical_fighter, line 142 def draw(cr,xroot,yroot,bs) r=bs/3 if ready? cr.set_source_rgba(0,0,1,0.5) else cr.set_source_rgba(0,1,0,0.5) end cr.move_to(xroot+bs*(@head_x-0.5)+rx(0,-r),yroot+bs*(@head_y-0.5)+ry(0,-r)) rct(cr,-r,0,-r,0,-r,r*2) rct(cr,0,r,0,r,-r,r) rct(cr,-(bs*2-r),0,-(bs*2-r),0,-(bs*2-r),r) rct(cr,0,r,0,r,(bs*2-r),r) rct(cr,r,0,r,0,r,r) rct(cr,0,bs,0,bs,-r,bs) rct(cr,-r*2,0,-r*2,0,-r*2,r) rct(cr,0,r,0,r,bs+r,r) rct(cr,bs+r,0,bs+r,0,bs+r,-r) rct(cr,0,-r,0,-r,-r*2,-r) rct(cr,-r,0,-r,0,-r,-r) rct(cr,0,-bs,0,-bs,r,-bs) rct(cr,bs*2-r,0,bs*2-r,0,bs*2-r,-r) rct(cr,0,-r,0,-r,-(bs*2-r),-r) rct(cr,-r,0,-r,0,-r,-r) rct(cr,0,-2*r,0,-2*r,-r,-2*r) cr.close_path cr.fill cr.stroke end
head?(x,y)
click to toggle source
# File bin/tactical_fighter, line 72 def head?(x,y) x == @head_x and y == @head_y end
invalidate()
click to toggle source
# File bin/tactical_fighter, line 66 def invalidate @status = InitialState end
keep_on_map()
click to toggle source
# File bin/tactical_fighter, line 90 def keep_on_map newx=@head_x newy=@head_y #keep head on map newx=0 if @head_x < 0 newy=0 if @head_y < 0 newx=@nx if @head_x > @nx newy=@ny if @head_y > @ny #keep body on map case @direction when Down then newy=@ny-3 if @head_y+3>@ny when Up then newy=4 if @head_y<4 when Left then newx=4 if @head_x<4 when Right then newx=@nx-3 if @head_x+3>@nx end case @direction when Up,Down then newx=3 if @head_x<3 newx=@nx-2 if @head_x>@nx-2 when Right,Left then newy=3 if @head_y<3 newy=@ny-2 if @head_y>@ny-2 end move_to(newx,newy) if newx!=@head_x || newy!=@head_y end
keep_on_map_by_rotate_only(nhead_x=@head_x,nhead_y=@head_y)
click to toggle source
# File bin/tactical_fighter, line 116 def keep_on_map_by_rotate_only(nhead_x=@head_x,nhead_y=@head_y) newx=@head_x newy=@head_y if nhead_x!=@head_x || nhead_y!=@head_y @head_x=nhead_x @head_y=nhead_y end #keep body on map case @direction when Down then newy=@ny-3 if @head_y+3>@ny when Up then newy=4 if @head_y<4 when Left then newx=4 if @head_x<4 when Right then newx=@nx-3 if @head_x+3>@nx end case @direction when Up,Down then newx=3 if @head_x<3 newx=@nx-2 if @head_x>@nx-2 when Right,Left then newy=3 if @head_y<3 newy=@ny-2 if @head_y>@ny-2 end rotate_cw(true) if newx!=@head_x || newy!=@head_y validate end
move_to(newx,newy)
click to toggle source
# File bin/tactical_fighter, line 84 def move_to(newx,newy) @head_x=newx @head_y=newy keep_on_map return @head_x,@head_y end
on_coordinates?(x,y)
click to toggle source
# File bin/tactical_fighter, line 52 def on_coordinates?(x,y) head?(x,y) || body?(x,y) end
rct(cr,x1,y1,x2,y2,xd,yd)
click to toggle source
# File bin/tactical_fighter, line 173 def rct(cr,x1,y1,x2,y2,xd,yd) cr.rel_curve_to(rx(x1,y1),ry(x1,y1),rx(x2,y2),ry(x2,y2),rx(xd,yd),ry(xd,yd)) end
ready?()
click to toggle source
# File bin/tactical_fighter, line 63 def ready? @status == ReadyState end
rotate_cw(only_by_rotate=false)
click to toggle source
# File bin/tactical_fighter, line 75 def rotate_cw(only_by_rotate=false) @direction-=1 @direction+=4 if @direction<1 if only_by_rotate keep_on_map_by_rotate_only else keep_on_map end end
rx(x,y)
click to toggle source
# File bin/tactical_fighter, line 176 def rx(x,y) case @direction when Down then x when Up then -x when Left then -y when Right then y end end
ry(x,y)
click to toggle source
# File bin/tactical_fighter, line 184 def ry(x,y) case @direction when Down then y when Up then -y when Left then -x when Right then x end end
validate()
click to toggle source
# File bin/tactical_fighter, line 69 def validate @status = ReadyState end