display.item documentation - wladekpal/The-Lazy-Snek GitHub Wiki

Item

Container class for blocks used to handle drag and drop feature.

Properties

  • block - engine.blocks.Block type object wrapped by Item class
  • pos- two elements tuple representing position of displayed block's top left corner on screen.
  • offset - two elements tuple representing difference between cursor position on displayed block's body and its top left corner. Used to mantain block's top left corner and cursor relative positions while dragging block.
  • level_view - gameplay.LevelView type object that Item communicates with handling actions
  • side_length - side length of dragged block's texture displayed on screen while dragging

Item(block, level_view, pos, offset, side_lenght)

All properties, besides pos are set by assigning arguments of their name and have role described in Properties section. pos agument should be cursor position, and pos property will be set to displayed block's top left corner, after applying offset property values to pos argument.

apply_offset(pos)

Sets current pos property by substracting offset from pos argument to mantain cursor and block's top left corner relative positions.

self_draw(frame)

Draws block in given frame, with top left corner position equal to current pos property value.

handle_motion(pos)

Changes displayed block's position on screen when cursor changed its position to pos.

handle_unclick(pos)

Handles release of mouse left button. If wrapped dragged block was dropped on an empty field, places the block on the field. If not, returns block to pool of blocks available for dragging.