代码拉取完成,页面将自动刷新
# -*- coding: utf-8 -*-
import pygame
from pygame.locals import *
from Src_loader import *
from Level import *
import tools as t
from npc import Npc
class Background(pygame.sprite.Sprite):
def __init__(self,image,rect,mask):
pygame.sprite.Sprite.__init__(self) #call Sprite intializer
self.name = 'background'
self.image, self.rect = image, rect
self.mask = mask
self.width = self.rect.width
self.height = self.rect.height
self.xy =[self.width/2,self.rect.height]
self.z = 0
self.pos = []
def update(self):
self.rect.left = self.pos[0] - self.width
self.rect.top = self.pos[1] - self.rect.height
def setPos(rectPos):
self.pos = rectPospos
pass
class Level_test(Level):
"""description of class"""
def __init__(self):
Level.__init__(self)
self.level = 'level_0'
self.size = (3000,3000)
self.surface = pygame.Surface(self.size)
self.src_path = 'src'
self.map = 'map_test'
self.sub = None
self.setup()
def setup(self):
#image = load_img(self.src_path + '/map/map1.jpg')
image = load_img(self.src_path + '/level/background.png')
rect = image.get_rect()
image_mask = load_img(self.src_path + '/level/background_mask.png')
image_mask = pygame.mask.from_surface(image_mask)
self.background = Background(image, rect, image_mask)
self.spriteGroup = pygame.sprite.LayeredUpdates(pygame.sprite.Group())
self.config()
pass
def loadBackground(self,screen,pos):
dx = pos[0] - self.pos[0]
dy = pos[1] - self.pos[1]
print(dx,dy)
self.pos = pos
newpos = self.background.rect.move((dx, dy))
def sub_addNpcGroup(self,world,n):
npcNum = n
for i in range(npcNum):
npc = Npc()
npc.name = 'npc' + str(i)
npc.dummy = False
npc.maxHp = 1000
npc.hp = 1000
world.npcGroup.add(npc)
def sub_addNpc(self,world):
n = len(world.npcs)
npc = Npc()
npc.name = 'npc' + str(n)
npc.dummy = False
npc.maxHp = 1000
npc.hp = 1000
world.npcGroup.add(npc)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。