Exemple #1
0
def draw_line_with_fraction(x0, y0, x1, y1, col):
    # 2点のどちらが始点か[点1, (点2)]
    # x, y のどちらを基準軸にするか[x, y]
    ### for 文を回す時の方向
    ### w > h の時 x
    ### w = h の時 どっちでも
    ### w < h の時 y

    # 基準軸の方向
    # サブ軸の方向

    w = x1 - x0
    h = y1 - y0
    is_steep = h > w

    error = Fraction(0)
    gradient = abs(Fraction(h) / Fraction(w))
    y = y0
    for x in range(x0, x1 + 1):
        if is_steep:
            pyxel.pset(y, x, col)
        else:
            pyxel.pset(x, y, col)
        error += gradient
        if error >= 0.5:
            y += 1
            error -= Fraction(1)
Exemple #2
0
    def draw(self):
        if (self.heal > 0):

            self.collisionObject.draw()

            for pixel in self.points:
                pyxel.pset(pixel[0], pixel[1], 11)
            for i in range(1, len(self.points)):
                point = self.points[i - 1]
                nextPoint = self.points[i]
                pyxel.line(point[0], point[1], nextPoint[0], nextPoint[1],
                           self.col)
            pyxel.line(self.points[0][0], self.points[0][1], self.points[3][0],
                       self.points[3][1], self.col)

            for shoot in self.shoots:
                shoot.draw()
            # pyxel.trib(self.points[0][0],self.points[0][1],self.points[1][0],self.points[1][1],self.points[3][0],self.points[3][1],self.col)
            if (self.otherPlayer): self.angleController.draw()
            if (pyxel.btn(pyxel.KEY_TAB)):
                pyxel.text(self.pos[0] - (len(self.name) * 2),
                           self.pos[1] + 10, self.name, 7)
                pyxel.rectb(self.pos[0] - 12, self.pos[1] + 16, 24, 8, 7)
                pyxel.rect(self.pos[0] - 10, self.pos[1] + 18, self.heal / 5,
                           4, 7)
Exemple #3
0
    def draw(self):
        pyxel.cls(0)
        # 星
        for i in range(0, 96):
            pyxel.pset(EndingScene.star_ary[i][0], i * 2,
                       int(random.randrange(0, 2) + 5))

        pyxel.blt(128 - 56 / 2, 40, 2, 128, 48, 56, 56, 2)
        if self.state == 0:
            Drawing.stretchBlt(self.px - self.sx * self.size/2, self.py - self.sy * self.size/2, 	\
             self.sx * self.size, self.sy * self.size,	\
             1, 0, 0, self.sx, self.sy)
        elif self.state == 2:
            px = 132
            py = 60
            if self.cnt < 18:
                self.drawShine(px, py, int(self.cnt / 6))
            elif self.cnt < 60:
                if self.cnt & 2 == 0:
                    self.drawShine(px, py, 2)
            elif self.cnt < 80:
                self.drawShine(px, py, int(2 - (self.cnt - 62) / 6))
            elif self.cnt >= 150:
                l = int((self.cnt - 150) / 20)
                sl = len(self.message)
                if l > sl:
                    l = sl
                Drawing.showText(128 - sl * 4, 120, self.message[:l])

        for obj in self.objs:
            if obj.removeFlag == False:
                obj.draw()
Exemple #4
0
def DebugDrawPosHitRect(self):
    if imp._DEBUG_ == True:
        pyxel.pset(self.PosX, self.PosY, pyxel.frame_count % 16)
        pyxel.rectb(self.PosX - (self.HitRectX / 2),
                    self.PosY - (self.HitRectY / 2), self.HitRectX,
                    self.HitRectY, pyxel.frame_count % 16)
    return
Exemple #5
0
 def _drawSnake(self):
     if self.snake.alive:
         snake_colors = [6, 12, 5, 1]
         idx_color = 1
         for part in self.snake.body:
             pyxel.pset(part.x, part.y, snake_colors[idx_color - 1])
             idx_color = min((idx_color + 1), len(snake_colors))
Exemple #6
0
def draw():
    pyxel.cls(0)
    for y in range(0, SIZE):
        for x in range(0, SIZE):
            if cell_matrix[x,
                           y]:  # Pequeña optimización. No pintar celdas vacías
                pyxel.pset(x, y, 1)
