예제 #1
0
파일: qbot.py 프로젝트: ihasdapie/pong_180
 def __init__(self, table_dim, margins, p1, p2, b):
     self.p1 = fRect(p1.pos, p2.size)
     self.p2 = fRect(p1.pos, p2.size)
     self.b = fRect(b.pos, b.size)
     self.dim = (table_dim[0], table_dim[1])
     self.walls_Rects = [Rect((-100, -100), (table_size[0]+200, 100)),
                    Rect((-100, table_size[1]), (table_size[0]+200, 100))]
예제 #2
0
    def draw(self, p_game_screen: Surface, p_actor: Actor):
        """
        Draw an Energy bar on a Surface using the energy value of an Actor

        Args:
            p_game_screen: The Surface to draw to
            p_actor: The Actor to display the energy status of
        """
        if p_actor.get_energy() > 70:
            rectangle = Rect(self.coordinate.get_x(), self.coordinate.get_y(),
                             60, 20)
            draw.rect(p_game_screen, color.THECOLORS['green'], rectangle)
        elif p_actor.get_energy() > 30:
            rectangle = Rect(self.coordinate.get_x(), self.coordinate.get_y(),
                             60, 20)
            draw.rect(p_game_screen, color.THECOLORS['orange'], rectangle)
        else:
            rectangle = Rect(self.coordinate.get_x(), self.coordinate.get_y(),
                             60, 20)
            draw.rect(p_game_screen, color.THECOLORS['red'], rectangle)

        rectangle_border = Rect(self.coordinate.get_x() - 3,
                                self.coordinate.get_y() - 3, 65, 25)
        draw.rect(p_game_screen, color.THECOLORS['black'], rectangle_border, 2)

        self.draw_header(p_game_screen, "Energy")
예제 #3
0
def 그리기(점수판, 게임종료):

    # 음식 그리기
    for food in 음식:
        pygame.draw.ellipse(화면, (0, 255, 0),
                            Rect(food[0] * 20, food[1] * 20, 20, 20))
        # 타원그리기( 화면이동 , (칼라[RGB] , 타원( x축 , y축 , 가로크기 , 세로크기 )

    # 점수 그리기
    if 점수판 != None:  # 점수에 내용이 있으면
        화면.blit(점수판, (10, 10))  # x좌표 y좌표 표기

    # 뱀 그리기
    for body in 뱀:
        pygame.draw.rect(화면, (0, 255, 255),
                         Rect(body[0] * 20, body[1] * 20, 20, 20))
        # 사각형그리기( 화면이름 , (칼라[RGB] , 사각형( x축 , y축 , 가로크기 , 세로크기 )

    # 종료메세지 그리기
    if 게임종료:  # 게임종료메세지 내용이 있으면
        게임종료메세지 = my글꼴.render("게임 종료 [ 획득점수는: ] " + str(점수), True,
                              (255, 255, 0))
        화면.blit(게임종료메세지, (275, 450))  # x좌표 y좌표에 표기

    pygame.display.update()  # 화면 업데이트
예제 #4
0
파일: draw_rect1.py 프로젝트: Ikaasa/MasaP
def main():
    """ main routine """

    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        SURFACE.fill((255, 255, 255))

        # 赤:矩形(塗りつぶし)
        pygame.draw.rect(SURFACE, (255, 0, 0), (10, 20, 100, 50))

        # 赤:矩形(太さ3)
        pygame.draw.rect(SURFACE, (255, 0, 0), (150, 10, 100, 30), 3)

        # 緑:矩形
        pygame.draw.rect(SURFACE, (0, 255, 0), ((100, 80), (80, 50)))

        # 青:矩形、Rectオブジェクト
        rect0 = Rect(200, 60, 140, 80)
        pygame.draw.rect(SURFACE, (0, 0, 255), rect0)

        # 黄:矩形、Rectオブジェクト
        rect1 = Rect((30, 160), (100, 50))
        pygame.draw.rect(SURFACE, (255, 255, 0), rect1)

        pygame.display.update()
        FPSCLOCK.tick(3)
예제 #5
0
    def update(self, game):
        """update - update the game window"""
        #self.game_plane.image.blit(self.game_background, (0,0)) #reset background drawing
        for c in game.cities:
            if not c.plane:
                c.plane = clickndrag.Plane("city of %s" % c.name,
                                           Rect(c.location, c.image_size))
                c.plane.image.blit(c.image, (0, 0))
                self.game_plane.sub(c.plane)

        for d in game.dredges:
            if not d.plane:
                image_size = 50, 50
                d.plane = clickndrag.Plane(d.name,
                                           Rect(d.location, image_size))
                d.plane.image.set_colorkey(white)
                d.plane.image.fill(white)
                draw_dredge(d.plane.image, d.dimensions,
                            image_size[0])  #todo: figure out scaling
                #d.plane.image.blit(d.image, (0,0))
                d.plane.draggable = True
                self.game_plane.sub(d.plane)

        self.date_status.text = game.date.strftime("Date: %d %B %Y")
        self.player_status.text = "Value: {0:,}".format(
            int(game.players[0].value))
        self.screen.update()
        self.screen.render()

        pygame.display.flip()
        return True
