Created
July 26, 2019 13:01
-
-
Save robertpfeiffer/1e82ca9656173afcdb7282341e2a1670 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
import sys | |
import webm_recording | |
from yarn.ninepatch import NinePatchTemplate | |
from yarn.jrpg_froentend import Dialogue | |
pygame.init() | |
screen=pygame.display.set_mode((320,240), pygame.SCALED) | |
group=pygame.sprite.Group() | |
triangle=pygame.sprite.Sprite() | |
triangle.image=pygame.image.load("triangle_sprite.png").convert_alpha() | |
triangle.rect=triangle.image.get_rect() | |
triangle.rect.topleft=20,20 | |
triangle.portraits=dict( | |
neutral=pygame.image.load("triangle_portrait_neutral.png").convert_alpha(), | |
angry=pygame.image.load("triangle_portrait_angry.png").convert_alpha(), | |
happy=pygame.image.load("triangle_portrait_happy.png").convert_alpha(), | |
surprised=pygame.image.load("triangle_portrait_surprised.png").convert_alpha()) | |
square=pygame.sprite.Sprite() | |
square.image=pygame.image.load("square_sprite.png").convert_alpha() | |
square.rect=square.image.get_rect() | |
square.rect.topleft=200,20 | |
square.portraits=dict( | |
neutral=pygame.image.load("square_portrait_neutral.png").convert_alpha(), | |
happy=pygame.image.load("square_portrait_happy.png").convert_alpha()) | |
group.add(square) | |
group.add(triangle) | |
ninpatch=pygame.image.load("ninpatch.png") | |
template=NinePatchTemplate(ninpatch, pygame.Rect(12,12,5,5), pygame.Rect(8,7,18,19)) | |
font=pygame.font.SysFont("Arial", 11) | |
dialogue=Dialogue("a heated exchange","dialogue.json", dict(square=square, triangle=triangle), template, font) | |
clip_recorder=webm_recording.Recorder(screen, prefix="jrpg_dialogue") | |
clip_recorder.start() | |
clock=pygame.time.Clock() | |
running=True | |
while running: | |
evs=pygame.event.get() | |
for e in evs: | |
if e.type==pygame.QUIT: | |
running=False | |
if e.type==pygame.KEYDOWN and e.key==pygame.K_SPACE: | |
dialogue.advance() | |
if e.type==pygame.KEYDOWN and e.key==pygame.K_RIGHT: | |
dialogue.select_next() | |
if e.type==pygame.KEYDOWN and e.key==pygame.K_LEFT: | |
dialogue.select_prev() | |
if e.type==pygame.KEYDOWN and e.key==pygame.K_RETURN: | |
dialogue.choose_option() | |
screen.fill((255,255,255)) | |
group.draw(screen) | |
dialogue.draw(screen) | |
clip_recorder.record_maybe() | |
pygame.display.flip() | |
clock.tick(30) | |
clip_recorder.finish() | |
pygame.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment