#! /usr/bin/env python
# -*- coding: utf-8 -*-
import pygame
from pygame.locals import *
import sys

SCR_WIDTH,SCR_HEIGHT = 640,480

pygame.init()
screen = pygame.display.set_mode((SCR_WIDTH,SCR_HEIGHT))
pygame.display.set_caption("key event")

backImg = pygame.image.load('j.png').convert()        #背景画像
Img = pygame.image.load('ojizousan2.png').convert_alpha()
Img_rect = Img.get_rect()
Img_rect.center = (320,240)

vx = vy = 10        

while True:
        screen.blit(backImg,(0,0))
        screen.blit(Img,Img_rect)
        pygame.display.update()
        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    sys.exit()
            if event.key == K_LEFT:
                if Img_rect.left > 0:
                    Img_rect.move_ip(-vx,0)
            if event.key == K_RIGHT:
                if Img_rect.right < SCR_WIDTH:
                    Img_rect.move_ip(vx,0)
            if event.key == K_UP:
                if Img_rect.top > 0:
                    Img_rect.move_ip(0,-vy)
            if event.key == K_DOWN:
                if Img_rect.bottom < SCR_HEIGHT:
                    Img_rect.move_ip(0,vy)
