Exemplo n.º 1
0
def scene_to_str(GAME_BASE_DIR, renpy, node, res):
    next = real_next(renpy, node.next)
    name = node.imspec[0][0]
    load_image(GAME_BASE_DIR, renpy, res, name, node.imspec)
    res['nodes'][id(node)] = {
        'class_name': 'Scene',
        'arguments': [name, [str(id(next))] if next else []]
    }
    return [next]
Exemplo n.º 2
0
    def __init__(self, canvas, destroy_cb=None):
        self.__images = [
            images.load_image("hero2.png"),
            images.load_image("hero1.png"),
            images.load_image("hero_blowup_n1.png"),
            images.load_image("hero_blowup_n2.png"),
            images.load_image("hero_blowup_n3.png"),
            images.load_image("hero_blowup_n4.png"),
            images.load_image("hero_blowup_n5.png"),
            images.load_image("hero_blowup_n8.png"),
            images.load_image("hero_blowup_n9.png")
        ]
        self.__status = self.NORMAL  # 設置飛行狀態為正常飛行
        self.__canvas = canvas
        self.__destroy_cb = destroy_cb
        self.firetwo = 0
        image = self.__images[0]
        # self.old_image = self.new_image = self.__images[0]  # 設置當前顯示圖片

        # 畫布尺寸
        canvas_width = canvas.width()
        canvas_height = canvas.height()

        # 計算飛機能夠飛行的的上下左右邊緣
        self.__left_side = image.width() / 2  # 左邊緣
        self.__right_side = canvas_width - image.width() / 2  # 右邊緣
        self.__top_side = image.height() / 2  # 上邊緣
        self.__bottom_side = canvas_height - image.height() / 2  # 下邊緣

        # 把飛機的初始放在圖片的底部 (x坐標,y軸坐標)
        x = int(canvas_width / 2)
        y = int(canvas_height - image.height() / 2)
        pos = (x, y)
        size = (image.width(), image.height())
        super().__init__(position=pos, size=size)

        # 此集合用於存放用戶操作的按鍵或鼠標事件
        self.__key_evens = set()

        # 設置飛機的初始圖片
        self.__image_id = canvas.create_image(pos, image=image)

        # 正常飛行時採用正常飛行圖片管理器
        self.__image_manager = HeroPlaneImageManager(canvas, self.__image_id,
                                                     self.__images[:2], pos)
        # 鼠標的按下狀態
        self.__mouse_down = False

        # -----子彈相關----

        self.__bullet_list = TimerList()
        self.__bullet_interval = 7  # 每秒鐘2.8 發子彈(40X7=350毫秒 1 發子彈)
        self.__bullet_count = 0  # 子彈計數
Exemplo n.º 3
0
def load():
	check = 0
	check += images.load_image()
	if check > 0:
		print("Error:" + str(check))
		exit(check)
	return conf()
