Пример #1
0
def create_sprite_grid(w: Window, x0, y0, m, n, scale=1, sprite_cls=Sprite):
    grid: List[List[Sprite]] = []
    for i in range(m):
        row = []
        for j in range(n):
            s = w.create_sprite(sprite_cls)
            s.scale = scale
            s.x = x0 + j * (1 + s.width)
            s.y = y0 + i * (1 + s.height)
            row.append(s)
        grid.append(row)
Пример #2
0
def create_level(n, m, scale, x0, y0, w: Window, Csprite=Sprite):
    rows, cols = n, m
    grid = []
    for i in range(rows):
        row = []
        for j in range(cols):
            q = w.create_sprite(Csprite)
            q.scale = scale
            q.x = x0 + j * (2 + q.width)
            q.y = y0 + i * (2 + q.height)
            r = row.append(q)
        grid.append(r)
Пример #3
0
def create_sprite(splited, scale, x0, y0, w: Window, Csprite=Sprite):
    rows, cols = len(splited), len(splited[0])
    grid = []
    for i in range(rows):
        row = []
        for j in range(cols):
            p = w.create_sprite(Csprite)
            p.texture = ni.get_texture_from_array(splited[i][j])
            p.scale = scale
            p.x = x0 + j * (2 + p.width)
            p.y = y0 + i * (2 + p.height)
            r = row.append(p)
        grid.append(r)
Пример #4
0
def create(w: Window,
           sub_array: List[List[ndarray]],
           scale=1,
           sprite_cls=Sprite):
    s, n = len(sub_array), len(sub_array[0])
    grid: List[List[Sprite]] = []
    for i in range(s):
        row = []
        for j in range(n):
            s = w.create_sprite(sprite_cls)
            s.texture = np.get_texture_from_array(sub_array[i][j])
            s.scale = scale
            s.x = s.width / 2 + (j * s.width)
            s.y = s.height / 2 + (i * s.height)
            row.append(s)
        grid.append(row)
Пример #5
0
    def __init__(self,
                 w: Window,
                 rows: int,
                 cols: int,
                 x: float = None,
                 y: float = None,
                 scale: float = 10,
                 cell_gap: float = 1,
                 cell_cls: Callable[..., T] = Sprite):

        self.__x = scale / 2 if x is None else x
        self.__y = scale / 2 if y is None else y
        self.__scale = scale
        self.__cell_gap = cell_gap
        self.__rows = rows
        self.__cols = cols
        self.__cells = [[w.create_sprite(cell_cls) for j in range(cols)]
                        for i in range(rows)]
        self.__update_cells()
Пример #6
0
    "pbpppbp",
    "ppppppp",
    "ppwwwpp",
]

current_color = Color.WHITE

w = Window(width=len(my_list[0])*PIXEL+100, height=len(my_list)*PIXEL)

class Pixel(Sprite):
    def on_create(self):
        self.scale = PIXEL

class ColorChoice(Sprite):
    def on_create(self):
        self.scale = PIXEL
    def on_left_click(self):
        global current_color
        current_color = self.color

for i in range(len(my_list)):
    for j in range(len(my_list[i])):
        p = w.create_sprite(Pixel)
        p.x = j*(p.width+1) + p.width/2
        p.y = w.height - p.height/2 - i*(p.height+1)
        p.color = color[my_list[i][j]]

for k in range(2):
    pass
c = w.create_sprite(ColorChoice)
w.run()
Пример #7
0
            self.rotation = 90
        if window.is_key_down(KeyCode.DOWN):
            self.rotation = 270
        if window.is_key_down(KeyCode.LEFT):
            self.rotation = 180
        if window.is_key_down(KeyCode.RIGHT):
            self.rotation = 0

        if self.x > 1225:
            print("You Win!")
            window.close()

        if self.is_touching_any_sprite():
            print("You Lose!")
            window.close()


s = window.create_sprite()
s.image = "img/beach.png"

s.x = 500
s.y = 550
window.create_sprite(Player)

window.create_sprite(image='img/beach.png', x=500, y=100)
window.create_sprite(image='img/beach.png', x=500, y=230)
window.create_sprite(image='img/beach.png', x=700, y=300)
window.create_sprite(image='img/beach.png', x=600, y=430)

window.run()
Пример #8
0
    "w":"tiles/tile_001.png",
    "b":"tiles/tile_002.png",
}

my_list = [
    "wwwwwww",
    "ppppppp",
    "pbpppbp",
    "ppppppp",
    "ppwwwpp",
]
w = Window(width=len(my_list[0])*PIXEL, height=len(my_list)*PIXEL)
class Pixel(Sprite):

    def on_create(self):
        self.scale = 3