예제 #6
0
    def __init__(self, city, msgs=[], padding=0, background_color=None):
        """
        initialize.  Initialized with a name, destroy button in upper right, and
        basic city information.
        """
        planes.gui.Container.__init__(self, "{}_status".format(city.name),
                                      padding, background_color)
        self.city = city
        if city.owner:
            owner_name = city.owner.name
        else:
            owner_name = 'Neutral'
        city_data_strs = [('city_name', city.name), ('city owner', owner_name)]
        city_data_strs.extend(msgs)
        self.num_proj = -1

        name_length = max([len(s[1])
                           for s in city_data_strs]) * char_width + char_width
        for s in city_data_strs:
            name_label = planes.gui.Label(s[0],
                                          s[1],
                                          Rect(0, 0, name_length, 15),
                                          background_color=teal)
            self.sub(name_label)

        destroy_button = planes.gui.Button(
            'X',
            Rect(name_label.rect.width - char_width, 0, char_width, 15),
            lambda x: x.parent.parent.destroy(),
            background_color=teal)
        name_label.sub(destroy_button)
예제 #7
0
def main():
    """main routine"""

    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        SURFACE.fill((255, 255, 255))

        pygame.draw.rect(SURFACE, (255, 0, 0), (10, 20, 100, 50))
        pygame.draw.rect(SURFACE, (255, 0, 0), (150, 10, 100, 30), 3)
        pygame.draw.rect(SURFACE, (0, 255, 0), ((100, 80), (80, 50)))

        rect0 = Rect(200, 60, 140, 80)
        pygame.draw.rect(SURFACE, (0, 0, 255), rect0)

        rect1 = Rect((30, 160), (100, 50))
        pygame.draw.rect(SURFACE, (255, 255, 0), rect1)

        # circle( Surface, color, pos, radius, width = 0) -> Rect
        pygame.draw.circle(SURFACE, (255, 0, 0), (150, 50), 20, 10)

        # ellipse( Surface, color, Rect, width = 0) -> Rect
        pygame.draw.ellipse(SURFACE, (0, 255, 0), (50, 150, 110, 60), 5)

        # line( Surface, color, start_ pos, end_ pos, width = 1) -> Rect
        # 青: 斜線( 太 さ 10)
        start_pos = (300, 30)
        end_pos = (380, 200)
        pygame.draw.line(SURFACE, (0, 0, 255), start_pos, end_pos, 10)

        pygame.display.update()
        FPSCLOCK.tick(3)
예제 #8
0
파일: functions.py 프로젝트: ghyde/kcc_2019
    def draw_scoreboard(self, screen, screen_size, score):
        """Draws a box with the score in it onto the screen."""
        screenw, screenh = screen_size
        wellx, welly = self.well_pixel_coords(screen_size)
        wellw, wellh = self.well_size()
        border_size = 5
        padding = 20
        height = 50

        left = wellx + wellw + padding
        right = screenw - padding
        top = welly
        #bottom = top + height
        width = right - left + 1

        pygame.draw.rect(
            screen, Color(255, 255, 255, 255),
            Rect(left - border_size, top - border_size,
                 width + border_size * 2, height + border_size * 2))
        pygame.draw.rect(screen, Color(0, 0, 0, 255),
                         Rect(left, top, width, height))

        text = str(score)
        font = pygame.font.SysFont("Lucida Console", 32, 1, 0)
        text_surface = font.render(text, False, Color(255, 255, 255, 255))
        screen.blit(text_surface,
                    (left + (width - text_surface.get_width()) / 2, top +
                     (height - text_surface.get_height()) / 2))
