Esempio n. 1
0
	def __render(self):
		w = core.get_value("Width")
		h = core.get_value("Height")
		if w != self.__width or h != self.__height:
			for i in range(self.__width, self.__width * self.__height):
				core.delete_draw_command("Canvas", f"quad-{i}")

			self.__width = w
			self.__height = h
			for i in range(self.__width, self.__width * self.__height):
				core.draw_quad("Canvas", (0, 0), (0, 0), (0, 0), (0, 0), (0, 0, 0, 0), thickness=0, tag=f"quad-{i}")
			self.__fire = [0] * (self.__height * self.__width)

		for x in range(self.__width):
			self.__fire[x + self.__width] = random.random() * 255

		for y in range(self.__height - 1, 1, -1):
			for x in range(self.__width):
				i = y * self.__width + x
				w2 = (x + self.__width) % self.__width
				self.__fire[i] = math.floor((
					self.__fire[(y - 1) * self.__width + w2] +
					self.__fire[(y - 1) * self.__width + (x - 1 + self.__width) % self.__width] +
					self.__fire[(y - 2) * self.__width + w2] +
					self.__fire[(y - 1) * self.__width + (x + 1 + self.__width) % self.__width]) /
					4.34)

		ws, hs = core.get_main_window_size()
		xScale = ws / self.__width
		yScale = hs / self.__height

		for i in range(self.__width, self.__width * self.__height):
			kwarg = {}
			x1 = (i % self.__width) * xScale
			y1 = (self.__height - math.floor(i / self.__width)) * yScale
			kwarg['p1'] = (x1, y1)
			kwarg['p2'] = (x1 + xScale, y1)
			kwarg['p3'] = (x1 + xScale, y1 + yScale)
			kwarg['p4'] = (x1, y1 + yScale)

			r = self.__fire[i]
			g = int(self.__fire[i] * .2)
			kwarg['color'] = (r, g, 0, 255)
			kwarg['fill'] = (r, g, 0, 255)
			core.modify_draw_command("Canvas", f"quad-{i}", **kwarg)
Esempio n. 2
0
    def __render(self):
        delta = core.get_delta_time()
        # offset everyone the delta amount
        x, y, h, v = self.__pos
        size = core.get_main_window_size()
        x += (h * delta)
        y += (v * delta)

        x1 = x - self.__radius
        x2 = x + self.__radius
        y1 = y - self.__radius
        y2 = y + self.__radius

        # hit walls
        if x1 <= 10 or x2 >= size[0] - 10:
            h += (math.copysign(1, h) * 0.1 * self.__speed)
            h *= -1
        if y1 <= 50 or y2 >= size[1] - 100:
            v += (math.copysign(1, v) * 0.1 * self.__speed)
            v *= -1

        # hit paddle....
        if x > self.__paddle[0] - self.__paddleSize[0] and \
         x < self.__paddle[0] + self.__paddleSize[0] and \
         y > self.__paddle[1] - 1.5 * self.__paddleSize[1]:
            v *= -1

        # check bricks ??? all of them? ouch...
        for k, rect in self.__board.items():
            if x2 >= rect[0] and x1 <= rect[2] and y2 >= rect[
                    1] and y1 <= rect[3]:
                px, py = k
                core.delete_draw_command("canvas", f"brick-{px}.{py}")
                del self.__board[k]
                v *= -1
                h += (math.copysign(1, h) * 0.1 * self.__speed)
                break

        core.modify_draw_command("canvas", "ball", center=[x, y])
        v = min(self.__speedMax, max(-self.__speedMax, v))
        h = min(self.__speedMax, max(-self.__speedMax, h))
        self.__pos = (x, y, h, v)
Esempio n. 3
0
 def __move(self, direction):
     x, y = self.__paddle
     delta = core.get_delta_time()
     x += direction * delta * self.__paddleSpeed
     # bounds
     size = core.get_main_window_size()
     if x < self.__paddleSize[0]:
         x = self.__paddleSize[0]
     if x > size[0] - self.__paddleSize[0]:
         x = size[0] - self.__paddleSize[0]
     pmin = [
         self.__paddle[0] - self.__paddleSize[0],
         self.__paddle[1] - self.__paddleSize[1]
     ]
     pmax = [
         self.__paddle[0] + self.__paddleSize[0],
         self.__paddle[1] + self.__paddleSize[1]
     ]
     core.modify_draw_command("canvas", "paddle", pmin=pmin, pmax=pmax)
     self.__paddle = (x, y)
Esempio n. 4
0
 def __set__(self, instance: DrawCommand, value: Any) -> None:
     config = self.fconfig(instance, value)
     dpgcore.modify_draw_command(instance.canvas.id, instance.id, **config)
Esempio n. 5
0
 def set_config(self, **config: Any) -> None:
     dpgcore.modify_draw_command(self.canvas.id, self.id, **config)