def __init__(self, name, x, y, properties={}, **kwargs): self.name = name self.pos = Vector2f(x,-y) * (1.0 / 8) self.mat = self.model_matrix() self.killed = False if 'texture' in properties: self.diffuse = properties['texture'] if 'shader' in properties: self.shader_name = properties['shader'] self.load_sprite(self.diffuse, self.normal) self.shader = Shader.load(self.shader_name) if self.shader is None: raise AttributeError, 'Failed to load shader %s' % self.shader_name
def init(self, size, fullscreen=False): flags = OPENGL|DOUBLEBUF if fullscreen: flags |= FULLSCREEN pygame.display.set_mode(size.xy, flags) pygame.display.set_caption('Ancient Earth') i = pygame.display.Info() self.size = Vector2i(i.current_w, i.current_h) glMatrixMode(GL_MODELVIEW) glEnable(GL_TEXTURE_2D) glDisable(GL_CULL_FACE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) image.setup() self.stage = 1 self.projection = Matrix.perspective(75, self.size, 0.1, 100) self.ortho = Matrix.ortho(self.size) v = np.array([ 0,0,0, 0,0, 1,0,0, 1,0, 1,1,0, 1,1, 0,1,0, 0,1, ], np.float32) i = np.array([0,1,2,3], np.uint32) self.quad = VBO(GL_QUADS, v, i) # parallax self.parallax_rep = 10 v = np.array([ 0,0,0, 0,1, 1,0,0, self.parallax_rep, 1, 1,1,0, self.parallax_rep, 0, 0,1,0, 0,0, ], np.float32) i = np.array([0,1,2,3], np.uint32) self.repquad = VBO(GL_QUADS, v, i) self.parallax = Image('texture/sky.png', wrap=GL_REPEAT) self.hudbg = Image('texture/hud_bottom.png') self.fbo = FBO(self.size, format=GL_RGB8, depth=True) self.shader = Shader.load('default') self.shader_hud = Shader.load('hud') self.post = Shader.load('post') self.windmax = 1.0 self.random_wind() self.ambient_light = (1.0, 1.0, 1.0) fontsize = 16 + int(self.res_hack() * 14) self.map = Map('map.json') self.clock = pygame.time.Clock() self.hud_msgbox = HUD(Vector2i(500,100), 'msgbox') self.hud_ui = HUD(Vector2i(self.size.x, self.size.x * (160./800)), 'ui') self.scrollbar = HUD(Vector2i(self.size.x,28), 'scrollbar') self.font = self.hud_msgbox.create_font(size=fontsize) self.font_ui = self.hud_ui.create_font(size=fontsize, font='Comic Sans MS') self.camera_max = self.map.width - 38 self.catapults = [self.map.get_named_item('Catapult 1'), self.map.get_named_item('Catapult 2')] self.reset() with self.hud_msgbox: self.hud_msgbox.clear((0,1,1,1))