예제 #9
0
def paint(message):
    SURFACE.fill((0, 0, 0))
    for food in FOODS:
        pygame.draw.ellipse(SURFACE, (0, 255, 0),
                            Rect(food[0] * 30, food[1] * 30, 30, 30))
    for bomb in BOMBS:
        pygame.draw.ellipse(SURFACE, (255, 0, 0),
                            Rect(bomb[0] * 30, bomb[1] * 30, 30, 30))
    for body in SNAKE:
        pygame.draw.rect(SURFACE, (0, 255, 255),
                         Rect(body[0] * 30, body[1] * 30, 30, 30))
    for enemy in ENEMY:
        pygame.draw.rect(SURFACE, (255, 30, 30),
                         Rect(enemy[0] * 30, enemy[1] * 30, 30, 30))
    for index in range(20):
        pygame.draw.line(SURFACE, (64, 64, 64), (index * 30, 0),
                         (index * 30, 600))
        pygame.draw.line(SURFACE, (64, 64, 64), (0, index * 30),
                         (600, index * 30))
    if message is not None:
        SURFACE.blit(message, (150, 300))

    smallfont = pygame.font.SysFont(None, 36)
    message_score = smallfont.render("SCORE = "
                                     f'{len(SNAKE)}', True, (0, 255, 255))
    SURFACE.blit(message_score, (250, 0))

    pygame.display.update()
	def __init__(self, x_dim, y_dim):

		init()

		# Dimensions Game Screen (grid)
		self.x_dim = x_dim
		self.y_dim = y_dim
		self.MARGIN = 8
		self.HEADER_BAR = 70
		self.SPACE_PIXELS = 32

		if (self.SPACE_PIXELS*self.x_dim + 2 * self.MARGIN) < 550 :
			self.WIDTH = 550
		else:
			self.WIDTH = self.SPACE_PIXELS*self.x_dim + 2 * self.MARGIN

		self.HEIGHT = self.SPACE_PIXELS*self.y_dim + 2 * self.MARGIN + self.HEADER_BAR
		self._screen = display.set_mode((self.WIDTH, self.HEIGHT))
		display.set_caption("BitSweeper")

		if (self.x_dim*self.SPACE_PIXELS) < self.WIDTH :
			self.GAME_SCREEN_LEFT = (self.WIDTH / 2) - ((self.x_dim* self.SPACE_PIXELS) / 2)
		else :
			self.GAME_SCREEN_LEFT = self.MARGIN

		# Dimensions buttons
		self.BUTTON_WIDTH = math.floor(self.WIDTH/3)

		# Dimensions timer and flag counter
		self.TIMER_WIDTH = 150
		self.FLAG_COUNTER_HEIGHT = 20
		self.FLAG_COUNTER_WIDTH = 150

		# Game Screen (grid)
		self._gameScreen = self._screen.subsurface(
				Rect(self.GAME_SCREEN_LEFT, self.HEADER_BAR + self.MARGIN, self.SPACE_PIXELS*self.x_dim, self.SPACE_PIXELS*self.y_dim)
			)

		# Reset button
		self._reset = self._screen.subsurface(
				Rect(self.MARGIN, self.MARGIN, self.BUTTON_WIDTH, self.HEADER_BAR-self.MARGIN)
			)

		# Timer and flag counter
		self._timer = self._screen.subsurface(
				Rect(self.MARGIN + self.BUTTON_WIDTH + self.MARGIN, self.MARGIN, self.TIMER_WIDTH, self.FLAG_COUNTER_HEIGHT)
			)
		self._flagCounter = self._screen.subsurface(
				Rect(self.MARGIN + self.BUTTON_WIDTH + self.MARGIN, self.MARGIN + self.FLAG_COUNTER_HEIGHT, self.FLAG_COUNTER_WIDTH, self.FLAG_COUNTER_HEIGHT)
			)

		self._screen.fill(Color('light grey'))

        # Cheat Mode button
		self.CHEATMODE_WIDTH = math.floor(self.WIDTH/3)
		self._cheatMode = self._screen.subsurface(
				Rect(self.MARGIN + self.BUTTON_WIDTH + self.MARGIN + self.TIMER_WIDTH + self.MARGIN, self.MARGIN, self.CHEATMODE_WIDTH, self.HEADER_BAR-self.MARGIN)
			)

		display.flip()
예제 #11
0
def paint():
    """update the screen"""
    SURFACE.fill((0, 0, 0))

    for shape in SHAPES:
        polygons = shape.model.work
        for vertices in polygons:
            poly = []
            for vertex in vertices:
                pos_z = vertex[2]
                if pos_z <= 1:
                    continue
                poly.append((vertex[0] / pos_z * 1000 + 300,
                             -vertex[1] / pos_z * 1000 + 300))
            if len(poly) > 1:
                pygame.draw.lines(SURFACE, shape.get_color(), True, poly)

    pos_x, pos_z, theta = CAMERA[0], CAMERA[1], CAMERA_THETA
    RADAR.set_alpha(128)
    RADAR.fill((128, 128, 128))
    pygame.draw.arc(RADAR, (0, 0, 225),
                    Rect(pos_x + 100, -pos_z + 100, 200, 200),
                    theta - 0.6 + pi / 2, theta + 0.6 + pi / 2, 100)
    pygame.draw.rect(RADAR, (225, 0, 0), Rect(pos_x + 200, -pos_z + 200, 5, 5))
    for tank in TANKS:
        pygame.draw.rect(RADAR, (0, 255, 0),
                         Rect(tank.get_x() + 200, -tank.get_z() + 200, 5, 5))

    for shot in SHOTS:
        pygame.draw.rect(RADAR, (225, 225, 225),
                         Rect(shot.get_x() + 200, -shot.get_z() + 200, 5, 5))

    scaled_radar = pygame.transform.scale(RADAR, (300, 300))
    SURFACE.blit(scaled_radar, (650, 50))
    pygame.display.update()
