Re: Sub Commander Project (Don)
- Posted by don cole <doncole at pacb?ll.?et> Dec 12, 2007
- 506 views
Al Getz wrote: > > Hi Don, > > > I am just wondering when can we expect to see something that is > say the first draft of the program? > > I was thinking that if you want you can include a location matrix > that can be used to tell where the Sub(s) and ships are located > on the globe, or even just start with a fictitious flat playing field > with 'longitude' and 'latitude' as x and y coord's. > > > Al > > E boa sorte com sua programacao Euphoria! > > > My bumper sticker: "I brake for LED's" >
-- with trace include Win32Lib.ew --include mywin.ew sequence s,cen,fin,ship,stuff integer left,top,box_width,box_height,screen_width, screen_height,remain_width,A,B,r,bot,right,step, ship_dir,ship_loc,yy atom start step=16 start=time() s=getRect(1) screen_width=s[3]-s[1] screen_height=s[4]-s[2] box_height=screen_height-54--for tab bar at bottom box_width=box_height remain_width=screen_width-box_width left=remain_width/2 right=left+box_width top=1 bot=box_height A=floor(box_width/2)+left--x B=floor(box_height/2) --y cen={A,B} r=B constant Window1 = createEx( Window, "Window1", 0, s[1],s[2], s[3], s[4], 0, 0 ) constant Pix=createEx(Pixmap,"", 0, box_height,bot,s[3],bot,0,0 ) constant ButtonFace= rgb( #D4, #CF, #C6 ) procedure mPuts(integer id,integer col,integer row,sequence text) setPenPos(id,col,row) wPuts(id,text) end procedure function p2xy(atom r, atom a) -- polar to xy return {r*sin(a),-r*cos(a)} end function function vector(sequence pt1,sequence pt2)--distance and angle from pt1 to pt2 integer dx,dy atom r,a dx=floor(pt2[1]-pt1[1]) dy=floor(pt2[2]-pt1[2]) r=sqrt(dx*dx+dy*dy) if r=0 then return {0,0} end if if dy<0 then if dx<0 then a=2*PI-arctan(dx/dy) else a=-arctan(dx/dy) end if elsif dy>0 then a=PI-arctan(dx/dy) else --dy=0 (one point above the other); can't use arctan formula if dx<0 then a=3*PI/2 else a=PI/2 end if end if return {r,1800*a/PI} --convert radians to decidegrees end function function get_ship_dir(sequence shp) stuff=vector(cen,shp) return floor(stuff[2]) end function function get_ship_dist(sequence shp) stuff=vector(cen,shp) return floor(stuff[1]) end function ----------------------------setup ship-------------------------------- --sub is heading do North and not moving ship_loc=rand(r) ship_dir=rand(3600) ship=cen+p2xy(ship_loc,ship_dir/1800*PI) -- this the beging ship location ship_dir=rand(3600)--the direction the ship will travel ---------------------------------------------------------------------- procedure print_info1() mPuts(Pix,1,1,sprintf("screen_width=%d",screen_width)) mPuts(Pix,1,12,sprintf("box_width=%d",box_width)) mPuts(Pix,1,24,sprintf("remain=%d",remain_width)) mPuts(Pix,1,36,sprintf("used=%d",box_width+remain_width)) mPuts(Pix,1,48,sprintf("left=%d",left*2)) end procedure procedure print_info2() mPuts(Pix,1,58,sprintf("A=%d",A)) mPuts(Pix,1,70,sprintf("B=%d",B)) mPuts(Pix,1,90,sprintf("12 o'clk=%d,%d,%d,%d",{A,B,A,top})) mPuts(Pix,1,110,sprintf("3 o'clk=%d,%d,%d,%d",{A,B,right,B})) mPuts(Pix,1,130,sprintf("6 o'clk=%d,%d,%d,%d",{A,B,A,bot})) mPuts(Pix,1,150,sprintf("9 o'clk=%d,%d,%d,%d",{A,B,left,B})) mPuts(Pix,1,170,sprintf(" radius=%d",A)) -- mPuts(Pix,1,190,sprintf("circum=%d",pi*r*pi*r)) end procedure procedure print_time() setPenColor(Pix,ButtonFace) drawRectangle(Pix,1,31,210,120,230) setPenColor(Pix,Black) mPuts(Pix,1,210,sprintf("Time=%.2f",time()-start)) end procedure procedure print_ship_info() setPenColor(Pix,ButtonFace) drawRectangle(Pix,1,1,210,100,260) setPenColor(Pix,Black) mPuts(Pix,1,236,sprintf("s[1]=%d s[2]=%d",{ship[1],ship[2]})) mPuts(Pix,1,246,sprintf("deg=%d rad=%d",{get_ship_dir(ship),get_ship_dist(ship)})) end procedure procedure move_dot() ship=ship+p2xy(9,ship_dir/1800*PI) end procedure procedure print_dot() setPenColor(Pix,BrightWhite) ship=floor(ship) drawEllipse(Pix,1,ship[1]-5,ship[2]-5,ship[1]+5,ship[2]+5) end procedure procedure clear_dot() if get_ship_dist(ship) < r then setPenColor(Pix,Black) ship=floor(ship) drawEllipse(Pix,1,ship[1]-5,ship[2]-5,ship[1]+5,ship[2]+5) end if end procedure procedure stall(atom limit) atom stall_time,stall_start stall_start=time() stall_time=0 while stall_time<limit do stall_time=time()-stall_start end while end procedure procedure paint() setPenColor( Pix, Black ) print_info1() drawEllipse( Pix,1 ,left,0,box_width+left,box_height) setPenColor(Pix,Red) setPenWidth(Pix,4) drawEllipse( Pix,0 ,left,0,box_width+left,box_height) setPenWidth(Pix,1) setPenColor(Pix,Yellow) print_info2() fin=cen+p2xy(r,3600/1800*PI)--=pre loop while 1 do print_ship_info() for x=1 to 3600 by step do---- clock loop---------- setPenColor(Pix,Black) drawLine(Pix,cen[1],cen[2],floor(fin[1]),floor(fin[2])) --1st line fin=cen+p2xy(r,x/1800*PI) print_ship_info() yy=get_ship_dir(ship) if get_ship_dist(ship)<r and yy<x+step and yy>x-step then print_dot() end if setPenColor(Pix,Yellow) drawLine(Pix,cen[1],cen[2],floor(fin[1]),floor(fin[2])) --2nd line copyBlt(Window1,0,0,Pix) stall(.01) clear_dot() end for--------------------end clock------------------------ move_dot() print_ship_info() end while end procedure procedure Window1_onPaint(integer self,integer event,sequence parms) paint() end procedure setHandler( Window1, w32HPaint, routine_id("Window1_onPaint")) setHandler( Window1, w32HOpen,routine_id("setup")) WinMain( Window1,Normal )
Don Cole