for i in range(len(my_list)):
    for j in range(len(my_list[i])):
        p = w.create_sprite(Pixel)
        
        p.image = color[my_list[i][j]]
        p.scale = 3
        p.x = j*(p.width+1) + p.width/2
        p.y = w.height - p.height/2 - i*(p.height+1)
        # if my_list[i][j] == "p":
        #     p.color = Color.PURPLE
        # if my_list[i][j] == "w":
        #     p.color = Color.WHITE

w.run()
Пример #9
0
    def set_color(self, max, min):
        scale = (self.value - min) / (max - min)
        self.color = Color(255, (1 - scale) * 255, (1 - scale) * 255)


my_list = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]

list_min = list_max = my_list[0][0]
for i in range(3):
    for j in range(4):
        v = my_list[i][j]
        if v < list_min:
            list_min = v
        if v > list_max:
            list_max = v
print(list_min, list_max)

for i in range(3):
    for j in range(4):
        #print(my_list[i][j], end=" ")
        # label_1 = w.create_label()
        # label_1.text = str(my_list[i][j])
        # label_1.x = 100 + j*50
        # label_1.y = w.height - i*50
        cell = w.create_sprite(Cell)
        cell.x = 600 + j * (cell.width + 1)
        cell.y = w.height - 300 - i * (cell.height + 1)
        cell.create_label(my_list[i][j])
        cell.set_color(list_max, list_min)

w.run()
Пример #10
0
            print(b.power)

        if self.is_touching_any_sprite_with_tag("explosion"):
            self.delete()
            window.close()


WORLD_SIZE = 11
LEVEL_OFFSET = CELL_SIZE * 2

for i in range(WORLD_SIZE):
    for j in range(WORLD_SIZE):
        x = LEVEL_OFFSET + j * CELL_SIZE
        y = LEVEL_OFFSET + i * CELL_SIZE
        if i == 0 or j == 0 or i == WORLD_SIZE - 1 or j == WORLD_SIZE - 1:
            wall = window.create_sprite(Wall, x=x, y=y)
        elif i % 2 == 0 and j % 2 == 0:
            wall = window.create_sprite(Wall, x=x, y=y)
        elif i % 2 == 1 or j % 2 == 1:
            grass = window.create_sprite(Grass, x=x, y=y)
            if random() < TREE_PROB:
                tree = window.create_sprite(Tree, x=x, y=y)
                window.create_sprite(PowerUp, x=x, y=y)

p1 = window.create_sprite(Player)
p1.set_keys(KeyCode.UP, KeyCode.DOWN, KeyCode.LEFT, KeyCode.RIGHT,
            KeyCode.SPACE)
p2 = window.create_sprite(Player)
p2.set_keys(KeyCode.W, KeyCode.S, KeyCode.A, KeyCode.D, KeyCode.ENTER)
p2.x += (WORLD_SIZE - 3) * CELL_SIZE
p2.y += (WORLD_SIZE - 3) * CELL_SIZE
Пример #11
0
my_list = [[1, 2, 3, 4], [-1, 2, 3, 4], [-1, -2, 3, 4], [-1, -2, -3, 4],
           [-1, -2, -3, -4]]

list_min = list_max = my_list[0][0]
for i in range(4):
    for j in range(4):
        val = my_list[i][j]
        if val < list_min:
            list_min = val
        if val > list_max:
            list_max = val

print(list_max, list_min)

for i in range(4):
    for j in range(4):
        # print(my_list[i][j], end = " ")
        # print( )
        # label_ij = window.create_label()
        # label_ij.text = str(my_list[i][j])
        # label_ij.x = 400 + j*100
        # label_ij.y = window.height - i*60
        cell = window.create_sprite(Cell)
        cell.x = 500 + j * (cell.width + 1)
        cell.y = 100 + i * (cell.height + 1)
        cell.create_label(my_list[i][j])
        cell.set_color(list_min, list_max)

window.run()
Пример #12
0
    box.x = x
    box.y = y


def make_target(x, y):
    target = w.create_sprite(Target)
    target.x = x
    target.y = y


# make_wall(100, 300, 20)
# make_wall(100, 500, 20)
# make_box(600, 400)
# make_box(400, 400)
# make_target(100, 400)
# make_target(800, 400)
x0 = 100
y0 = 500

for i in range(rows):
    for j in range(cols):
        if level[i][j] == "w":
            make_wall(x0 + j * CELL_SIZE, y0 - i * CELL_SIZE, 1)
        elif level[i][j] == "b":
            make_box(x0 + j * CELL_SIZE, y0 - i * CELL_SIZE)
        elif level[i][j] == "r":
            make_target(x0 + j * CELL_SIZE, y0 - i * CELL_SIZE)
        elif level[i][j] == "p":
            player = w.create_sprite(Player)