Exemple #7
0
    def draw(self):
        pyxel.cls(0)
        for i in range(0, 96):
            x = (EndingScene.star_ary[i][0] + self.pos) & 255
            y = (i * 2 + self.pos) % 200
            pyxel.pset(x, y, int(random.randrange(0, 2) + 5))

        x = self.px  #+ random.randrange(-1, 1)
        y = self.py  #+ random.randrange(-1, 1)
        pyxel.blt(x, y, 2, 0, 48, 96, 80, 0)
        if self.cnt & 2 == 0:
            if self.state < 2:
                if self.cnt % 4 == 0:
                    pyxel.blt(x + 77, y + 75, 2, 0, 128, 48, 48, 0)
                else:
                    pyxel.blt(x + 77, y + 75, 2, 48, 128, 56, 56, 0)
            else:
                if self.cnt % 4 == 0:
                    pyxel.blt(x + 77, y + 75, 2, 48, 128, 56, 56, 0)
                else:
                    pyxel.blt(x + 77, y + 75, 2, 104, 128, 72, 72, 0)

        for obj in self.objs:
            if obj.removeFlag == False:
                obj.draw()
    def text(self, x: int, y: int, txt, color: int = 7):
        '''
        テキストを出力する

        pyxel.txtの上位互換で、引数のtxtにKANA_DICのキーをlist/tupleで設定することでカナ文字が表示できます。
        '''
        _txtlist = []
        if type(txt) == str:
            _txtlist.append(txt)
        else:
            _txtlist = list(txt)

        for _value in _txtlist:
            if _value == "":
                continue

            if _value[0] == "*":
                _v = _value[1:len(_value)]
                pyxel.text(x, y + 1, _v, color)
                x = x + 4 * len(_v)

            else:
                try:
                    for _row, _rowdata in enumerate(self.KANA_DIC[_value]):
                        for _col, _v in enumerate(_rowdata):
                            if _v == "1":
                                pyxel.pset(x + _col, y + _row, color)
                    x = x + 8
                except KeyError:
                    x = x + 8
                    continue
Exemple #9
0
def draw():
    # Mostra ponto inicial e legenda.
    if pyxel.frame_count == 0:
        pyxel.text(10, 160, "t positivo", pyxel.COLOR_GREEN)
        pyxel.text(10, 170, "t negativo", pyxel.COLOR_RED)
        x, y = pyxel.R0
        pyxel.text(x, pyxel.height - y, str(list(pyxel.R0)), pyxel.COLOR_WHITE)

    # Marca pontos na tela a partir da parametrização da reta.
    dt = pyxel.dt / pyxel.steps
    R0, n = pyxel.R0, pyxel.n

    for i in range(pyxel.steps):
        t = pyxel.time + dt * i

        x1, y1 = R0 + n * t
        x2, y2 = R0 - n * t

        pyxel.pset(x1, pyxel.height - y1, pyxel.COLOR_GREEN)
        pyxel.pset(x2, pyxel.height - y2, pyxel.COLOR_RED)

    # Desenha tempo decorrido no canto inferior direito
    pyxel.time += pyxel.dt
    x, y = (pyxel.width - pyxel.FONT_WIDTH * 14,
            pyxel.height - pyxel.FONT_HEIGHT)
    pyxel.rect(x, y, pyxel.FONT_WIDTH * 14, pyxel.FONT_HEIGHT,
               pyxel.COLOR_BLACK)
    pyxel.text(x, y, ("t = %.1f" % pyxel.time).rjust(10), pyxel.COLOR_WHITE)
Exemple #10
0
    def draw_first_person(self):
        # Draw ceiling
        pyxel.rect(0, 0, WIDTH, horizon, 10)

        # Draw floor
        pyxel.rect(0, horizon, WIDTH, HEIGHT - horizon, 9)

        # Draw walls...

        # Calculate the angle of the LEFT MOST ray in the FOV.
        alpha = left_extreme(phi)

        for vx in range(WIDTH):
            ray_alpha = ray(X, Y, alpha)

            wx, wy, ix, iy = trace(X, Y, *ray_alpha)

            d = sqrt(dsq(X, Y, ix, iy))
            p = d * cos(alpha - phi)
            h = 2 * HEIGHT / p

            top = horizon - floor(h / 2)
            bot = horizon + floor(h / 2)
            for vy in range(top, bot):
                # draw pixel at (vx, vy)
                tx, ty = texture_coordinates(ix, iy, h, vy - top, 16, 16)
                # color = bricks[ty][tx]
                color = pyxel.image(0).get(tx, ty)

                pyxel.pset(vx, vy, color)

            alpha += epsilon
