400x400のマップを移動します。
ランダムマップなのでおもしろみはないです。
コーディングはキースキャンが少しはまりました。
Windows7
Python 2.7
pygame 1.9.2a
numpy 1.7.0
いずれも32ビット版を使っています。

bg.png

ランダムマップなのでおもしろみはないです。
コーディングはキースキャンが少しはまりました。
Windows7
Python 2.7
pygame 1.9.2a
numpy 1.7.0
いずれも32ビット版を使っています。

bg.png

#!/usr/bin/python # -*- coding: utf-8 -*- import pygame from pygame.locals import * import random import numpy as np pygame.init() window_size = (640, 480) bg_color = (0, 0, 0) clock = pygame.time.Clock() screen = pygame.display.set_mode(window_size) img_char = pygame.image.load('bg.png') spimg = [] bgx=0 bgy=0 mapdata = np.array([0 for y in range(400*400)]) def bgrandset(): for x in range(400): for y in range(400): mapdata[x+y*400]=random.randrange(0, 5) def spset(): for y in range(10): for x in range(10): temp = pygame.Surface((16, 16), pygame.SRCALPHA) temp.blit(img_char, (0, 0), (x * 16, y * 16, 16, 16)) spimg.append(temp) def bgwrite(bx,by): for x in range(40): for y in range(30): if mapdata[x+bx+(y+by)*400]>=0: screen.blit(spimg[mapdata[x+bx+(y+by)*400]], (x*16, y*16)) def spwrite(cn,x,y): screen.blit(spimg[cn], (x*16, y*16)) spset() bgrandset() pygame.key.set_repeat (30, 30) end_game = False while not end_game: for event in pygame.event.get(): if event.type == pygame.QUIT: end_game = True if event.type == KEYDOWN: if event.key == K_LEFT: if bgx>0: bgx -= 1 if event.key == K_RIGHT: if bgx<400-40: bgx += 1 if event.key == K_UP: if bgy>0: bgy -= 1 if event.key == K_DOWN: if bgy<400-30: bgy += 1 screen.fill(bg_color) bgwrite(bgx,bgy) spwrite(10,20,15) pygame.display.flip() clock.tick(20) pygame.quit() quit()