예제 #12
0
    def chamadaImagensDominoCentroMesa(self):

        for i in range(len(Utils.listaPedrasInseridasNaMesa)):
            Utils.img = pygame.image.load(
                Utils.listaPedrasInseridasNaMesa[i]['url'])
            size = Utils.listaPedrasInseridasNaMesa[i]['size']
            pos = Utils.listaPedrasInseridasNaMesa[i]['pos']
            Utils.img = pygame.transform.scale(Utils.img, (size))

            if Utils.listaPedrasInseridasNaMesa[i]["rotate"]["verify"] == True:

                Utils.img = pygame.transform.rotate(
                    Utils.img,
                    Utils.listaPedrasInseridasNaMesa[i]["rotate"]["grau"])

                Utils.listaPedrasInseridasNaMesa[i]["rectLadosPedra"][
                    "rectEsquerda"] = Rect((pos[0], (pos[1] + 2)),
                                           ((size[0] - 6), (size[1] / 2)))

                print "POS = ", pos
                print "SIZE = ", size

                Utils.listaPedrasInseridasNaMesa[i]["rectLadosPedra"][
                    "rectDireita"] = Rect(((pos[0] + 40), pos[1] + 2),
                                          ((size[0] - 7), (size[1] / 2)))

            else:
                Utils.listaPedrasInseridasNaMesa[i]['rect'] = Rect(
                    Utils.listaPedrasInseridasNaMesa[i]['pos'],
                    (Utils.listaPedrasInseridasNaMesa[i]['size']))
            self.screen.blit(Utils.img,
                             Utils.listaPedrasInseridasNaMesa[i]['pos'])
            pygame.display.update()
예제 #13
0
파일: speed0.py 프로젝트: kijimaD/python
def main():
    """メインルーチン"""
    pos_x = 0
    pos_y = 0
    velocity_x = 5
    velocity_y = 6
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        SURFACE.fill((0, 0, 0))
        pos_x += velocity_x
        if pos_x > 600:
            pos_x = 0

        pos_y += velocity_y
        if pos_y > 600:
            pos_y = 0

        pygame.draw.rect(SURFACE, (255, 255, 255), Rect(pos_x, 200, 10, 10))
        pygame.draw.rect(SURFACE, (255, 255, 255), Rect(200, pos_y, 10, 10))

        pygame.display.update()
        FPSCLOCK.tick(10)
예제 #14
0
def 그리기(점수판, 게임종료메세지):
    화면.fill((0, 0, 0))  # 검정색으로 칠하기
    화면.blit(배경, (0, 0))

    # 음식 그리기
    for food in 음식:
        pygame.draw.ellipse(화면, (0, 255, 0),
                            Rect(food[0] * 20, food[1] * 20, 20, 20))

    # 뱀 그리기
    for body in 뱀[::2]:
        pygame.draw.rect(화면, (0, 0, 0), Rect(body[0] * 20, body[1] * 20, 20,
                                             20))
    for body in 뱀[1::2]:
        pygame.draw.rect(화면, (255, 255, 255),
                         Rect(body[0] * 20, body[1] * 20, 20, 20))

    # 점수 그리기
    if 점수판 != None:  # 점수에 내용이 있으면
        화면.blit(점수판, (10, 10))

    # 종료 메세지 그리기
    if 게임종료메세지 != None:
        화면.blit(게임종료메세지, (280, 500))

    pygame.display.update()  # 화면 업데이트
예제 #15
0
def main():
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
        SURFACE.fill((255, 255, 255))

        # Red rectangle(full)
        pygame.draw.rect(SURFACE, (255, 0, 0), (10, 20, 100, 50))

        # Red rectangle(not full)
        pygame.draw.rect(SURFACE, (255, 0, 0), (150, 10, 100, 50), 3)

        # Green rectangle
        pygame.draw.rect(SURFACE, (0, 255, 0), (100, 80, 80, 50))

        # Blue rectangle
        rect0 = Rect(200, 60, 140, 80)
        pygame.draw.rect(SURFACE, (0, 0, 255), rect0)

        # Yellow rectangle
        rect1 = Rect(30, 160, 100, 50)
        pygame.draw.rect(SURFACE, (255, 255, 0), rect1)

        pygame.display.update()
