Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursively extracting sprites
#2
Makes sense. If this was SCREEN 0, I would approach it using the SCREEN function to do as follows:

1) Start at the top row and for across the screen, one column at a time until the end of the screen. If a pixel is filled, jump out of the loop and continue down to the next row until the function can go completely across the screen without encountering a filled pixel. This is the bottom row just below the bottom of all images in a row.

2) Start at the first column of the first row and proceed down to the bottom row of the sprite discovered in the step above. If no pixel is encountered, jump to the next column to the left. When a pixel is encountered, load the first of four variables as true, and proceed on until a full downward pass is made with no pixels encountered. You now have the first and last columns occupied by the first sprite.

3) Repeat step two from the last column scanned, finding the first and last columns of the second sprite.

4) Take half the width between the first two variables, and half the width between the second two variables. Measure between those two results to get the width between the centers of all sprites in a line and the starting point.

5) start from the first column and measure as far as the width results above to find and pixels in the first sprite. Multiply this amount by the sprite number on the line desired, and start from there to retrieve that sprite.

Code: (Select All)

Print "                                           "
Print "   ******    *******   *******   *******   "
Print "   *     *   *            *      *         "
Print "   *     *   *            *      *         "
Print "   ******    *****        *      ****      "
Print "   *         *            *      *         "
Print "   *         *            *      *         "
Print "   *         *******      *      *******   "
Print "                                           "

Locate 1, 1
Do
    Do Until Pos(0) = _Width
        If Screen(CsrLin, Pos(0)) <> 32 Then Exit Do
        Locate , Pos(0) + 1
    Loop
    y1 = CsrLin: x1 = Pos(0)
    If pixel = 0 Then If x1 < _Width Then pixel = -1: start_row = CsrLin
    Locate CsrLin + 1, 1
Loop Until y1 > 1 And x1 = _Width And pixel = -1 Or CsrLin = _Height
If pixel And x1 = _Width Then sprite_height = CsrLin - start_row - 1

col = 0
Do
    col = col + 1: pixel = 0
    Locate start_row, col
    For i = 1 To sprite_height
        If Screen(CsrLin, col) <> 32 Then
            pixel = -1
            If sprite_1_start_col = 0 Then sprite_1_start_col = col: Exit For
        End If
        Locate CsrLin + 1, col
    Next
Loop Until sprite_1_start_col And pixel = 0 Or col = _Width
If col < _Width Then
    sprite_1_end_col = col - 1
End If

Do
    col = col + 1: pixel = 0
    Locate start_row, col
    For i = 1 To sprite_height
        If Screen(CsrLin, col) <> 32 Then
            pixel = -1
            If sprite_2_start_col = 0 Then sprite_2_start_col = col: Exit For
        End If
        Locate CsrLin + 1, col
    Next
Loop Until sprite_2_start_col And pixel = 0 Or col = _Width
If col < _Width Then
    sprite_2_end_col = col - 1
End If

fac_1 = sprite_1_start_col / 2
fac_2 = (sprite_2_start_col + (sprite_2_end_col - sprite_2_start_col) / 2) - (sprite_1_start_col + (sprite_1_end_col - sprite_1_start_col) / 2)

Do
    View Print: Locate 12, 1: Print Space$(_Width);
    Locate 12, 1
    Input "Select to retrieve a sprite from sprite sheet (1 - 4): "; sel
    View Print 13 To _Height: Cls 2
    x = fac_1 + (sel - 1) * fac_2
    y = start_row

    For i = start_row To start_row + sprite_height
        For j = x To x + fac_2
            If Screen(i, j) <> 32 Then Locate 15 + i - start_row, 4 + j - ((sel - 1) * fac_2): Print "*";
        Next
    Next
Loop

Not completely stress tested and note if you took out a full column in any sprite, it would fail. With sprites like that you would have to increase the loop sensitivity to account for a few columns or rows of completely missing pixels.

Pete
Reply


Messages In This Thread
Recursively extracting sprites - by TerryRitchie - 03-03-2024, 05:56 AM
RE: Recursively extracting sprites - by Pete - 03-03-2024, 07:45 AM
RE: Recursively extracting sprites - by GareBear - 03-03-2024, 03:21 PM
RE: Recursively extracting sprites - by Pete - 03-03-2024, 06:09 PM
RE: Recursively extracting sprites - by bplus - 03-03-2024, 07:43 PM
RE: Recursively extracting sprites - by Pete - 03-03-2024, 08:18 PM
RE: Recursively extracting sprites - by Pete - 03-03-2024, 10:03 PM
RE: Recursively extracting sprites - by bplus - 03-04-2024, 12:21 AM



Users browsing this thread: 3 Guest(s)