background_image_filename = 'j.jpg'
filename = 'ojizousan2.png'
import sys
import sdl2
import sdl2.ext
clas posi():
    def left():

    
class SoftwareRenderSystem(sdl2.ext.SoftwareSpriteRenderSystem):
   def __init__(self,window):
       super(SoftwareRenderSystem,self).__init__(window)
                
   def render(self,components):
        sdl2.ext.fill(self.surface, BLACK)
        super(SoftwareRenderSystem,self).render(components)

BLACK = sdl2.ext.Color(0, 0, 0)
    
def run():
    sdl2.ext.init()
    window = sdl2.ext.Window("Hello World!", size=(640,480))
    window.show()
    
    #sss = SoftwareRenderSystem(window)
    
    x,y = 0, 0
    move_x,move_y = 0, 0
    renderer = sdl2.ext.Renderer(window)
    factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)
    sprite = factory.from_image("o_def.png")
    sprite1 = factory.from_image("o_def.png")
    #spritebg = factory.from_image("j.jpg")
    
    sss = sdl2.ext.SoftwareSpriteRenderSystem(window)
    world = sdl2.ext.World()
    spriterenderer =SoftwareRenderSystem(window)
    world.add_system(sss)
    while True:
        for event in sdl2.ext.get_events():
            if event.type == sdl2.SDL_QUIT:
                exit()
            if event.type == sdl2.SDL_KEYDOWN:
                if event.key.keysym.sym == sdl2.SDLK_LEFT:
                    move_x += -1
                elif event.key.keysym.sym == sdl2.SDLK_RIGHT:
                    move_x += +1
                elif event.key.keysym.sym == sdl2.SDLK_UP:
                    move_y += -1
                elif event.key.keysym.sym == sdl2.SDLK_DOWN:
                    move_y += +1
                elif event.key.keysym.sym == sdl2.SDLK_ESCAPE:
                    exit()
    
        spriterenderer = factory.create_sprite_render_system(window)
        spriterenderer.render(sprite)
        #spriterenderer.render(spritebg)
        #sdl2.ext.fill(spritebg,BLACK)
        sprite.x=move_x
        sprite.y=move_y
        window.refresh()
        print(move_y,move_x)
sys.exit(run())