예제 #16
0
def main():
    pygame.init()
    pygame.key.set_repeat(10, 10)
    clock = pygame.time.Clock()
    surface = pygame.display.set_mode((WIDTH, HEIGHT))
    pygame.display.set_caption("Squah game")
    font = pygame.font.Font(None, 80)
    message_over = font.render("Game Over!!", True, (255, 0, 0))
    message_pos = message_over.get_rect()
    message_pos.centerx = surface.get_rect().centerx
    message_pos.centery = surface.get_rect().centery
    ball_num = 3
    racket = Rect(RACKET_SIZE)
    ball = Rect(surface.get_rect().centerx - 10, 0, BALL_SIZE, BALL_SIZE)
    dir = randint(ANGLE, 180 - ANGLE)
    speed = INIT_SPEED
    game_over = False

    while True:
        # キーの判定
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == KEYDOWN:
                if event.key == K_LEFT:
                    racket.centerx -= 10
                elif event.key == K_RIGHT:
                    racket.centerx += 10
                elif event.key == K_UP:
                    racket.centery -= 10
                elif event.key == K_DOWN:
                    racket.centery += 10

        # 判定ボールの移動
        if ball.centery < HEIGHT:
            ball.centerx += cos(radians(dir)) * speed
            ball.centery += sin(radians(dir)) * speed
        else:
            if ball_num > 1:
                ball_num -= 1
                ball.left = surface.get_rect().centerx - 10
                ball.top = 0
                dir = randint(ANGLE, 180 - ANGLE)
            else:
                game_over = True
        if racket.colliderect(ball):
            dir = -(90 + (racket.centerx - ball.centerx) / racket.width * 100)
            print(dir)
        if ball.centerx < 0 or ball.centerx > WIDTH:
            dir = 180 - dir
        dir = -dir if ball.centery < 0 else dir

        surface.fill((255, 255, 255))
        if game_over:
            surface.blit(message_over, (message_pos))
        pygame.draw.rect(surface, RACKET_COLOR, racket)
        pygame.draw.ellipse(surface, BALL_COLOR, ball)
        pygame.display.update()
        clock.tick(30)
예제 #17
0
def main():  # メイン関数

    while True:  # 無限ループ

        for event in pygame.event.get():  # イベントキューからイベントを取得
            if event.type == QUIT:  # 終了イベントの判定
                pygame.quit()  # PyGameの初期化を解除
                sys.exit()  # プログラム終了

        # White surface
        SCREEN.fill((255, 255, 255))
        # Red:rectangle
        pygame.draw.rect(SCREEN, (255, 0, 0), (10, 20, 100, 50))
        # Red:rectangle
        pygame.draw.rect(SCREEN, (255, 0, 0), (150, 10, 100, 30), 3)
        # Green:rectangle
        pygame.draw.rect(SCREEN, (0, 255, 0), ((100, 80), (80, 50)))
        # Blue:rectangle Rect object
        rect0 = Rect(200, 60, 140, 80)
        pygame.draw.rect(SCREEN, (0, 0, 255), rect0)
        # Yellow:rectangle Rect object
        rect1 = Rect((30, 160), (100, 50))
        pygame.draw.rect(SCREEN, (255, 255, 0), rect1)

        pygame.display.update()  # 描画内容を画面に反映
        FPSCLOCK.tick(3)  # 1 秒間に 3 回ループする
def draw_graph():
    '''
    根据处理后的频域信息进行图像绘制
    '''
    # 从左到右让RGB渐变,并尽量不出现RGB(255,255,255)颜色
    setColor = list(color)
    for n in range(0, transformedL.size, GAP):
        if setColor[0] + 5 <= COLOR_BOUND_H:
            setColor[0] += 5
        elif setColor[1] + 5 <= COLOR_BOUND_H:
            setColor[1] += 5
            setColor[0] -= 2
        else:
            setColor[0] -= 5
        # 左耳信息绘制在界面中线上方,右耳信息绘制在界面中线下方
        # 为了美观在矩阵(RECT)上方绘制了一条短线
        heightL = np.nan_to_num(transformedL[n])
        heightR = np.nan_to_num(transformedR[n])
        draw.rect(
            screen, setColor,
            Rect((GAP + n, WINDOW_SIZE[1] / 2 - heightL / 2 - 5),
                 (GAP * 0.8, 1)))
        draw.rect(
            screen, setColor,
            Rect((GAP + n, WINDOW_SIZE[1] / 2), (GAP * 0.8, -heightL / 2)))
        draw.rect(
            screen, setColor,
            Rect((GAP + n, WINDOW_SIZE[1] / 2 + heightR / 2 + 5),
                 (GAP * 0.8, 1)))
        draw.rect(
            screen, setColor,
            Rect((GAP + n, WINDOW_SIZE[1] / 2), (GAP * 0.8, heightR / 2)))
