home *** CD-ROM | disk | FTP | other *** search
/ Dave Lowe: Amiga Extras 1.3 Amiga Basic 1.2 / Lowe_AmigaExtras1_3AmigaBasic1_2.adf / BasicDemos / ObjEdit (.txt) < prev    next >
Encoding:
AmigaBASIC Source Code  |  1988-09-06  |  10.5 KB  |  552 lines

  1. '     Modified : Oct 23, 1985
  2. '     Modified : Aug 28, 1986  CAS
  3.  
  4.   DEFINT a-z
  5.  
  6. '   Format of the file produced by this program
  7. '
  8. '   long ColorSetOffset
  9. '   long DataSetOffset
  10. '   long depth                  number of bit planes
  11. '   long width                  width of object in pixels
  12. '   long height                 height of object in pixels
  13. '   short flags:
  14. '     fVsprite=1                TRUE if its a vsprite, FALSE if its a BOB
  15.       collisionPlaneIncluded=2  'never set by this editor
  16.       imageShadowIncluded=4     'never set by this editor
  17.       SAVEBACK=8                'save background before drawing BOB
  18.       OVERLAY=16                'color 0 for BOB is transparent, not black
  19.       SAVEBOB=32                'let BOB act like a paint brush
  20. '   short planePick          which playfield planes do object planes map to
  21. '   short planeOnOff         set to 0 by object editor
  22. '   <first bit-plane>
  23. '   <second bit-plane>       /* must begin on even byte boundary */
  24. '     :
  25. '   <last bit-plane>
  26. '   <imageShadow bit-plane>  not currently produced by object editor
  27. '   <collision bit-plane>    not currently produced by object editor
  28. '
  29.  
  30.   DEF FNArraySize& = 3+INT((BobRight+16)/16)*(BobBottom+1)*Depth
  31.   DIM DrawRect(3),ToolName$(6)
  32.  
  33.   LIBRARY "graphics.library"
  34.  
  35.   scrn=-1 'puts window in workbench screen
  36.   Depth=2
  37.   WinY=185: WinX=617
  38. 'If BOBs are to be created with other than 2 bit-planes
  39. ' alter next 4 lines (only if machine has more than 256k)
  40. ' Depth=3
  41. ' scrn=1
  42. ' SCREEN scrn,640,200,Depth,2
  43. ' WINDOW 1,,(0,0)-(WinX,WinY),31,scrn
  44.  
  45.   PRINT "Amiga-BASIC Object Editor"
  46.   GOSUB InitConstant
  47.   GOSUB InitFile
  48.   GOSUB InitMenu
  49. StartOver:
  50.   ON MENU GOSUB CheckMenu : MENU ON
  51.   ON MOUSE GOSUB CheckMouse : MOUSE ON
  52.   ON BREAK GOSUB IgnoreBreak: BREAK ON
  53.   DrawBoundary
  54.   GOSUB PrintStatus
  55.   Unfinished = -1
  56.   WHILE Unfinished
  57.     SLEEP 'this program is completely event driven
  58.   WEND
  59.  
  60.   MENU OFF: MOUSE OFF
  61.   SCREEN CLOSE 1
  62.   WINDOW CLOSE 1
  63.   WINDOW 1,,,,-1
  64.  
  65.   MENU RESET
  66.   CLS
  67.   END
  68.  
  69. InitConstant:
  70.   IF FRE(-1)>50000 THEN MaxTool=6 :ELSE MaxTool=5
  71.   ToolMode=1
  72.   CurrentColor=1
  73.   MaxY=120: MaxX=500
  74.   MaxY10=MaxY+10: MaxX10=MaxX+10
  75.   StatusLine=20
  76.   Top = 20: Left = 450
  77.   MaxBobRight=3*0.8*FRE(0)/4 : MaxBobBottom=0.8*FRE(0)/4
  78.   RETURN
  79.  
  80. InitFile:
  81.   CLS
  82.   IF Depth = 2 THEN
  83.     PRINT "Enter 1 if you want to edit sprites"
  84.     INPUT "Enter 0 if you want to edit bobs > ",fVSprite
  85.     CLS
  86.   ELSE
  87.     fVSprite = 0 'user can't edit sprite
  88.   END IF
  89.   FileName$=""
  90.   Flags=SAVEBACK+OVERLAY+fVSprite
  91.   IF fVSprite = 1 THEN BobRight=15 :ELSE BobRight=31
  92.   BobBottom=31
  93.   CurrentX=BobRight:CurrentY=BobBottom
  94.   maxColor=2^Depth - 1
  95.   PlanePick=maxColor
  96.   Change=0
  97.   RETURN
  98.  
  99. InitMenu:
  100.   MENU 1,0,1,"File"
  101.   MENU 1,1,1,"New"
  102.   MENU 1,2,1,"Open ..."
  103.   MENU 1,3,1,"Save"
  104.   MENU 1,5,1,"Quit"
  105.   MENU 1,4,1,"Save as ..."
  106.   MENU 2,0,1,"Tools" 
  107.   MENU 3,0,1,"Enlarge"
  108.   MENU 3,1,1,"4x4"
  109.   MENU 3,2,1,"1x1"
  110.   MENU 4,0,1,""
  111.   ToolName$(1)="Pen"
  112.   ToolName$(2)="Line"
  113.   ToolName$(3)="Oval"
  114.   ToolName$(4)="Rectangle"
  115.   ToolName$(5)="Eraser"
  116.   ToolName$(6)="Paint"
  117.   FOR i=1 TO MaxTool
  118.     MENU 2,i,1,ToolName$(i)
  119.   NEXT i
  120.   RETURN
  121.  
  122. CheckMenu:
  123.   MenuId=MENU(0)
  124.   MenuItem=MENU(1)
  125.   ON MenuId GOTO FileMenu,ToolsMenu,FatBits
  126.  
  127. CheckMouse:
  128.   GetCurrentXY 
  129.   IF CurrentY>MaxY+10 THEN CheckColor
  130.   IF NOT fEnlarge THEN
  131.     IF CurrentY>BobBottom+10 OR CurrentX>BobRight+10 THEN RETURN
  132.     IF CurrentY>=BobBottom AND CurrentX>=BobRight THEN ChangeSizePicture
  133.     IF (CurrentY>BobBottom OR CurrentX>BobRight) THEN RETURN
  134.   ELSE
  135.     IF CurrentX>BobRight*Offset OR CurrentY>BobBottom*Offset THEN RETURN
  136.   END IF
  137.   StartY=CurrentY
  138.   StartX=CurrentX
  139.   Change=-1
  140.   ON ToolMode GOSUB Pen,DrawLine,DrawCircle,DrawRectangle,ErasePicture,PaintPicture
  141.   RETURN
  142.  
  143. DrawLine:
  144.   WHILE MOUSE(0)<>0
  145.     GetCurrentXY
  146.     IF InsideBob THEN
  147.       InvertVideo
  148.       LINE (StartX,StartY)-(CurrentX,CurrentY) 'draw line
  149.       LINE (StartX,StartY)-(CurrentX,CurrentY) 'erase line
  150.       NormalVideo
  151.     END IF
  152.   WEND
  153.   LINE (StartX,StartY)-(CurrentX,CurrentY),CurrentColor
  154.   RETURN
  155.   
  156. FatBits:
  157.   ON MenuItem GOTO Enlarge, Shrink
  158.   
  159. Enlarge:
  160.   IF fEnlarge THEN RETURN
  161.   fBig = -1
  162.   IF BobBottom > 31 THEN
  163.     LOCATE 17,1:PRINT "Y >= 31 too large to enlarge. ";
  164.   ELSEIF BobRight >=100 THEN 
  165.     LOCATE 17,1:PRINT "X >=100 too large to enlarge. ";
  166.   ELSE
  167.     fBig = 0
  168.   END IF
  169.   IF fBig THEN
  170.     PRINT "Press any key to continue";
  171. 10 a$=INKEY$:IF a$="" GOTO 10
  172.     LOCATE 17,1:PRINT "                                  ";   
  173.     PRINT "                            ";
  174.     RETURN
  175.   END IF
  176.   Offset = 4:OffsetB=Offset-1
  177.   ChangeToolsMode 0 'Disable Tools
  178.   MenuItem = 1
  179.   GOSUB ToolsMenu
  180.   fEnlarge = -1 'Enlarge flag
  181.  
  182.   DIM BobArray(FNArraySize&)
  183.   GET (0,0)-(BobRight,BobBottom),BobArray
  184.   LINE (Left-1,Top-1)-(Left+BobRight+1,Top+BobBottom+1),,b
  185.   PUT (Left,Top),BobArray
  186.   ERASE BobArray
  187.   
  188.   LINE (0,0)-(BobRight*2,BobBottom*2),0,bf
  189.   LINE (-1,-1)-((BobRight+1)*Offset,(BobBottom+1)*Offset),,b
  190.   m=0:n=0
  191.   FOR i=Left TO Left+BobRight
  192.     n=0
  193.     FOR j=Top TO Top+BobBottom
  194.       x=POINT(i,j)
  195.       IF x>0 THEN LINE (m,n)-(m+OffsetB,n+OffsetB),x,bf
  196.       n=n+Offset
  197.     NEXT j
  198.     m=m+Offset
  199.   NEXT i
  200.   RETURN
  201.       
  202.   
  203. Shrink:
  204.   IF fEnlarge = 0 THEN RETURN
  205.   ChangeToolsMode 1
  206.   fEnlarge = 0
  207.   DIM BobArray(FNArraySize&)
  208.   GET (Left,Top)-(Left+BobRight,Top+BobBottom),BobArray
  209.   LINE (Left-1,Top-1)-(Left+BobRight+1,Top+BobBottom+1),0,bf
  210.   LINE (0,0)-(BobRight*Offset+Offset,Offset*BobBottom+Offset),0,bf
  211.   DrawBoundary
  212.   PUT (0,0),BobArray
  213.   ERASE BobArray
  214.   RETURN
  215.   
  216.  
  217. SUB ChangeToolsMode (Mode) STATIC
  218. SHARED MaxTool
  219.   FOR i=2 TO MaxTool
  220.     MENU 2,i,Mode
  221.   NEXT
  222. END SUB
  223.  
  224. Pen:
  225.   IF fEnlarge THEN GOTO BigPen
  226.   GetCurrentXY
  227.   IF InsideBob THEN PSET (CurrentX,CurrentY),CurrentColor
  228.   WHILE MOUSE(0)<>0
  229.     GetCurrentXY
  230.     IF NOT InsideBob THEN RETURN
  231.     LINE -(CurrentX,CurrentY),CurrentColor
  232.   WEND
  233.   RETURN
  234.   
  235. BigPen:
  236.   GOSUB GetX1Y1
  237.   IF InsideBob THEN 
  238.     PSET (CurrentX+Left,CurrentY+Top),CurrentColor
  239.     LINE (x1,y1)-(x1+OffsetB,y1+OffsetB),CurrentColor,bf
  240.   END IF
  241.   WHILE MOUSE(0)<>0
  242.     GOSUB GetX1Y1
  243.     IF InsideBob  THEN
  244.       PSET (CurrentX+Left,CurrentY+Top),CurrentColor
  245.       LINE (x1,y1)-(x1+OffsetB,y1+OffsetB),CurrentColor,bf
  246.     END IF
  247.   WEND
  248.   RETURN
  249.   
  250. GetX1Y1:
  251.   GetCurrentXY
  252.   IF (CurrentX>=0 AND CurrentX < (BobRight+1)*Offset) AND (CurrentY>=0 AND CurrentY <(BobBottom+1)*Offset) THEN 
  253.     InsideBob = -1
  254.     CurrentX = INT(CurrentX/Offset)
  255.     x1=CurrentX*Offset
  256.     CurrentY=INT(CurrentY/Offset)
  257.     y1=CurrentY*Offset
  258.   ELSE
  259.     InsideBob = 0
  260.   END IF
  261.   RETURN
  262.  
  263. DrawCircle:
  264.   GOSUB TrackRect
  265.   CenterX=(DrawRect(1)+DrawRect(3))/2
  266.   CenterY=(DrawRect(2)+DrawRect(0))/2
  267.   RadiusX=(DrawRect(3)-DrawRect(1))/2
  268.   RadiusY=(DrawRect(2)-DrawRect(0))/2
  269.   IF RadiusX=0 OR RadiusY=0 THEN RETURN
  270.   Aspect!=ABS(RadiusY/RadiusX)
  271.   IF RadiusX < RadiusY THEN RadiusX=RadiusY
  272.   CIRCLE (CenterX,CenterY),RadiusX,CurrentColor,,,Aspect!
  273.   RETURN
  274.  
  275. DrawRectangle:
  276.   GOSUB TrackRect
  277.   LINE (DrawRect(1),DrawRect(0))-(DrawRect(3),DrawRect(2)),CurrentColor,b
  278.   RETURN
  279.  
  280. ErasePicture:
  281.   WHILE MOUSE(0)<>0
  282.     GetCurrentXY
  283.     IF CurrentX-5<0 OR CurrentY-3<0 THEN InsideBob=0
  284.     IF InsideBob THEN
  285.       LINE (CurrentX-5,CurrentY-3)-(CurrentX,CurrentY),1,bf
  286.       LINE (CurrentX-5,CurrentY-3)-(CurrentX,CurrentY),0,bf
  287.     END IF
  288.   WEND
  289.   DrawBoundary
  290.   RETURN
  291.  
  292. PaintPicture:
  293.   IF InsideBob THEN 
  294.      LINE(0,BobBottom+1)-(BobRight+1,BobBottom+1),CurrentColor
  295.      LINE(BobRight+1,0)-(BobRight+1,BobBottom+1),CurrentColor
  296.      PAINT (CurrentX, CurrentY),CurrentColor
  297.      DrawBoundary
  298.   END IF
  299.   RETURN
  300.  
  301. TrackRect:
  302.   WHILE MOUSE(0)<>0
  303.     GetCurrentXY
  304.     IF InsideBob THEN
  305.       DrawRect(0)=StartY
  306.       DrawRect(1)=StartX
  307.       DrawRect(2)=CurrentY
  308.       DrawRect(3)=CurrentX
  309.       InvertVideo
  310.       FrameRect DrawRect() 'Draw it
  311.       FrameRect DrawRect() 'Erase it
  312.       NormalVideo
  313.     END IF
  314.   WEND
  315.   IF CurrentY<StartY THEN DrawRect(0)=CurrentY: DrawRect(2)=StartY
  316.   IF CurrentX<StartX THEN DrawRect(1)=CurrentX: DrawRect(3)=StartX
  317.   RETURN
  318.  
  319. ChangeSizePicture:
  320.   MaxMem = 0.8 * FRE(0)
  321.   COLOR 0
  322.   DrawBoundary
  323.   COLOR 1
  324.   InvertVideo
  325.   WHILE MOUSE(0)<>0
  326.     GetCurrentXY 
  327.     IF (CurrentY < MaxY) AND (CurrentY > 0) THEN
  328.      IF (CurrentX <= MaxX) AND (CurrentX >= 10) THEN
  329.       IF MaxMem > (Depth * CurrentX * CurrentY /8) THEN   
  330.         IF fVSprite = 1 THEN BobRight = 15:CurrentX=15::ELSE BobRight=CurrentX
  331.         BobBottom=CurrentY
  332.         DrawBoundary
  333.         DrawBoundary
  334.       END IF 
  335.      END IF
  336.     END IF
  337.   WEND
  338.   NormalVideo
  339.   GOSUB GetPicture
  340.   GOSUB RedrawPicture
  341.   RETURN
  342.  
  343. ToolsMenu:
  344.   ToolMode=MenuItem
  345.   GOSUB PrintToolStatus
  346.   RETURN
  347.  
  348. FileMenu:
  349.   ON MenuItem GOSUB NewFile,OpenFile,SaveFile,SaveFileAs,Quit
  350.   RETURN
  351.  
  352. NewFile:
  353.   GOSUB CheckSave
  354.   IF CancelCommand THEN RETURN
  355.   CLS
  356.   GOSUB InitFile
  357.   GOTO StartOver
  358.  
  359. OpenFile:
  360.   GOSUB CheckSave
  361.   IF CancelCommand THEN RETURN
  362.   CLS
  363.   INPUT "Enter Filename > ",FileName$
  364.   IF FileName$="" THEN NewFile
  365.   OPEN FileName$ FOR INPUT AS 1
  366.   ColorSet=CVL(INPUT$(4,1))
  367.   DataSet=CVL(INPUT$(4,1))
  368.   Depth=CVL(INPUT$(4,1))
  369.   BobRight=CVL(INPUT$(4,1)) - 1
  370.   BobBottom=CVL(INPUT$(4,1)) - 1
  371.   REM --- UNDONE if ColorSet<>0 or DataSet<>0, read image.editor format file
  372.   Flags=CVI(INPUT$(2,1))
  373.   IF Flags AND 1 THEN fVSprite = 1 :ELSE fVSprite = 0
  374.   IF PlanePick <> CVI(INPUT$(2,1)) THEN
  375.     PRINT "Error: file not compatible with this SCREEN"
  376.   ELSE
  377.     PlaneOnOff=CVI(INPUT$(2,1))
  378.     ArraySize&=FNArraySize&
  379.     DIM BobArray(ArraySize&)
  380.     BobArray(0)=BobRight + 1
  381.     BobArray(1)=BobBottom + 1
  382.     BobArray(2)=Depth
  383.     FOR i=3 TO ArraySize&-1
  384.       BobArray(i)=CVI(INPUT$(2,1))
  385.     NEXT i
  386.     CLS
  387.     CurrentX=BobRight: CurrentY=BobBottom
  388.     GOSUB RedrawPicture
  389.   END IF
  390.   CLOSE #1
  391.   Change=0
  392.   GOTO StartOver
  393.  
  394. SaveFileAs:
  395.   FileName$=""
  396. SaveFile:
  397.   IF fEnlarge THEN GOSUB Shrink
  398.   GOSUB GetPicture
  399.   IF FileName$="" THEN CLS: INPUT "Enter Filename > ",FileName$
  400.   IF FileName$<>"" THEN
  401.     OPEN FileName$ FOR OUTPUT AS 1
  402.     PRINT #1, MKL$(0); 'ColorSet
  403.     PRINT #1, MKL$(0); 'DataSet
  404.     PRINT #1, MKI$(0);MKI$(BobArray(2)); 'depth
  405.     PRINT #1, MKI$(0);MKI$(BobArray(0)); 'width
  406.     PRINT #1, MKI$(0);MKI$(BobArray(1)); 'height
  407.     PRINT #1, MKI$(Flags);
  408.     PRINT #1, MKI$(PlanePick);  'planePick
  409.     PRINT #1, MKI$(0);  'planeOnOff
  410.     FOR i=3 TO ArraySize&-1
  411.       PRINT #1, MKI$(BobArray(i));
  412.     NEXT i
  413.     IF fVSprite THEN
  414.     'Output the colors for sprite> Change output values for different colors
  415.       PRINT #1,MKI$(&Hff); 'White. Color 1
  416.       PRINT #1,MKI$(0); 'Black. Color 2
  417.       PRINT #1,MKI$(&Hf80); 'Orange. Color 3
  418.     END IF
  419.     CLOSE#1
  420.   END IF
  421.   GOSUB RedrawPicture
  422.   Change=0
  423.   RETURN
  424.  
  425. Quit:
  426.   Cancel=0
  427.   GOSUB CheckSave
  428.   IF CancelCommand THEN RETURN
  429.   Unfinished=0
  430.   RETURN
  431.  
  432. GetPicture:
  433.   ArraySize&=FNArraySize&
  434.   DIM BobArray(ArraySize&)
  435.   GET (0,0)-(BobRight,BobBottom),BobArray
  436.   RETURN
  437.  
  438. RedrawPicture:
  439.   CLS
  440.   PUT (0,0),BobArray,PSET
  441.   ERASE BobArray
  442.   DrawBoundary
  443.   GOSUB PrintStatus
  444.   RETURN
  445.  
  446. PrintStatus:                                                  
  447.   PrintCurrentXY
  448.   GOSUB PrintToolStatus
  449.   GOSUB PrintColorBar
  450.   RETURN
  451.  
  452. PrintToolStatus:
  453.   LOCATE StatusLine,24: PRINT SPACE$(10);
  454.   LOCATE StatusLine,24: PRINT ToolName$(ToolMode);
  455.   RETURN
  456.  
  457. PrintColorBar:
  458.   COLOR CurrentColor
  459.   LOCATE 19,1: PRINT "Color:";
  460.   ColorBar = WINDOW(5)-10
  461.   COLOR 1
  462.   x=70
  463.   FOR i=0 TO maxColor
  464.     LINE (x,ColorBar)-(x+20,y+ColorBar+10),i,bf
  465.     LINE (x,ColorBar)-(x+20,y+ColorBar+10),1,b
  466.     x=x+20
  467.   NEXT i
  468.   RETURN
  469.  
  470. CheckColor:
  471.   IF CurrentY<ColorBar OR CurrentY>ColorBar+10 THEN RETURN
  472.   IF CurrentX<70 THEN RETURN
  473.   i=INT((CurrentX-70)/20)
  474.   IF i>maxColor THEN RETURN
  475.   CurrentColor=i
  476.   GOSUB PrintColorBar
  477.   RETURN
  478.  
  479. CheckSave:
  480.   IF fEnlarge THEN GOSUB Shrink
  481.   CancelCommand=0
  482.   IF Change THEN
  483.     BEEP
  484.     GOSUB GetPicture
  485.     CLS
  486.     PRINT "Current file is not saved."
  487.     PRINT "Do you want to save it?"
  488.     PRINT " Press Y key if you want to save it"
  489.     PRINT " Press N key if don't you want to save it"
  490.     PRINT " Press C key if you want to cancel command"
  491.     Response=0
  492.     WHILE Response=0
  493.       a$=INKEY$
  494.       IF a$<>"" THEN
  495.         a$=UCASE$(a$)
  496.         IF a$="Y" THEN Response=1
  497.         IF a$="N" THEN Response=2
  498.         IF a$="C" THEN Response=3
  499.         IF Response=0 THEN BEEP
  500.       END IF
  501.     WEND
  502.     GOSUB RedrawPicture
  503.     IF Response=1 THEN GOSUB SaveFileAs
  504.     IF Response=3 THEN CancelCommand=-1
  505.   END IF
  506.   RETURN
  507.  
  508. SUB GetCurrentXY STATIC
  509.   SHARED CurrentX,CurrentY,InsideBob,BobRight,BobBottom
  510.   dummy=MOUSE(0)
  511.   CurrentX=MOUSE(1)
  512.   CurrentY=MOUSE(2)
  513.   InsideBob=-1
  514.   IF CurrentX>BobRight OR CurrentY>BobBottom THEN InsideBob=0
  515.   IF CurrentX<0 OR CurrentY<0 THEN InsideBob=0
  516.   END SUB
  517.  
  518. SUB PrintCurrentXY STATIC
  519.   SHARED StatusLine,CurrentX,CurrentY
  520.   LOCATE StatusLine,1: PRINT "Bob size X:";CurrentX;
  521.   LOCATE StatusLine,17: PRINT "Y:";CurrentY;
  522. END SUB
  523.  
  524. SUB DrawBoundary STATIC
  525. SHARED BobRight,BobBottom
  526.   x=BobRight+10
  527.   y=BobBottom+10
  528.   LINE (0,y)-(x,y)
  529.   LINE (x,y)-(x,0)
  530.   LINE (0,BobBottom+1)-(x,BobBottom+1)
  531.   LINE (BobRight+1,y)-(BobRight+1,0)
  532. END SUB
  533.  
  534. SUB InvertVideo STATIC
  535.    CALL SetDrMd& (WINDOW(8),3)
  536. END SUB
  537.  
  538. SUB NormalVideo STATIC
  539.    CALL SetDrMd& (WINDOW(8),1)
  540. END SUB
  541.  
  542. SUB FrameRect(rect()) STATIC
  543.   LINE (rect(1),rect(0))-(rect(3),rect(0))
  544.   LINE (rect(3),rect(0))-(rect(3),rect(2))
  545.   LINE (rect(3),rect(2))-(rect(1),rect(2))
  546.   LINE (rect(1),rect(2))-(rect(1),rect(0))
  547. END SUB
  548.  
  549. IgnoreBreak:
  550.   RETURN
  551.  
  552.