w.run()
Пример #13
0
        else:
            self.move_time = 0.5

    def check_ground(self):
        if self.y < GROUND_Y:
            self.lock()
            self.y = GROUND_Y
            return True
        else:
            return False

    def check_cell(self):
        cells: List[Cell] = self.get_touching_sprites_with_tag("cell")
        if cells:
            self.y = cells[0].y + self.height + GAP
            self.lock()
            

    def on_update(self, dt):
        if self.state is Cell.State.FALL:
            self.down()
            self.time += dt
            if self.time > self.move_time:
                self.y -= self.y_speed
                self.time = 0
            
            
            

w.create_sprite(Game)
w.run()
Пример #14
0
from pycat.core import Window, Sprite, Color
from random import randint

window = Window()
s = window.create_sprite()


class Bat(Sprite):
    def on_create(self):
        s.image = "bat-b.png"
        self.goto_random_position()

s1 = window.create_sprite(Bat)
s2 = window.create_sprite(Bat)
s3 = window.create_sprite(Bat)
for i in range(200):
    s = window.create_sprite(Bat)
    s.opacity = 200
    s.color = Color.random_rgb()
    s.rotation = randint(0,360)
    s.width = randint(0,10)
    s.height = randint(5,10)




window.run()
Пример #15
0
           height= len(list0)*PIXEL_SIZE)

ncolor = Color.WHITE

class PixelR(Sprite):

    def on_create(self):
        self.scale = PIXEL_SIZE
        

x0 = PIXEL_SIZE/2
y0 = w.height - PIXEL_SIZE/2

for i in range (len(list0)):
    for j in range (len(list0[0])):
        p = w.create_sprite(PixelR)
        p.x = x0 + PIXEL_SIZE *j
        p.y = y0 - PIXEL_SIZE * i
        p.color = color0[list0[i][j]]
        

class Ccolor(Sprite):

    def on_create(self):
        self.scale = PIXEL_SIZE


for i in range (len(ccolor)):
    c:Ccolor = w.create_sprite(Ccolor)
    c.x = w.width - c.width/2
    c.y = w.height -c.width/2 - i*c.height
Пример #16
0
from pycat.core import Window
from pycat.base import NumpyImage as Image

window = Window()
image_rgb = Image(255, 255, 3)
for i in range(image_rgb.rows):
    for j in range(image_rgb.cols):
        if j < 85:
            image_rgb[i][j] = [255, 0, 0]
        elif j < 170:
            image_rgb[i][j] = [0, 255, 0]
        else:
            image_rgb[i][j] = [0, 0, 255]

sprite = window.create_sprite()
sprite.texture = image_rgb.texture
sprite.position = window.center
sprite.x -= sprite.width / 2

image_rgba = Image(255, 255, 4)
for i in range(image_rgba.rows):
    for j in range(image_rgba.cols):
        if j < 85:
            image_rgba[i][j] = [255, 0, 0, i]
        elif j < 170:
            image_rgba[i][j] = [0, 255, 0, i]
        else:
            image_rgba[i][j] = [0, 0, 255, i]

sprite = window.create_sprite()
sprite.texture = image_rgba.texture
Пример #17
0
from pycat.core import Window
from pycat.base import NumpyImage

w = Window()
original_image = NumpyImage.get_array_from_file("view.PNG")
print(original_image.shape)

sub = original_image[:386, :567, :]
sub2 = original_image[386:, 567:, :]
# sub3 = original_image[386:, :567, :]
# sub4 = original_image[:386, 567:, :]

s = w.create_sprite(x=250, y=200)
s.texture = NumpyImage.get_texture_from_array(sub)
s2 = w.create_sprite(x=900, y=400)
s2.texture = NumpyImage.get_texture_from_array(sub2)
w.run()
Пример #18
0
        print('export')
        pickle.dump(level_grid.data, open('level_data', 'wb'))


class ImportButton(Sprite):
    def on_create(self):
        self.width = 100
        self.height = 50
        self.color = Color.GREEN
        self.x = 100
        self.y = 400
        label = w.create_label(text='Import')
        label.x = self.x - label.content_width / 2
        label.y = self.y + label.content_height / 2

    def on_left_click(self):
        global level_grid
        w.delete_sprites_with_tag("Level Cell")
        print("import")
        level_grid = SpriteGrid.create_from_data_file('level_data',
                                                      scale=15,
                                                      x=600,
                                                      cell_gap=1,
                                                      cell_cls=LevelCell)