예제 #19
0
 def update_col(self,
                col=0,
                num=3,
                base=16,
                blank=False):  # ある桁にある数字を表示する関数
     # numをcol桁目に表示、桁は最上位桁の左から右へ進む。
     block_size = self.BLOCK_SIZE
     num = num % base  # デフォルトは16進数表示
     for segment in segments:  # 7つのセグメントのうちの、あるセグメントについて、
         if segment[num] == 1:
             color = self.COLOR_ON
         else:
             color = self.COLOR_OFF
         if blank is True:  # ブランク表示の場合は、すべてOFFで上書き
             color = self.COLOR_OFF
         # 桁の原点
         x0 = self.X_ORG + self.COL_INTV * col
         y0 = self.Y_ORG
         # ブロック1、ブロック2の座標オフセット
         x1, y1 = segment[16][0]
         x2, y2 = segment[16][1]
         # ブロック1、ブロック2の原点座標
         org1 = (x0 + x1 * self.BLOCK_INTV, y0 - y1 * self.BLOCK_INTV)
         org2 = (x0 + x2 * self.BLOCK_INTV, y0 - y2 * self.BLOCK_INTV)
         # ブロック1,2を描く
         pygame.draw.rect(self.screen, color,
                          Rect(org1[0], org1[1], block_size, block_size))
         pygame.draw.rect(self.screen, color,
                          Rect(org2[0], org2[1], block_size, block_size))
def 그리기(점수판, 게임종료메시지):  # 그리기 함수 선언
    화면.blit(배경, (0, 0))  # 화면색상 색으로 칠하기

    # 음식 그리기
    for food in 음식:  # 음식 리스트의 개수 만큼 반복하기
        pygame.draw.ellipse(화면, (255, 255, 0),
                            Rect(food[0] * 20, food[1] * 20, 20, 20))
        # 음식 그리기(타원)      색                 가로              세로

    # 뱀 그리기
    for body in 뱀:  # 뱀 리스트의 개수 만큼 반복하기
        pygame.draw.rect(화면, (255, 255, 255),
                         Rect(body[0] * 20, body[1] * 20, 20, 20))
        # 음식 그리기(타원)   색                 가로                  세로

    # 점수 그리기
    if 점수판 != None:  # 점수에 내용이 있으면
        화면.blit(점수판, (10, 10))  # 점수판 위치

    # 종료 메시지 그리기
    if 게임종료:  # 게임종료 메시지가 내용이 있으면
        게임종료메시지 = my글꼴1.render("게임종료 점수 : " + str(점수), True, (255, 255, 255))
        화면.blit(게임종료메시지, (375, 400))
    print(단계)
    pygame.display.update()  # 화면 업데이트
예제 #21
0
def main():
    """main routine"""

    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        SURFACE.fill((255, 255, 255))

        # 빨간색: 직사각형(꽉 채워서 칠한다.)
        pygame.draw.rect(SURFACE, (255, 0, 0), (10, 20, 100, 50))

        # 빨간색: 직사각형(굵기3)
        pygame.draw.rect(SURFACE, (255, 0, 0), (150, 10, 100, 30), 3)

        # 녹색:직사각형
        pygame.draw.rect(SURFACE, (0, 255, 0), ((100, 80), (80, 50)))

        # 파란색:직사각형,Rect객체
        rect0 = Rect(200, 60, 140, 80)
        pygame.draw.rect(SURFACE, (0, 0, 255), rect0)

        # 노란색:직사각형,Rect객체
        rect1 = Rect((30, 160), (100, 50))
        pygame.draw.rect(SURFACE, (255, 255, 0), rect1)

        pygame.display.update()
        FPSCLOCK.tick(3)
예제 #22
0
    def __init__(self, left: int, top: int, game_player, image_height: int=50):
        super().__init__()

        self.game_player = game_player

        surface = game_player.character.face_image
        name = game_player.player.name
        stock = game_player.stock

        # キャラ画像
        image_width = image_height
        rect = Rect(left, top, image_width, image_height)
        image = surface_fit_to_rect(surface, rect)
        self.character_sprite = SimpleSprite(rect, image)
        self.add(self.character_sprite)

        # ストックの丸
        self.stock = stock
        self.stock_sprites = [Group() for i in range(stock)]
        x, y = self.character_sprite.rect.bottomright
        stock_radius = int(0.05 * image_height)
        left, top = x, y - stock_radius * 2
        for i in range(stock):
            surface = Surface((stock_radius * 2, stock_radius * 2)).convert_alpha()
            surface.fill((125, 125, 125))
            surface.set_colorkey(surface.get_at((0, 0)))
            pygame.gfxdraw.filled_circle(surface, stock_radius, stock_radius, stock_radius-1, (255, 255, 255))
            stock_sprite = SimpleSprite(Rect(left, top, stock_radius * 2, stock_radius * 2), surface)
            self.stock_sprites[i].add(stock_sprite)
            print(self.stock_sprites[i])
            left += stock_radius * 2

        # プレイヤーネーム
        font_size = int(0.2 * image_height)
        font = pygame.font.Font(None, font_size)
        left, bottom = self.character_sprite.rect.bottomright
        bottom -= stock_radius * 2
        self.player_name_sprite = TextSprite(
            x=left,
            y=bottom,
            align="left",
            vertical_align="bottom",
            text=name,
            font=font,
            color=(255, 255, 255)
        )
        self.add(self.player_name_sprite)

        # プレイヤーネームのbg
        width = self.character_sprite.rect.w + max(stock_radius * 2 * stock, self.player_name_sprite.rect.w) + 10
        height = self.character_sprite.rect.h
        self.base_rect = Rect(*self.character_sprite.rect.topleft, width, height)
        rect = self.base_rect
        bg_image = Surface(rect.size).convert_alpha()
        bg_image.fill((0, 0, 0))
        bg_image.set_alpha(225)
        bg_sprite = SimpleSprite(rect, bg_image)
        self.bg_group = Group()
        self.bg_group.add(bg_sprite)
