Beispiel #1
0
pygame.display.set_caption("Test")
screen = pygame.display.set_mode(SCREEN_SIZE)
#screen = pygame.display.set_mode(SCREEN_SIZE, flags=pygame.FULLSCREEN)

clock = pygame.time.Clock()

level1_map = []
with open("assets/5.csv") as f:
    reader = csv.reader(f, delimiter=',', quotechar='"')
    for row in reader:
        ints_row = [int(i) for i in row]
        level1_map.append(ints_row)

spritesheet = Spritesheet(
    "assets/tileset3b.png",
    tile_width=24, tile_height=24,
    colorkey=pygame.Color(255, 0, 255)
)

start_x = (screen.get_width() - len(level1_map[0]) * 24) // 2
start_y = (screen.get_height() - len(level1_map) * 24) // 2

class Hero:
    def __init__(self, x, y, width, height):
        self.position = pygame.Vector2(x, y)
        self.velocity = pygame.Vector2(0, 0)
        self.acceleration = pygame.Vector2(0, 0)
        self.acceleration_const = pygame.Vector2(0.2, 0.2)

        self.width = width
        self.height = height
Beispiel #2
0
    text_surface = font.render(text, True, color)
    text_rect = text_surface.get_rect()
    text_rect.topleft = (x, y)
    screen.blit(text_surface, text_rect)


level1_map = []
with open('../assets/5.csv') as f:
    reader = csv.reader(f)
    for i in reader:
        level1_map.append([int(j) for j in i])

clock = pygame.time.Clock()

ss = Spritesheet('../assets/tileset3b.png',
                 24,
                 24,
                 colorkey=pygame.Color(255, 0, 255))

tile_id_to_image = {}

indexes = set()
for i in level1_map:
    indexes = indexes.union(set(i))
print(indexes)
for i in indexes:
    if i not in tile_id_to_image:
        row = i // 20
        col = i % 20
        tile_id_to_image[i] = ss.image_at(tile_col=col, tile_row=row)

is_running = True
Beispiel #3
0
import pygame as pygame

from tiled.spritesheet import Spritesheet

SCREEN_SIZE = WIDTH, HEIGHT = 800, 600

pygame.init()
pygame.display.set_caption("Test")
screen = pygame.display.set_mode(SCREEN_SIZE)

clock = pygame.time.Clock()

sprite_sheet = Spritesheet('../assets/tileset3b.png',
                           24,
                           24,
                           colorkey=(255, 0, 255))
# col,row = 2,3
# col, row = 5,5
# col, row = 7,5

is_running = True
while is_running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            is_running = False

    screen.fill((0, 0, 0))
    sprite_sheet.blit_tile(screen, 2, 3, 0, 0)
    sprite_sheet.blit_tile(screen, 5, 5, 100, 100)
    sprite_sheet.blit_tile(screen, 7, 5, 50, 50)
Beispiel #4
0
DARK_GREEN_COLOR = pygame.Color('forestgreen')
GREEN_COLOR = pygame.Color('green')
RED_COLOR = pygame.Color('red')

color_key = (255, 0, 255)

SCREEN_SIZE = WIDTH, HEIGHT = 800, 600

pygame.init()
pygame.display.set_caption("Test")
screen = pygame.display.set_mode(SCREEN_SIZE)

clock = pygame.time.Clock()

spritesheet = Spritesheet("assets/tileset3b.png",
                          tile_width=24,
                          tile_height=24,
                          colorkey=pygame.Color(255, 0, 255))

is_running = True
while is_running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            is_running = False

    screen.fill((0, 0, 255))

    spritesheet.blit_tile(screen, tile_col=8, tile_row=11, x=0, y=0)
    spritesheet.blit_tile(screen, tile_col=9, tile_row=11, x=100, y=0)
    spritesheet.blit_tile(screen, tile_col=10, tile_row=11, x=200, y=0)

    pygame.display.flip()
Beispiel #5
0
import pygame as pygame

from tiled.spritesheet import Spritesheet

SCREEN_SIZE = WIDTH, HEIGHT = 800, 600

pygame.init()
pygame.display.set_caption("Test")
screen = pygame.display.set_mode(SCREEN_SIZE)

clock = pygame.time.Clock()

ss = Spritesheet(
    "../assets/tileset3b.png",
    24,
    24,
    pygame.Color(255, 0, 255)
)

print([ss])

is_running = True
while is_running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            is_running = False

    screen.fill((0, 0, 255))
    for i in range(0, 34):
        img = ss[9 + i % 6, 2]
        screen.blit(img, (i * 24, 0))
Beispiel #6
0
              ],
              [
                  261, -1, -1, 152, 220, 220, 220, 220, 220, -1, -1, -1, -1,
                  -1, 220, 220, 220, 220, 220, 152
              ],
              [
                  261, -1, -1, 152, -1, -1, -1, -1, -1, -1, -1, 156, -1, -1,
                  -1, -1, -1, -1, -1, 152
              ],
              [
                  220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
                  220, 220, 220, 220, 220, 220, 220, 220
              ]]

spritesheet = Spritesheet("assets/tileset3b.png",
                          tile_width=24,
                          tile_height=24,
                          colorkey=pygame.Color(255, 0, 255))


class Hero:
    def __init__(self, x, y, width, height):
        self.x = x
        self.y = y

        self.width = width
        self.height = height

    def draw(self):
        pygame.draw.rect(screen, GREEN_COLOR,
                         (self.x, self.y, self.width, self.height))