from scene import *
import random, sound
from arrows import *
sw, sh = get_screen_size()
rect_w = sw/3 #343.33
rect_h = 612 #668
side = int(rect_w/10)
colors = ['red']
x = side/2
y = rect_h/2 - side/2
dot = [[
[x, y]
]]
line = [
[[x, y], [x+side, y]],
[[x, y], [x, y-side]]
]
shapes = [dot, line]
class Board(ShapeNode):
def __init__(self, stroke_color='lightgrey', line_width=1, parent=None, *args, **kwargs):
path = ui.Path.rect(0, 0, rect_w, rect_h)
path.line_width = line_width
if stroke_color == 'lightgrey':
d = int(rect_w/10)
for l in range(int(rect_w/d)):
x = l*d
path.move_to(x, 0)
path.line_to(x, rect_h)
super().__init__(path,
fill_color='white',
stroke_color=stroke_color,
parent=parent,
*args, **kwargs)
class Game(Scene):
def setup(self):
self.background_color = 'white'
self.grey_rect = Board(line_width=2, parent=self, position=(sw/3, sh/2), z_position=0)
self.board = Board(stroke_color='purple', line_width=15, parent=self, position=(sw/3, sh/2), z_position=-1)
self.seconds = 0
self.figure = {}
self.add_buttons()
self.add_figure()
def update(self):
self.seconds += self.dt
if self.seconds > 0.2:
for f in self.figure:
self.figure[f][1] -= side/2
f.position = self.figure[f]
self.seconds = 0
if f.position.y == - rect_h/2 + side/2:
self.figure.pop(f)
self.add_figure()
break
def touch_began(self, touch):
tapped = True
for arw in self.arrows:
if touch.location in arw.frame:
sound.play_effect('rpg:Chop')
arw.fill_color = '#969696'
for f in self.figure:
if -rect_w/2 < self.figure[f][0] + side < rect_w/2:
if 'right' in arw.picture:
self.figure[f][0] += side
if -rect_w/2 < self.figure[f][0] - side < rect_w/2:
if 'left' in arw.picture:
self.figure[f][0] -= side
def touch_ended(self, touch):
for arw in self.arrows:
if arw.fill_color == '#969696':
arw.fill_color = 'white'
right = left = down = up = None;
def add_buttons(self):
self.arrows = [Arrow(i, position=icons[i], parent=self) for i in icons]
def add_figure(self):
figure = random.choice(shapes)
#for example, var=0 for horizontal line, 1 - for vertical
var = random.choice(range(len(figure)))
print(figure[var])
global x
global y
x = random.choice(range(10)) * side - rect_w/2 + side/2
y = rect_h/2 - side/2
for pos in figure[var]:
print(pos)
block = SpriteNode('pzl:Gray3', pos, color=colors[shapes.index(figure)] , size=(side, side), parent=self.grey_rect)
self.figure[block] = pos
run(Game())
There are a lot of bugs cause I move the blocks one by one. And I added colors but they mix with the original color