예제 #23
0
 def __init__(self, xpos):
     self.rect = Rect(xpos, 550, 40, 40)
     self.exploded = False
     strip = pygame.image.load("strip.png")
     self.images = (pygame.Surface((20, 20), pygame.SRCALPHA),
                    pygame.Surface((20, 20), pygame.SRCALPHA))
     self.images[0].blit(strip, (0, 0), Rect(0, 0, 20, 20))
     self.images[1].blit(strip, (0, 0), Rect(20, 0, 20, 20))
예제 #24
0
def parallax(surf, initial_pos, img, pos_x):
    pos_x %= img.get_width()
    rect1 = Rect((0, 0), (pos_x, img.get_height()))
    temp_img1 = img.subsurface(rect1)
    rect2 = Rect((pos_x, 0), (img.get_width() - pos_x, img.get_height()))
    temp_img2 = img.subsurface(rect2)
    surf.blit(temp_img1, (img.get_width() - pos_x, initial_pos[1]))
    surf.blit(temp_img2, initial_pos)
예제 #25
0
 def __init__(self, rect, offset0, offset1):
     strip = pygame.image.load("./image/strip.png")
     self.images = (pygame.Surface((24, 24), pygame.SRCALPHA),
                    pygame.Surface((24, 24), pygame.SRCALPHA))
     self.rect = rect
     self.count = 0
     self.images[0].blit(strip, (0, 0), Rect(offset0, 0, 24, 24))
     self.images[1].blit(strip, (0, 0), Rect(offset1, 0, 24, 24))
예제 #26
0
    def clear(self, surface, bg):
        # make heavily used symbols local, avoid python performance hit
        split_rects_add = _split_rects_add
        spritelist = self._spritelist
        spritelist_len = len(spritelist)
        changed = self.lostsprites
        changed_append = changed.append

        for sprite in spritelist:
            if not sprite.last_state_changed():
                continue

            state = sprite.last_state
            changed_append(state.rect)

            i = sprite.zindex
            while i < spritelist_len:
                s2 = spritelist[i]
                i += 1

                if s2.dirty or not s2.visible:
                    continue

                r = state.rect.clip(s2.rect)
                if r:
                    r2 = Rect((r.left - s2.rect.left, r.top - s2.rect.top),
                              r.size)
                    s2.damaged_areas.append((r, r2))
                    s2.damaged = True
        # for in spritelist

        changed.sort(_cmp_area)
        split_rects = []
        for r in changed:
            split_rects_add(split_rects, r)

        surface_blit = surface.blit
        dirty = []
        dirty_append = dirty.append
        for r in split_rects:
            r = surface_blit(bg, r, r)
            dirty_append(r)

            for s in spritelist:
                if s.dirty or s.damaged or not s.visible:
                    continue

                state = s.last_state
                r2 = r.clip(state.rect)
                if r2:
                    r3 = Rect(r2.left - s.rect.left, r2.top - s.rect.top,
                              r2.width, r2.height)
                    surface_blit(s.image, r2, r3)
            # for in spritelist
        # for in split_rects

        self.lostsprites = dirty
예제 #27
0
 def _calc_area(self):
     f = self.get_curr_frame()
     s = self.srcCorner
     h = self.h_s
     v = self.v_s
     if self.hor_step <> 0:
         return Rect(s[0] + h * f, s[1], self.size[0], self.size[1])
     else:
         return Rect(s[0], s[1] + v * f, self.size[0], self.size[1])
