I want to arrange objects on the screen using an array, which is a map.
Objects on the map are defined by different values. So far, there are only 2 of them in the example: "+" and "-"
Each of them can be defined by some kind of image, such as grass and stone (as an example).
This is a working option.
Code: Select all
init python:
class Level:
self.level_map = [
'++++++++++++++++++++',
'+-------------+----+',
'+----++-----------++',
'+---------+--------+',
'++++++++++++++++++++',
]
screen show_map:
$ x = 0
$ y = 0
for row in level.level_map:
for col in row:
if col == '+':
$ img = level.stone
if col == '-':
$ img = level.grass
image Transform(img, size=(level.sizes), pos=(x, y))
$ x += level.width
$ y += level.height
$ x = 0
I did not find an analogue of image Transform () for the function.
It should somehow work, because there is this:
Code: Select all
init python:
def some_func(var):
renpy.show_screen('test', var)
# You can show the screen through functions.
Code: Select all
renpy.image(name, d) # But how do you draw an image through a function?
Ultimately it should look like this:
Code: Select all
class Level:
# Method for drawing the map.
def draw(self):
x = 0
y = 0
for row in self.level_map:
for col in row:
if col == '+':
img = self.stone
if col == '-':
img = self.grass
renpy.image(Transform(img, size=(self.sizes), pos=(x, y)) )
x += self.width
y += self.height
x = 0
screen show_map:
$ level.draw() # I only call the class method.