(sprito.py) Improved Sprite legacy

This commit is contained in:
KikooDX 2020-04-10 14:27:22 +02:00
parent 0cfaf131ff
commit d8683ffca5
1 changed files with 17 additions and 14 deletions

View File

@ -5,14 +5,19 @@ class SpriteIndexed:
self.w = w
self.h = h
self.data = data
def _get_data(self, index: int, pallet: dict):
value = self.data[index]
if value == " ":
return None
return pallet[value]
def draw(self, x: int, y: int, pallet: dict) -> None:
i = 0
for yoff in range(self.h):
for xoff in range(self.w):
data_cell = self.data[i]
if data_cell and data_cell != " ":
set_pixel(x + xoff, y + yoff, pallet[data_cell])
i += 1
i = 0
for yoff in range(self.h):
for xoff in range(self.w):
value = self._get_data(i, pallet)
if value:
set_pixel(x + xoff, y + yoff, value)
i += 1
def to_raw(self, pallet: dict) -> SpriteRaw:
raw_data = []
for i in range(len(self.data)):
@ -24,11 +29,9 @@ class SpriteIndexed:
return SpriteRaw(self.w, self.h, raw_data)
class SpriteRaw(SpriteIndexed):
def _get_data(self, index: int, placeholder: None) -> tuple:
return self.data[index]
def draw(self, x: int, y: int) -> None:
i = 0
for yoff in range(self.h):
for xoff in range(self.w):
data_cell = self.data[i]
if data_cell:
set_pixel(x + xoff, y + yoff, data_cell)
i += 1
SpriteIndexed.draw(self, x, y, None)
def to_raw(self) -> None:
return None