Exemplo n.º 4
0
    def move(self):
        if self.index + 1 == len(self.path):
            return

        last_time = self.clock.tick() / 1000
        self.time_buffer += last_time
        direction = [self.path[self.index + 1][0] - self.path[self.index][0],
                     self.path[self.index + 1][1] - self.path[self.index][1]]
        for i in range(2):
            if direction[i]:
                direction[i] //= abs(direction[i])
        self.rect.x += direction[0] * round(self.time_buffer // self.speed)
        self.rect.y += direction[1] * round(self.time_buffer // self.speed)
        self.time_buffer %= self.speed
        self.time += last_time

        zombie_cell = (self.rect.x // board.cell_size, self.rect.y // board.cell_size)
        zombie_cell_x, zombie_cell_y = zombie_cell
        grass_to_draw = pygame.sprite.Group()
        for direct in self.directions1:
            x, y = zombie_cell_x + direct[0], zombie_cell_y + direct[1]
            if check(x, y) and start_field[y][x] == 0:
                Grass(x * board.cell_size, y * board.cell_size, grass_to_draw)
        grass_to_draw.draw(screen)

        b = int(self.time % (self.sprite_speed * (2 / self.sprite_speed)) // 0.5)
        direction_tuple = (direction[0], direction[1])
        a = self.directions[direction_tuple]
        self.image = load_image("zombie_" + a + "_" + str(b) + ".png", -1)
        zombies.draw(screen)

        if [zombie_cell_x, zombie_cell_y] == self.path[self.index + 1]:
            self.index += 1
Exemplo n.º 5
0
def show_to_str(GAME_BASE_DIR, renpy, node, res):
    next = real_next(renpy, node.next)
    name = node.imspec[0][0]
    is_Movie = load_image(GAME_BASE_DIR, renpy, res, name, node.imspec)
    res['nodes'][id(node)] = {
        'class_name': 'ShowVideo' if is_Movie else 'Show',
        'arguments': [name, [str(id(next))] if next else []]
    }
    return [next]
Exemplo n.º 6
0
 def __init__(self, x, y, powerup_kind= None):
 	# Define the properties of a pwerup object
   self.type_img = images.load_image('powerup.png')
   self.sprite = pygame.transform.scale(self.type_img, (images.TILE_SIZE, images.TILE_SIZE))
   self.x_pos = x
   self.y_pos = y
   self.timer = 0
   self.powerup_timer = 20
   GameVisibleObject.__init__(self, x, y, self.sprite)
Exemplo n.º 7
0
 def __init__(self, name, coord, group):
     super().__init__(group)
     self.x, self.y = coord
     self.clock = pygame.time.Clock()
     self.time = 0
     self.image = load_image("bed.jpg")
     self.name = name
     self.rect = self.image.get_rect()
     self.rect.x, self.rect.y = coord[0], coord[1]
Exemplo n.º 8
0
 def __init__(self, canvas, callback=None):
     self.__image_pause = images.load_image("game_pause_nor.png")
     self.__canvas = canvas
     self.__click_cb = callback
     self.__size = (self.__image_pause.width(), self.__image_pause.height()
                    )  # 寬和高(元組)
     self.__pos = (self.__image_pause.width() * .75,
                   self.__image_pause.height() * .75)
     self.__images_id = self.__canvas.create_image(self.__pos,
                                                   image=self.__image_pause)
Exemplo n.º 9
0
 def __init__(self, canvas, resume_cb=None, destroy_cb=None):
     # 設置顯示狀態
     self.__image = images.load_image("pause.gif")
     self.__canvas = canvas
     self.__image_id = self.__canvas.create_image(canvas.width() / 2,
                                                  canvas.height() / 2,
                                                  image=self.__image)
     self.__resume_cb = resume_cb
     self.__destroy_cb = destroy_cb
     self.__destroy_count = 75
Exemplo n.º 10
0
 def __init__(self, canvas, speed=1):
     self.__image = images.load_image("background.png")
     self.__canvas = canvas
     self.__speed = speed
     self.__image_height = image_height = self.__image.height()
     self.__images_pos = [[0, 0], [0, -image_height]]
     self.__images_id = [
         self.__canvas.create_image(*pos, image=self.__image, anchor="nw")
         for pos in self.__images_pos
     ]
Exemplo n.º 11
0
 def __init__(self, canvas, destroy_cb=None):
     self.__images = [
     images.load_image('enemy1.png'),
     images.load_image('enemy1_down1.png'),
     images.load_image('enemy1_down2.png'),
     images.load_image('enemy1_down3.png'),
     images.load_image('enemy1_down4.png'),
     images.load_image('enemy1_down5.png'),
     images.load_image('enemy1_down8.png'),
     images.load_image('enemy1_down9.png')
 ]
     super().__init__(canvas,
                      image=self.__images[0], destroy_images=self.__images[1:], destroy_cb=destroy_cb, speed=(0,5))
Exemplo n.º 12
0
 def __init__(self, canvas, position, destroy_cb=None):
     self.__images = [images.load_image("bullet.png")]
     self.__canvas = canvas
     self.image = self.__images[0]
     # 先算寬和高
     self.size = (self.image.width(), self.image.height())
     self.__image_id = canvas.create_image(position, image=self.image)
     self.__destroy_cb = destroy_cb
     super().__init__(position=position, size=self.size, speed=(0, -20))
     # 圖片管理器
     self.__image_manager = FlyingImageManager(canvas, self.__image_id,
                                               position)
Exemplo n.º 13
0
 def __init__(self, coord, group):  # move = [y, x]
     super().__init__(group)
     self.clock = pygame.time.Clock()
     self.time = 0
     self.index = -1
     self.path = []
     self.time_buffer = 0
     self.speed = 0.01
     self.sprite_speed = 0.1
     self.directions = {(0, 1): 'down', (0, -1): 'up', (1, 0): 'right', (-1, 0): 'left'}
     self.image = load_image("zombie_down_0.png", -1)
     self.rect = self.image.get_rect()
     self.rect.x, self.rect.y = coord[0], coord[1]
     self.directions1 = [[0, 0], [0, 1], [0, -1], [1, 0], [-1, 0]]
Exemplo n.º 14
0
    def game_over(self):
        self.stop_timer()
        self.__event_list.clear()
        self.__timer_list.clear()
        self.__enemy_list.clear()
        self.__enemy_listhp.clear()
        self.__enemy_listtwo.clear()
        self.__image = images.load_image("gameover.gif")
        self.__images_id = self.__canvas.create_image(
            self.__canvas.width() / 2,
            self.__canvas.height() / 2,
            image=self.__image)

        print("遊戲結束")
Exemplo n.º 15
0
 def __init__(self, canvas, destroy_cb=None):
     self.__images = [
         images.load_image('enemy3_n1.png'),
         images.load_image('enemy3_down1.png'),
         images.load_image('enemy3_down2.png'),
         images.load_image('enemy3_down3.png'),
         images.load_image("hero_blowup_n4.png"),
         images.load_image("hero_blowup_n5.png"),
         images.load_image("hero_blowup_n8.png"),
         images.load_image("hero_blowup_n9.png")
     ]
     super().__init__(canvas,
                      image=self.__images[0],
                      destroy_images=self.__images[1:],
                      destroy_cb=destroy_cb,
                      speed=(0, 10))
Exemplo n.º 16
0
def cut_charaset(ruta, fil, col):
	'''
	Corta un chara en las fil y col indicadas. Array Bidimensional.
	'''
	image = load_image(ruta, True)
	w = image.get_rect().w / col
	h = image.get_rect().h / fil
	sprite = []
	for f in xrange(0, fil * h, h):
		subspr = []
		for c in xrange(0, col * w, w):
			subspr.append(image.subsurface((c, f, w, h)))
		sprite.append(subspr)
	return sprite
Exemplo n.º 17
0
    def __init__(self, canvas, count=0):
        self.__image = images.load_image("plane_count.gif")
        self.__canvas = canvas
        image = self.__image
        self.__pos = position = (image.width() * 0.75,
                                 canvas.height() - image.height() * 0.75)
        self.__images_id = self.__canvas.create_image(position,
                                                      image=self.__image)
        self.__size = size = (image.width(), image.height())  # 寬和高(元組)

        self.count = count
        self.__font_id = canvas.create_text(position[0],
                                            position[1] + 20,
                                            text=self.__get_str(self.count),
                                            font=("標楷體", 18),
                                            fill='#FF0000')
Exemplo n.º 18
0
def cut_charaset(ruta, fil, col):
    image = load_image(ruta, True)
    rect = image.get_rect()
    w = rect.w / col
    h = rect.h / fil
    sprite = range(fil)
    for i in range(fil):
        sprite[i] = range(col)

    for f in range(fil):
        for c in range(col):
            sprite[f][c] = image.subsurface((rect.left, rect.top, w, h))
            rect.left += w
        rect.top += h
        rect.left = 0

    return sprite
Exemplo n.º 19
0
def cut_charaset(ruta, fil, col):
	image = load_image(ruta, True)
	rect = image.get_rect()
	w = rect.w / col
	h = rect.h / fil
	sprite = range(fil)
	for i in range(fil):
		sprite[i] = range(col)

	for f in range(fil):
		for c in range(col):
			sprite[f][c] = image.subsurface((rect.left, rect.top, w, h))
			rect.left += w
		rect.top += h
		rect.left = 0

	return sprite
Exemplo n.º 20
0
    def __init__(self, canvas, start_callback=None, destroy=None):
        self.__images = [images.load_image("start2.gif")]
        self.__status = self.NORMAL  # 設置顯示狀態
        self.__canvas = canvas
        self.__start_fn = start_callback
        self.__destroy_cb = destroy
        # 畫布尺寸
        self.__pos = [
            self.__canvas.width() / 2,
            self.__canvas.height() / 2 + 3
        ]

        # 設置飛機的初始圖片
        self.__image_id = canvas.create_image(self.__pos,
                                              image=self.__images[0])
        self.__start_id = canvas.create_image(self.__pos[0],
                                              self.__pos[1] + 20,
                                              image=self.__images[0])
Exemplo n.º 21
0
def game_over(screen):
    background = pygame.transform.scale(load_image('gameOver.png'),
                                        (WIDTH, HEIGHT))
    screen.blit(background, (0, 0))

    clock = pygame.time.Clock()

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    return False
                return True
            if event.type == pygame.MOUSEBUTTONDOWN:
                return True
        pygame.display.flip()
        clock.tick(50)
Exemplo n.º 22
0
 def __init__(self):
     self.image = load_image("arrow1.png", -1)
Exemplo n.º 23
0
args = vars(ap.parse_args())

CONTENT_PATH = "data/content/"
STYLE_PATH = "data/styles/"

CONTENT_IMAGE_PATH = CONTENT_PATH + args["content_image"]
STYLE_IMAGE_PATH = STYLE_PATH + args["style_image"]

MODEL_PATH = args["model_path"]
OUTPUT_IMAGE_PATH = args["output_image_path"]
LOSS_SUMMARY_PATH = args["loss_summary_path"]

MAX_SIZE = args["max_size"]

content_image = load_image(CONTENT_IMAGE_PATH, max_size=MAX_SIZE)
content_shape = [content_image.shape[1], content_image.shape[0]]
content_image = add_one_dim(content_image)
style_image = load_image(STYLE_IMAGE_PATH, shape=content_shape)
style_image = add_one_dim(style_image)

CONTENT_LAYERS = args["content_layers"]
STYLE_LAYERS = args["style_layers"]
CONTENT_LAYER_WEIGHTS = args["content_layer_weights"]
STYLE_LAYER_WEIGHTS = args["style_layer_weights"]

CONTENT_LOSS_WEIGHT = args["content_loss_weight"]
STYLE_LOSS_WEIGHT = args["style_loss_weight"]
TV_LOSS_WEIGHT = args["tv_loss_weight"]

LEARNING_RATE = args["learning_rate"]
Exemplo n.º 24
0
		if ruta[i] == "/" or ruta[i] == "\\":
			a = i
	if a == -1:
		return ruta
	return ruta[a+1:]

# Quita la extensión a un archivo.	
def quit_extension(archivo):
	for i in range(len(archivo)):
		if archivo[i] == ".":
			a = i
	return archivo[:a]

# Corta un tilest y lo almacena en un array unidimensional.  
def cut_tileset(ruta, (w, h)):
	image = load_image(ruta, True)
	rect = image.get_rect()
	col = rect.w / w
	fil = rect.h / h
	sprite = [None]
		
	for f in range(fil):
		for c in range(col):
			sprite.append(image.subsurface((rect.left, rect.top, w, h)))
			rect.left += w
		rect.top += h
		rect.left = 0
		
	return sprite
	
# Ordena b en función de a.
Exemplo n.º 25
0
import images
import transfer
from constants import *

if __name__ == '__main__':
    content_image = images.load_image(content_path)
    style_image = images.load_image(style_path)
    inputs = {'content_image': content_image, 'style_image': style_image}

    images.plot_images(content_image, style_image)

    image = tf.Variable(content_image)
    transfer.transfer_style(image, epochs, steps_per_epoch, optimizer, layers,
                            inputs, weights)
    images.convert_tensor_to_image(image).save(output_path)

    new_image = images.load_image(output_path)
    images.plot_images(content_image, style_image, new_image)