Beispiel #1
0
class Terrain(mrc.Block):
    """Represents a single terrain piece placed in a level."""

    #: Raw value for the x position of the left edge.
    x_raw = mrc.UInt16_BE(0x00, bitmask=b'\x0f\xff')
    #: If 1, blit image behind background.
    draw_back = mrc.Bits(0x00, 0b10000000)
    #: If 1, draw piece flipped vertically.
    draw_upsidedown = mrc.Bits(0x00, 0b01000000)
    #: If 1, draw piece as a hole.
    draw_erase = mrc.Bits(0x00, 0b00100000)
    #: Raw value (coarse component) for the y position of the top edge.
    y_raw_coarse = mrc.Int8(0x02)
    #: Raw value (fine component) for the y position of the top edge.
    y_raw_fine = mrc.Bits(0x03, 0b10000000)

    unknown_1 = mrc.Bits(0x03, 0b01000000)

    #: Index of the TerrainInfo block in the accompanying GroundDAT.
    obj_id = mrc.UInt8(0x03, bitmask=b'\x3f', range=range(0, 64))

    @property
    def x(self):
        """The x position of the left edge."""
        return (self.x_raw - 16)

    @property
    def y(self):
        """The y position of the top edge."""
        return (self.y_raw_coarse * 2 + self.y_raw_fine) - 4

    @property
    def repr(self):
        return "obj_id={}, x={}, y={}".format(self.obj_id, self.x, self.y)
Beispiel #2
0
 class Test(mrc.Block):
     field1 = mrc.UInt16_BE(0x00)
     field2 = mrc.Int32_LE()
     field3 = mrc.Bits8(0x08, bits=0b00111100)
     field4 = mrc.Bits8(0x08, bits=0b11000011)
     field5 = mrc.Int8(enum=TestEnum)