home *** CD-ROM | disk | FTP | other *** search
/ Amiga Computing 57 / ac057a.adf / Demos / objedit.bas < prev    next >
BASIC Source File  |  1988-12-19  |  14KB  |  553 lines

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