w.create_sprite(ExportButton)
w.create_sprite(ImportButton)
w.create_sprite(GridController)
w.run()
Пример #19
0
from pycat.base import NumpyImage as Image

w = Window()
image01 = Image.get_array_from_file("4_0.jpg")
image02 = Image.get_array_from_file("10_0.jpg")
image03 = Image.get_array_from_file("11_0.jpg")
image04 = Image.get_array_from_file("16_0.jpg")
image06 = Image.get_array_from_file("22_0.jpg")

rows1, cols1, channels1 = image01.shape
rows2, cols2, channels2 = image02.shape
rows3, cols3, channels3 = image03.shape
rows4, cols4, channels4 = image04.shape
rows6, cols6, channels6 = image06.shape

isprite1 = w.create_sprite()
isprite1.scale = 1.6
isprite1.texture = Image.get_texture_from_array(image01)
isprite1.position = (430, 460)

isprite2 = w.create_sprite()
isprite2.scale = 1.6
isprite2.texture = Image.get_texture_from_array(image02)
isprite2.position = (860, 460)

isprite3 = w.create_sprite()
isprite3.scale = 1.6
isprite3.texture = Image.get_texture_from_array(image03)
isprite3.position = (360, 290)

isprite4 = w.create_sprite()
Пример #20
0
from pycat.core import Window, Sprite
w = Window()
s = w.create_sprite(scale=200, position=w.center)
w.run()
Пример #21
0
from pycat.core import Window, Sprite
from pycat.base import NumpyImage

window = Window()


class ImageSprite(Sprite):
    def on_create(self):
        self.image = "baboon.jpeg"
        self.scale = 2
        self.y = window.height / 2


input_sprite = window.create_sprite(ImageSprite)
input_sprite.x = (window.width - input_sprite.width) / 2
output_sprite = window.create_sprite(ImageSprite)
output_sprite.x = (window.width + output_sprite.width) / 2

image = NumpyImage.get_array_from_texture(input_sprite.texture)
rows, cols, channels = image.shape

img = NumpyImage(rows, cols)
for i in range(rows):
    for j in range(cols):
        intensity = (j * 255) // (cols - 1)
        img[i, j] = intensity

# for i in range(rows):
#     for j in range(cols):
#         channel_sum = 0
#         # print(image[i][j])
Пример #22
0
from turtle import position, window_height, window_width
from pycat.base import NumpyImage
from pycat.core import Window

w = Window(width=600, height=400)

oimage = NumpyImage.get_array_from_file("hummmm.png")
print(oimage.shape)

image01 = NumpyImage.get_texture_from_array(oimage[:84, :150:])
image02 = NumpyImage.get_texture_from_array(oimage[:84, 150::])
image03 = NumpyImage.get_texture_from_array(oimage[84:, :150:])
image04 = NumpyImage.get_texture_from_array(oimage[84:, 150::])

x0y0 = w.create_sprite(x=225, y=158)
x1y0 = w.create_sprite(x=375, y=158)
x0y1 = w.create_sprite(x=225, y=242)
x1y1 = w.create_sprite(x=375, y=242)

x0y0.texture = image01
x1y0.texture = image02
x0y1.texture = image03
x1y1.texture = image04

w.run()
Пример #23
0
    'Hedgehog',
    'Meerkat',
]

imnum = 0
text0 = Label('', 400, 50)
w.add_label(text0)
w.background_image = ima[imnum]
text0.text = texts[imnum]


class NButton(Sprite):
    def on_create(self):
        self.image = "button_next.png"
        self.x = 900
        self.y = 60
        self.scale = 0.5

    def on_left_click(self):
        global imnum
        imnum += 1
        if imnum >= len(ima):
            w.close()
            return
        w.background_image = ima[imnum]
        text0.text = texts[imnum]


button = w.create_sprite(NButton)

w.run()
Пример #24
0
        self.opacity *= 0.95
        self.move_forward(3)
        if self.touching_window_edge() or self.time > 2:
            self.delete()


class CreateButton(Sprite):
    def on_left_click(self):
        for _ in range(10):
            window.create_sprite(Particle)


class ExplodeButton(Sprite):
    def on_left_click(self):

        for p in window.get_sprites_with_tag('particle'):
            for r in range(0, 360, 30):
                q = window.create_sprite(ExplosionParticle)
                q.position = p.position
                q.rotation = r
            p.delete()


window = Window()

bb = window.create_sprite(CreateButton, x=100, y=100, scale=75)
bb.color = [0, 0, 255]
rb = window.create_sprite(ExplodeButton, x=100, y=200, scale=75)
rb.color = [255, 0, 0]