Exemple #11
0
def draw_stars():
    pyxel.cls(pyxel.COLOR_BLACK)

    if pyxel.frame_count % 8 == 0:
        star_field[:] = stars_field_commands()
    for args in star_field:
        pyxel.pset(*args)
Exemple #12
0
def draw():
    draw_stars()
    if pyxel.btn(pyxel.MOUSE_LEFT_BUTTON):
        pyxel.circ(pyxel.mouse_x, pyxel.mouse_y, 2, pyxel.COLOR_RED)
    else:
        pyxel.pset(pyxel.mouse_x, pyxel.mouse_y, pyxel.COLOR_WHITE)
    sp.draw()
Exemple #13
0
def linehoriz2(x1, y1, x2, y2):

    m_new = 2 * (y2 - y1)
    slope_error_new = m_new - (x2 - x1)
    points = []

    y = y1
    for x in range(x1, x2 + 1):
        points.append((x, y))

        # Add slope to increment angle formed
        slope_error_new = slope_error_new + m_new
        # Slope error reached limit, time to
        # increment y and update slope error.
        if (slope_error_new >= 0):
            y += 1
            slope_error_new = slope_error_new - 2 * (x2 - x1)
    trigger = False
    for i in points:
        pyxel.pset(i[0], i[1], 10)
        trigger = True
    if not trigger:
        #print("Didn't work")
        line(x1, y1, x2, y2)
    else:
        #print('lines:',x1,y1," -> ",x2,y2)
        pass
    def draw_shield(self):

        shield_start = self.shield_center - self.shield_size
        shield_end = self.shield_center + self.shield_size - 1
        # print(self.shield)

        # print(len(self.shield))
        # print(len(range(math.floor(shield_start),math.floor(shield_end))))

        s_index = 0
        for a in range(int(shield_start), int(shield_end)):
            b = math.radians(a)
            if 0 <= a % 90 < 90:
                sx = self.x + 15 * math.cos(b)
                sy = self.y - 15 * math.sin(b)
            elif 90 <= a % 90 < 180:
                sx = self.x - 15 * math.cos(b)
                sy = self.y - 15 * math.sin(b)
            elif 180 <= a % 90 < 270:
                sx = self.x - 15 * math.cos(b)
                sy = self.y + 15 * math.sin(b)
            elif 270 <= a % 90 < 360:
                sx = self.x + 15 * math.cos(b)
                sy = self.y + 15 * math.sin(b)
            self.shield[s_index] = ([sx, sy])
            # pyxel.pset(self.x+15*math.cos(b), self.y-15*math.sin(b), 9)
            # pyxel.line(self.x+14*math.cos(b), self.y-14*math.sin(b), self.x+15*math.cos(b), self.y-15*math.sin(b), 9)
            s_index += 1
        for s in self.shield[:len(self.shield) - 1]:
            color = 7
            pyxel.pset(s[0], s[1], color)
            pyxel.pset(s[0] - 1, s[1] - 1, color)
            pyxel.pset(s[0] + 1, s[1] - 1, color)
            pyxel.pset(s[0] + 1, s[1] + 1, color)
            pyxel.pset(s[0] - 1, s[1] + 1, color)