예제 #28
0
    def __init__(self, width=700, height=800, timeScale=1):

        self.max_frame_rate = 10  #max frame rate in frames-per-second
        self.clock = pygame.time.Clock()

        pygame.init()
        self.screenSize = width, height
        self.w32windowClass = "pygame"  #The win32 window class for this object
        self.screen = clickndrag.Display(
            self.screenSize)  #pygame.display.set_mode(self.screenSize)
        self.windowCaption = "Dredge Tycoon"
        pygame.display.set_caption(self.windowCaption)
        self.white = pygame.Color("white")
        self.screen.image.fill(self.white)
        pygame.display.flip()

        #The game screen
        sea_tile = pygame.image.load(
            os.path.join('graphics', 'sea_tile_32x32.png')).convert()
        self.sea_tiles = [sea_tile] * 250
        self.sea_tiles.append(
            pygame.image.load(os.path.join('graphics',
                                           'whale_tile_32x32.png')).convert())
        self.sea_tiles.append(
            pygame.image.load(
                os.path.join('graphics', 'tugboat_tile_32x32.png')).convert())
        self.sea_tiles.append(
            pygame.image.load(os.path.join('graphics',
                                           'turtle_tile_32x32.png')).convert())
        self.sea_tiles.append(
            pygame.image.load(
                os.path.join('graphics',
                             'swordfish_tile_32x32.png')).convert())
        menu_margin = width  #*.75
        self.game_plane = clickndrag.Plane("game screen",
                                           Rect(0, 0, menu_margin, height))
        self.game_background = tile_texture(self.game_plane.image,
                                            self.sea_tiles)
        self.game_plane.image.blit(self.game_background, (0, 0))
        self.screen.sub(self.game_plane)

        #The main status display - Date and player $$
        self.date_status = clickndrag.gui.Button("Date: 01 Jan 1900",
                                                 Rect(0, 0, 150, 15),
                                                 None)  #callback placeholder
        self.screen.sub(self.date_status)
        self.player_status = clickndrag.gui.Button("Value: 000,000,000",
                                                   Rect(150, 0, 125, 15),
                                                   None)  #callback placeholder
        self.screen.sub(self.player_status)
        self.status_windows = {}

        self.city_bubble = None

        pygame.display.flip()
예제 #29
0
def paint(message):
    SURFACE.fill((0,0,0))
    for food in FOODS:
        pygame.draw.ellipse(SURFACE,(0,255,0),Rect(food[0]*30, food[1]*30, 30,30))
    for body in SNAKE:
        pygame.draw.rect(SURFACE, (0,255,255),Rect(body[0]*30, body[1]*30, 30,30))
    for index in range(20):
        pygame.draw.line(SURFACE, (64,64,64),(index*30,0),(index*30, 600))
        pygame.draw.line(SURFACE,(64,64,64),(0, index*30),(600, index*30))
    if  message != None:
        SURFACE.blit(message, (150,300))
    pygame.display.update()
예제 #30
0
    def update(self, HP, stamina, ammo, equiped, pos):
        self.health = HP
        self.stamina = stamina
        self.ammo = ammo

        if equiped == 'swrd': self.equiped = 0
        else: self.equiped = 1

        # Draw HP Bar
        temp = int((self.health / self.healthTotal) * self.width)
        pygame.draw.rect(
            self.SURF, self.RED,
            Rect(self.healthBarPos[0], self.healthBarPos[1], temp,
                 self.height))
        pygame.draw.rect(
            self.SURF, self.BLACK,
            Rect(self.healthBarPos[0] - self.borderWidth,
                 self.healthBarPos[1] - self.borderWidth,
                 self.width + 2 * self.borderWidth,
                 self.height + 2 * self.borderWidth), 2 * self.borderWidth)

        # Draw Stamina Bar
        temp = int((self.stamina / self.staminaTotal) * self.width)
        pygame.draw.rect(
            self.SURF, self.GREEN,
            Rect(self.staminaBarPos[0], self.staminaBarPos[1], temp,
                 self.height))
        pygame.draw.rect(
            self.SURF, self.BLACK,
            Rect(self.staminaBarPos[0] - self.borderWidth,
                 self.staminaBarPos[1] - self.borderWidth,
                 self.width + 2 * self.borderWidth,
                 self.height + 2 * self.borderWidth), 2 * self.borderWidth)

        # Draw toolbar
        self.tbImgSwitch(self.equiped)
        self.SURF.blit(self.swrdImg[self.swrdHL],
                       (self.tbPos[0], self.tbPos[1]))
        self.SURF.blit(self.blndrImg[self.blndrHL],
                       (self.tbPos2[0], self.tbPos2[1]))
        ammoTxt = self.fontRender(self.ammoFont, 'x ' + str(self.ammo))
        self.SURF.blit(ammoTxt, self.tbTxtPos)

        # Draw MiniMap
        pygame.draw.rect(
            self.SURF, self.BLACK,
            Rect(self.MiniMapX - 10, self.MiniMapY - 10,
                 self.MiniMap.get_size()[0] + 20,
                 self.MiniMap.get_size()[1] + 20))
        temp = self.MiniMap.copy()
        xy = (pos[0] // self.TILESIZE, pos[1] // self.TILESIZE)
        self.__setPixels(temp, xy, size=5)
        self.SURF.blit(temp, (self.MiniMapX, self.MiniMapY))