window.run()
Пример #25
0
        y1 = self.y
        self.move_forward(rest)
        w.create_line(x1,y1,self.x,self.y)

    def draw_rect(self,width,height):
        self.draw_forward(width)
        self.rotation += 90
        self.draw_forward(height)  
        self.rotation += 90
        self.draw_forward(width)
        self.rotation += 90
        self.draw_forward(height)
        self.rotation += 90

    
t = w.create_sprite(Tur)
# for i in range (360):
#     t.draw_rect(200,200)
#     t.rotation += 1 

class Building:


    def __init__(self,x,y,w,h):
        self.x = x
        self.y = y
        self.width  = w
        self.height = h
    
    def draw (self,t:Tur):
        t.rotation = 0

max_rgb_image = get_max_rgb_image()
luminance_image = get_luminance_image()
complement_image = get_complement_image()
ohman_image = what_the()
# Extensions: add functions to extract the R G B functions


class ImageTest(Sprite):

    def on_create(self):
        self.texture = Image.get_texture_from_array(original_image)
        self.scale = 2
        self.position = w.center

    def on_update(self, dt):
        if w.get_key_down(KeyCode.UP):
            self.texture = Image.get_texture_from_array(original_image)
        if w.get_key_down(KeyCode.DOWN):
            self.texture = max_rgb_image.texture
        if w.get_key_down(KeyCode.LEFT):
            self.texture = luminance_image.texture
        if w.get_key_down(KeyCode.RIGHT):
            self.texture = complement_image.texture
        if w.get_key_down(KeyCode.Z):
            self.texture = ohman_image.texture

w.create_sprite(ImageTest)
w.run()
Пример #27
0
        self.image = "button3-a.png"
        self.scale = 0.75
        self.add_tag("platform")

    def add_hitbox(self):
        self.hitbox = window.create_sprite()
        self.hitbox.position = self.position
        self.hitbox.y += 35
        self.hitbox.width = self.width * 0.65
        self.hitbox.height = 5
        self.hitbox.color = Color.RED
        self.hitbox.opacity = 0


platforms = [
    window.create_sprite(Platform, x=600, y=100),
    window.create_sprite(Platform, x=800, y=300),
    window.create_sprite(Platform, x=300, y=200)
]

for p in platforms:
    p.add_hitbox()

window.create_sprite(Player)


class Enemy(Sprite):
    def on_create(self):
        self.image = "dinosaur4-c.png"
        self.x = 1000
        self.y = 300
Пример #28
0
from pycat.core import Window
window = Window()
animal = window.create_sprite()
anwser = input("What animal do you like?")
animal.x = 620
animal.y = 320

if anwser == "pico":
    animal.image = "pico-c.png"

if anwser == "squirrel":

    animal.image = "squirrel.png"

if anwser == "starfish":
    animal.image = "starfish.png"

if anwser == "cat":
    animal.image = "Cat.png"
anwser0 = input("Do you want your animal big or small?")

if anwser0 == "big":
    animal.scale = 10

if anwser0 == "small":
    animal.scale = 0.5

window.run()
Пример #29
0
    def on_update(self, dt):
        if window.get_key(KeyCode.W):
            self.y += self.speed
        if window.get_key(KeyCode.A):
            self.x -= self.speed
        if window.get_key(KeyCode.S):
            self.y -= self.speed
        if window.get_key(KeyCode.D):
            self.x += self.speed

    def on_left_click_anywhere(self):
        window.create_sprite(Bullet)


player = window.create_sprite(Player)


class Bullet(Sprite):
    def on_create(self):
        self.color = Color.BLUE
        self.scale = 15
        self.speed = 15
        self.position = player.position
        self.add_tag("Bullet")

    def on_update(self, dt):
        self.move_forward(self.speed)
        if self.touching_window_edge():
            self.delete()
Пример #30
0
from pycat.core import Window, Sprite

CELL_SIZE = 48

window = Window(height=700, width=700, is_sharp_pixel_scaling=True)


class Wall(Sprite):
    def on_create(self):
        self.scale = 3
        self.image = 'terrain/wall_1.png'
        self.add_tag('wall')


WORLD_SIZE = 11
LEVEL_OFFSET = CELL_SIZE * 2

for i in range(WORLD_SIZE):
    for j in range(WORLD_SIZE):
        if i == 0 or j == 0 or i == WORLD_SIZE - 1 or j == WORLD_SIZE - 1:
            wall = window.create_sprite(Wall)
            wall.x = LEVEL_OFFSET + j * CELL_SIZE
            wall.y = LEVEL_OFFSET + i * CELL_SIZE

window.run()