Exemple #15
0
def poly(points):
    def squarePolar(point, centre):
        return [
            math.atan2(point[1] - centre[1], point[0] - centre[0]),
            (point[0] - centre[0])**2 + (point[1] - centre[1])**2
        ]

    def polySort(points):  #main algorithm
        # Get "centre of mass"
        centre = [
            reducer(lambda sum, p: sum + p[0], points) / len(points),
            reducer(lambda sum, p: sum + p[1], points) / len(points)
        ]  #get center of mass
        # Sort by polar angle and distance, centered at this centre of mass.
        for point in points:
            for x in squarePolar(point, centre):
                point.append(x)

        points = sort(points, handler=lambda a, b: a[2] - b[2] or a[3] - b[3])
        #  Throw away the temporary polar coordinates
        for point in points:
            point = point[:len(point) - 2]
        return points

    def draw(points):
        todraw = []
        if (not points):
            return
        for i in points:
            x, y = i[0], i[1]
            todraw.append((x, y))
        #it =  iter(points)
        #for i,i2 in zip(it,it):
        for index in range(len(points)):
            if i != len(points):
                indexlast = index
                i = points[index - 1]
                i2 = points[index]
                x1, y1 = i[0], i[1]
                x2, y2 = i2[0], i2[1]
                trace = line(x1, y1, x2, y2)

        #print("custom one:")
        i = points[indexlast]
        i2 = points[0]
        x1, y1 = i[0], i[1]
        x2, y2 = i2[0], i2[1]
        trace = line(x1, y1, x2, y2)
        #print('lines:',x1,y1," -> ",x2,y2)

        return todraw

    #print("\n\n")
    for i in draw(polySort(points)):
        #for i in draw(points):
        #print("\n",i)
        pyxel.pset(i[0], i[1], 10)

    i = """		// Main algorithm:
Exemple #16
0
 def draw(self):
     """Draw sphere at viewport center."""
     pyxel.cls(BG_COL)  # Clear screen
     for point in self.my_sphere.vectors:
         px_out = point + ORIGIN
         pyxel.pset(px_out.x, px_out.y, px_out.b)
     self.draw_hud()
     pyxel.flip() # Progress pyxel
Exemple #17
0
def degrade(c1, c2):
    pyxel.cls(c1)

    for y in range(pyxel.height):
        prob = y / pyxel.height
        for x in range(pyxel.width):
            if random.random() < prob:
                pyxel.pset(x, y, c2)
Exemple #18
0
    def draw(self):
        pyxel.cls(0)

        for dy, dx in product(range(H), range(W)):
            x = self.x + dx
            y = self.y + dy
            if self.game_map[dy][dx]:
                pyxel.pset(x, y, 11)
Exemple #19
0
    def test_pset(self, x, y):
        pyxel.text(x, y, "pset(x,y,col)", 7)

        x += 4
        y += 10

        for i in range(16):
            pyxel.pset(x + i * 2, y, i)
Exemple #20
0
def draw_points(pts, color):
    """
    Desenha lista de pontos com a cor fornecida.
    """
    scale = 50
    for x, y in pts:
        i = scale * x + 120
        j = pyxel.height - scale * y - 80
        pyxel.pset(i, j, color)
Exemple #21
0
 def draw_endpoint(pt):
     x, y = pt
     xend = round(x)
     yend = y + grad * (xend - x)
     xgap = _rfpart(x + 0.5)
     px, py = int(xend), int(yend)
     pyxel.pset(px, py, 10)  # color, _rfpart(yend) * xgap)
     pyxel.pset(px, py + 1, 10)  #, _fpart(yend) * xgap)
     return px
 def draw_star(self):
     '''
     星を描画
     '''
     # 生成された星を移動する
     for idx, value in enumerate(self.star_flg):
         if value == 1:
             pyxel.pset(self.star_x[idx], self.star_y[idx],
                        self.star_col[idx])
    def draw(self):
        # Don't forget to clear screen on every frame!
        pyxel.cls(0)

        # Draw the pyxel location:
        pyxel.text(5, 5, f'({self.x}, {self.y})', 7)

        # Draw the text at position: (text_x, text_y)
        pyxel.pset(self.x, self.y, 8)
Exemple #24
0
    def draw_snake(self):
        """Draw the snake with a distinct head by iterating through deque."""

        for i, point in enumerate(self.snake):
            if i == 0:
                colour = COL_HEAD
            else:
                colour = COL_BODY
            pyxel.pset(point.x, point.y, col=colour)
Exemple #25
0
def draw_splash2(o, offset):
    r = offset
    for i in range(1, 201):
        rr = math.sqrt((o.cnt * 2 + i) * 20)
        pyxel.pset(o.x + (o.right - o.left + 1) / 2 + math.cos(r) * rr,
                   o.y + (o.bottom - o.top + 1) / 2 + math.sin(r) * rr,
                   7 + int(o.cnt % 2) * 3)
        #- kore ha tekito
        r += 0.11 + i * 0.04
Exemple #26
0
 def draw_panel(x, y, width, height, *, with_shadow=True):
     w = width
     h = height
     pyxel.line(x + 1, y, x + w - 2, y, WIDGET_PANEL_COLOR)
     pyxel.rect(x, y + 1, w, h - 2, WIDGET_PANEL_COLOR)
     pyxel.line(x + 1, y + h - 1, x + w - 2, y + h - 1, WIDGET_PANEL_COLOR)
     if with_shadow:
         pyxel.line(x + 2, y + h, x + w - 1, y + h, WIDGET_SHADOW_COLOR)
         pyxel.line(x + w, y + 2, x + w, y + h - 1, WIDGET_SHADOW_COLOR)
         pyxel.pset(x + w - 1, y + h - 1, WIDGET_SHADOW_COLOR)
Exemple #27
0
 def draw(self):
     if self.cnt & 3 == 0:
         pyxel.blt(self.x - 22, self.y - 7.5, 2, self.imageSourceX,
                   self.imageSourceY, 24, 16, 0)
     elif self.cnt & 3 == 1:
         pyxel.blt(self.x - 22, self.y - 7.5, 2, self.imageSourceX,
                   self.imageSourceY + 16, 24, 16, 0)
     for s in self.tbl:
         y = s.x * s.x * s.a
         pyxel.pset(self.x - s.x, self.y - y, 7)
Exemple #28
0
    def draw(self):
        if self.state == 4:
            if self.cnt > 20:
                if self.cnt & 3 == 0:
                    pyxel.blt(self.x - 22, self.y + 22, 1, 48, 208, 24, 16, 0)
                elif self.cnt & 3 == 1:
                    pyxel.blt(self.x - 22, self.y + 22, 1, 48, 224, 24, 16, 0)
            for s in self.tbl:
                y = s.x * s.x / s.a
                pyxel.pset(self.x - s.x, self.y + 28 - y + s.y, 7)
        # 本体
        pyxel.blt(self.x, self.y + 8, 1, 160, 208, 40, 48, gcommon.TP_COLOR)
        if self.isLeft:
            pyxel.blt(self.x + 40, self.y + 8, 1, 200, 208, 32, 48,
                      gcommon.TP_COLOR)
        else:
            pyxel.blt(self.x + 40, self.y + 8, 1, 128, 136, 32, 48,
                      gcommon.TP_COLOR)
        pyxel.blt(self.x + 72, self.y, 1, 232, 200, 24, 56, gcommon.TP_COLOR)

        # バーニア
        if self.dy > 0.1:
            if self.cnt & 3 == 0:
                pyxel.blt(self.x + 24, self.y - 6, 1, 24, 176, 8, -26, 0)
                pyxel.blt(self.x + 72, self.y - 6, 1, 24, 176, 8, -26, 0)
            elif self.cnt & 3 == 2:
                pyxel.blt(self.x + 24, self.y - 6, 1, 32, 176, 8, -26, 0)
                pyxel.blt(self.x + 72, self.y - 6, 1, 32, 176, 8, -26, 0)
        elif self.dy < -0.1:
            if self.cnt & 3 == 0:
                pyxel.blt(self.x + 24, self.y + 42, 1, 24, 176, 8, 26, 0)
                pyxel.blt(self.x + 72, self.y + 42, 1, 24, 176, 8, 26, 0)
            elif self.cnt & 3 == 2:
                pyxel.blt(self.x + 24, self.y + 42, 1, 32, 176, 8, 26, 0)
                pyxel.blt(self.x + 72, self.y + 42, 1, 32, 176, 8, 26, 0)

        # ビーム表示
        if self.beam >= 1 and self.beam <= 5:
            bx = self.x - 12
            while (bx > -8):
                pyxel.blt(bx, self.y + 10, 1, (self.beam - 1) * 8, 208, 8, 40,
                          gcommon.TP_COLOR)
                bx -= 8

        if self.beam == 6:
            # ビーーーーーーーーーーーーーーーム!!!
            pyxel.blt(self.x - 16, self.y + 10, 1, 144, 208, 16, 40,
                      gcommon.TP_COLOR)
            bx = self.x - 32
            sx = 128 - ((self.cnt >> 1) & 3) * 16
            while (bx > -32):
                pyxel.blt(bx, self.y + 10, 1, sx, 208, 16, 40,
                          gcommon.TP_COLOR)
                bx -= 16
Exemple #29
0
    def draw(self):
        """Draw the background, snake, score, and apple OR the end screen."""

        if not self.death:
            pyxel.cls(col=COL_BACKGROUND)
            self.draw_snake()
            self.draw_score()
            pyxel.pset(self.apple.x, self.apple.y, col=COL_APPLE)

        else:
            self.draw_death()
Exemple #30
0
 def draw(self):
     px.bltm(-self.position.x + self.original_position.x,
             -self.position.y + self.original_position.y, 0, 0, 0, 255, 255)
     px.blt(self.original_position.x,
            self.original_position.y,
            0,
            8,
            8,
            8,
            8,
            colkey=1)
     px.pset(self.x, self.y, px.COLOR_PINK)