Example #1
0
    def render(self, gl, w, h, ascii_r=None):

        zfar = 1000
        znear = 0.1

        # Create view and projection matrix
        #
        proj = mat4.perspectiveProjection(math.pi / 3,
                                          float(w) / h, znear, zfar)
        view = self.scene["ship"].get_view_matrix()

        # Render all objects in the scene
        #
        for (_, obj) in self.scene.items():
            obj.draw(gl, proj, view)

        if ascii_r:
            art = ascii.wordart('Asteroid\nStar\nCaptain\n-  II  -',
                                'star_wars',
                                align='c',
                                linespace=1)
            ascii_r.draw_text(art,
                              textorigin=(0.5, 0.5),
                              screenorigin=(0.5, 0.5),
                              color=(0.333, 1, 1))

            art2 = ascii.wordart('[SHOOT] to start', 'small')
            if self.pause % 50 > 25:
                ascii_r.draw_text(art2,
                                  textorigin=(0.5, 0),
                                  screenorigin=(0.5, 0.1),
                                  color=(1, 0.333, 1))

        return proj
Example #2
0
	def render(self, gl, w, h, ascii_r=None):

		zfar = 1000
		znear = 0.1

		# Create view and projection matrix
		#
		proj = mat4.perspectiveProjection(math.pi / 3, float(w)/h, znear, zfar)
		view = self.scene["ship"].get_view_matrix()

		# Render all objects in the scene
		# 
		for (_, obj) in self.scene.items():
			obj.draw(gl, proj, view)



		if ascii_r:
			art = ascii.wordart('Asteroid\nStar\nCaptain\n-  II  -', 'star_wars', align='c', linespace=1)
			ascii_r.draw_text(art, textorigin=(0.5,0.5), screenorigin=(0.5,0.5), color=(0.333,1,1))
			
			art2 = ascii.wordart('[SHOOT] to start', 'small')
			if self.pause % 50 > 25: ascii_r.draw_text(art2, textorigin=(0.5,0), screenorigin=(0.5,0.1), color=(1,0.333,1))
			
		return proj
Example #3
0
    def render(self, gl, w, h, ascii_r=None):
        if ascii_r:
            titleArt = ascii.wordart('CREDITS', 'star_wars')
            ascii_r.draw_text(titleArt,
                              color=(0.333, 1, 1),
                              screenorigin=(0.5, 0.9),
                              textorigin=(0.5, 0.5))

            ascii_r.draw_text(self.textarea,
                              textorigin=(0.5, 0.5),
                              screenorigin=(0.5, 0.5))
Example #4
0
	def render(self, gl, w, h, ascii_r=None):
		if ascii_r:
			titleArt = ascii.wordart('HIGHSCORE', 'star_wars')
			ascii_r.draw_text(titleArt, color = (0.333, 1, 1), screenorigin = (0.5, 0.9), textorigin = (0.5, 0.5), align = 'c')
			if self.state==0:
				if self.pause % 50 < 25 and self.done:
					selectedArt = ascii.wordart("[SHOOT] to continue", 'big')
					ascii_r.draw_text(selectedArt, color = (0.333, 1, 1), screenorigin = (0.5, 0.3), textorigin = (0.5, 0.5), align = 'c')
					
				elif (self.pause % 50 < 25 or self.keyispressed) and not self.done:
					character = self.alphabet[self.selected]
					if character == " ":
						character = "_"
					selectedArt = ascii.wordart(character, 'big')
					ascii_r.draw_text(selectedArt, color = (0.333, 1, 1), screenorigin = (self.startlocation+(self.selectindex*0.05), 0.5), textorigin = (0.5, 0.5), align = 'c')
				
				for i in range(0,len(self.name)):
					if not i == self.selectindex or self.done:
						character = self.name[i]
						if character == " ":
							character = "_"
						nameArt = ascii.wordart(character, 'big')
						ascii_r.draw_text(nameArt, color = (0.333, 1, 1), screenorigin = (self.startlocation+(0.05*i), 0.5), textorigin = (0.5, 0.5), align = 'c')
				
				
				scoreArt = ascii.wordart("SCORE: "+str(self.score), 'big')
				ascii_r.draw_text(scoreArt, color = (0.333, 1, 1), screenorigin = (0.5, 0.1), textorigin = (0.5, 0.5), align = 'c')
				
			if self.state>=1:
				count = 0
				offset = (self.pause / 20) % len(self.entries)
				for entry in self.entries[offset:]:
					nameArt = ascii.wordart(entry[0],'big')
					ascii_r.draw_text(nameArt, color = (1, 0.333, 1), screenorigin = (0.25, 0.7-(0.1*count)), textorigin = (0.5, 0.5), align = 'l')
					
					scoreArt = ascii.wordart(entry[1],'big')
					ascii_r.draw_text(scoreArt, color = (1, 0.333, 1), screenorigin = (0.75, 0.7-(0.1*count)), textorigin = (0.5, 0.5), align = 'r')
					count+=1
				if self.state==1:
					yourscoreArt = ascii.wordart("YOUR SCORE: ",'big')
					ascii_r.draw_text(yourscoreArt, color = (1, 0.333, 1), screenorigin = (0.5, 0.05), textorigin = (0.5, 0.5), align = 'c')
					yourscoreNumArt = ascii.wordart(str(self.score),'big')
					ascii_r.draw_text(yourscoreNumArt, color = (1, 0.333, 1), screenorigin = (0.75, 0.05), textorigin = (0.5, 0.5), align = 'r')
Example #5
0
	def draw_ascii(self, ascii_r, proj, view):
		ascii_r.draw_text(ascii.wordart(('LEVEL: '+str(self.level)), 'small'), color = (0.333, 1, 1), screenorigin = (0.0, 0.99), textorigin = (0.0, 1.0))
		ascii_r.draw_text(ascii.wordart(('SCORE: '+str(self.score)), 'small'), color = (0.333, 1, 1), screenorigin = (0.0, 0.99), textorigin = (0.0, 1.0), pos=(0,-5))
		ascii_r.draw_text(ascii.wordart(('END: '+str(self.end)), 'small'), color = (0.333, 1, 1), screenorigin = (0.0, 0.99), textorigin = (0.0, 1.0), pos=(0,-10))
		
		if not self.dead:
			
			# healthbar
			ascii_r.draw_text(ascii.box('\n'.join(['#' * (self.health // 1) + ' ' * ((100 - self.health) // 1)] * 3)), color=(1,0.333,1), screenorigin=(0.5,0.0), textorigin=(0.5,0), pos=(0,1))
			
			# Retical for enemy ship HACKY
			#
			if self.enemy_position.z < self.position.z:
				ship_on_screen = (proj * view).multiply_vec4(vec4.from_vec3(self.enemy_position, 1)).vec3()
				ship_ascii_pos = vec3.clamp((ship_on_screen + vec3([1,1,1])).scale(0.5), vec3([0,0,0]), vec3([1,1,1]))
				ascii_r.draw_text("X--\0\0\0\0--X\n|\0\0\0\0\0\0\0\0|\n\n\0\0\0\0\0\0\0\0\0\0\n\n\0\0\0\0\0\0\0\0\0\0\n\n|\0\0\0\0\0\0\0\0|\nX--\0\0\0\0--X", color = (1, 0.333, 1), screenorigin = (ship_ascii_pos.x,ship_ascii_pos.y), textorigin = (0.5, 0.5))
				ascii_r.draw_text(self.ehb, color = (1, 0.333, 1), screenorigin = (ship_ascii_pos.x,ship_ascii_pos.y), textorigin = (0.5, 1), pos=(0,-4))
				

			# Retical for mines
			#
			#for m in self.mine_positions:
			#	mine_on_screen = (proj * view).multiply_vec4(vec4.from_vec3(m.position, 1)).vec3()
			#	mine_ascii_pos = vec3.clamp((mine_on_screen + vec3([1,1,1])).scale(0.5), vec3([0,0,0]), vec3([1,1,1]))
			#	ascii_r.draw_text("X\0X\n\0X\0X\0\n\n\0X\0\n\0X\0X\0\nX\0X", color = (1, 0.333, 1), screenorigin = (mine_ascii_pos.x,mine_ascii_pos.y), textorigin = (0.5, 0.5))

			# Retical for aiming
			# 
			rotate = self.get_orientation_matrix()
			bullet_direction = (rotate.multiply_vec4(vec4([0,0,-1,0])).xyz).unit()
			t = ray_plane_intersection( (self.position, bullet_direction), (vec3([0,0,1]), self.enemy_position.z) )
			if t:
				shoot_pos = self.position + bullet_direction.scale(t)

				shoot_on_screen = (proj * view).multiply_vec4(vec4.from_vec3(shoot_pos, 1)).vec3()
				shoot_ascii_pos = (shoot_on_screen + vec3([1,1,1])).scale(0.5)
				ascii_r.draw_text("\0\0|\0\0|\0\0\n\0\0|\0\0|\0\0\n==#==#==\n\0\0|\0\0|\0\0\n\0\0|\0\0|\0\0", color = (0.333, 1, 1), screenorigin = (shoot_ascii_pos.x,shoot_ascii_pos.y), textorigin = (0.5, 0.5))
Example #6
0
	def render(self, gl, w, h, ascii_r=None):

		self.alive_for += 1

		zfar = 1000
		znear = 0.1

		# Create view and projection matrix
		#
		proj = mat4.perspectiveProjection(math.pi / 3, float(w)/h, znear, zfar)

		cam_pos = vec3([0,-4,15])
		view = mat4.translate(cam_pos.x, cam_pos.y, cam_pos.z).inverse()
		model = mat4.rotateX(math.pi * 0.3) * mat4.rotateY(math.pi * (self.alive_for/100.0)) * mat4.scale(0.25, 0.25, 0.25)
		mv = view * model

		# Retreive model and shader
		#
		vao, vao_size = Assets.get_geometry(tag="enemyship")
		prog = Assets.get_shader(tag="ship")

		# Render Ship
		# 
		gl.glUseProgram(prog)
		gl.glBindVertexArray(vao)
		
		gl.glUniform3f(gl.glGetUniformLocation(prog, "color"), 0.333, 1, 1)
		gl.glUniform1f(gl.glGetUniformLocation(prog, "explode_time"), 0.0)
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(prog, "modelViewMatrix"), 1, True, pygloo.c_array(GLfloat, mv.flatten()))
		gl.glUniformMatrix4fv(gl.glGetUniformLocation(prog, "projectionMatrix"), 1, True, pygloo.c_array(GLfloat, proj.flatten()))

		gl.glDrawArrays(GL_TRIANGLES, 0, vao_size)


		if ascii_r:
			art = ascii.wordart("Level {l}".format(l=self.level), 'big', align='c')
			ascii_r.draw_text(art, color = (1, 0.333, 1), screenorigin = (0.5,0.333), textorigin = (0.5, 0.0), align = 'c')
			ascii_r.draw_text(self.textarea, screenorigin=(0.5,0.333), textorigin=(0.5, 1.0))



		return proj
    def render(self, gl, w, h, ascii_r=None):
        if ascii_r:
            titleArt = ascii.wordart('HIGHSCORE', 'star_wars')
            ascii_r.draw_text(titleArt,
                              color=(0.333, 1, 1),
                              screenorigin=(0.5, 0.9),
                              textorigin=(0.5, 0.5),
                              align='c')
            if self.state == 0:
                if self.pause % 50 < 25 and self.done:
                    selectedArt = ascii.wordart("[SHOOT] to continue", 'big')
                    ascii_r.draw_text(selectedArt,
                                      color=(0.333, 1, 1),
                                      screenorigin=(0.5, 0.3),
                                      textorigin=(0.5, 0.5),
                                      align='c')

                elif (self.pause % 50 < 25
                      or self.keyispressed) and not self.done:
                    character = self.alphabet[self.selected]
                    if character == " ":
                        character = "_"
                    selectedArt = ascii.wordart(character, 'big')
                    ascii_r.draw_text(selectedArt,
                                      color=(0.333, 1, 1),
                                      screenorigin=(self.startlocation +
                                                    (self.selectindex * 0.05),
                                                    0.5),
                                      textorigin=(0.5, 0.5),
                                      align='c')

                for i in range(0, len(self.name)):
                    if not i == self.selectindex or self.done:
                        character = self.name[i]
                        if character == " ":
                            character = "_"
                        nameArt = ascii.wordart(character, 'big')
                        ascii_r.draw_text(nameArt,
                                          color=(0.333, 1, 1),
                                          screenorigin=(self.startlocation +
                                                        (0.05 * i), 0.5),
                                          textorigin=(0.5, 0.5),
                                          align='c')

                scoreArt = ascii.wordart("SCORE: " + str(self.score), 'big')
                ascii_r.draw_text(scoreArt,
                                  color=(0.333, 1, 1),
                                  screenorigin=(0.5, 0.1),
                                  textorigin=(0.5, 0.5),
                                  align='c')

            if self.state >= 1:
                count = 0
                offset = (self.pause / 20) % len(self.entries)
                for entry in self.entries[offset:]:
                    nameArt = ascii.wordart(entry[0], 'big')
                    ascii_r.draw_text(nameArt,
                                      color=(1, 0.333, 1),
                                      screenorigin=(0.25, 0.7 - (0.1 * count)),
                                      textorigin=(0.5, 0.5),
                                      align='l')

                    scoreArt = ascii.wordart(entry[1], 'big')
                    ascii_r.draw_text(scoreArt,
                                      color=(1, 0.333, 1),
                                      screenorigin=(0.75, 0.7 - (0.1 * count)),
                                      textorigin=(0.5, 0.5),
                                      align='r')
                    count += 1
                if self.state == 1:
                    yourscoreArt = ascii.wordart("YOUR SCORE: ", 'big')
                    ascii_r.draw_text(yourscoreArt,
                                      color=(1, 0.333, 1),
                                      screenorigin=(0.5, 0.05),
                                      textorigin=(0.5, 0.5),
                                      align='c')
                    yourscoreNumArt = ascii.wordart(str(self.score), 'big')
                    ascii_r.draw_text(yourscoreNumArt,
                                      color=(1, 0.333, 1),
                                      screenorigin=(0.75, 0.05),
                                      textorigin=(0.5, 0.5),
                                      align='r')
Example #8
0
	def render(self, gl, w, h, ascii_r=None):
		zfar = 1000
		znear = 0.1

		# Create view and projection matrix
		#
		proj = mat4.perspectiveProjection(math.pi / 3, float(w)/h, znear, zfar)
		view = self.scene["ship"].get_view_matrix()
		# view = self.scene["enemy_ship"].get_view_matrix()

		# Render all objects in the scene
		# 
		for (_, obj) in self.scene.items():
			obj.draw(gl, proj, view)

		if ascii_r:
			for (_, obj) in self.scene.items():
				obj.draw_ascii(ascii_r, proj, view)

			ship = self.scene['ship']
			
			if ship.win:
				if self.show_score :
					art = ascii.wordart('Bonuses!\n', 'big', align='c')
					ascii_r.draw_text(art, color = (0.333, 1, 1), screenorigin = (0.5,0.75), textorigin = (0.5, 0.0))

					# Draw the bonus from mission_info
					art = ascii.wordart('Bounty\nDamage Bill\nAmmo Bill\nProfit', 'big', align='r')
					ascii_r.draw_text(art, color = (1, 0.333, 1), screenorigin = (0.45,0.75), textorigin = (1.0, 1.0))

					#Scores associated with bonuses
					art = ascii.wordart('${0}\n$-{1}\n$-{2}\n${3}'.format(self.bounty, self.damage_bill, self.ammo_bill, self.score), 'big', align='r')
					ascii_r.draw_text(art, color = (0.333, 1, 1), screenorigin = (0.55,0.75), textorigin = (0.0, 1.0))

				else :
					art = ascii.wordart('SHOT BRO!', 'big', align='c')
					ascii_r.draw_text(art, color = (0.333, 1, 1), screenorigin = (0.5,0.5), textorigin = (0.5, 0.5))

					art = ascii.wordart('[SHOOT] to continue', 'small', align='c')
					ascii_r.draw_text(art, color = (1, 0.333, 1), screenorigin = (0.5,0.3), textorigin = (0.5, 0.5))
				
			elif self.scene["ship"].dead:
				art = ascii.wordart('YOU HAVE DIED !\nYOU LOSE !', 'big', align='c')
				ascii_r.draw_text(art, color = (0.333, 1, 1), screenorigin = (0.5,0.5), textorigin = (0.5, 0.5))

				art = ascii.wordart('[SHOOT] to continue', 'small', align='c')
				ascii_r.draw_text(art, color = (1, 0.333, 1), screenorigin = (0.5,0.3), textorigin = (0.5, 0.5))
			
			elif self.scene["enemy_ship"].win:
				art = ascii.wordart('YOUR BOUNTY ESCAPED !\nNo one will hire you anymore.\nYOU LOSE !', 'big', align='c')
				ascii_r.draw_text(art, color = (0.333, 1, 1), screenorigin = (0.5,0.5), textorigin = (0.5, 0.5))

				art = ascii.wordart('[SHOOT] to continue', 'small', align='c')
				ascii_r.draw_text(art, color = (1, 0.333, 1), screenorigin = (0.5,0.3), textorigin = (0.5, 0.5))
		# temp ?
		
		


		# Debug colliding spheres
		#
		if self.show_spheres:
			all_spheres = [s for (_, obj) in self.scene.items() for s in obj.get_sphere_list()]
			# all_spheres.extend( self.scene["ship"].get_sphere_list() )
			# all_spheres.extend( self.scene["bullet_collection"].get_sphere_list() )
			# all_spheres.extend( self.scene["asteroid_field"].get_sphere_list() )

			if len(all_spheres) > 0 :

				# Retreive model and shader
				#
				vao, vao_size = Assets.get_geometry(tag="sphere")
				inst_vbo = Assets.get_inst_vbo(tag="sphere")
				prog = Assets.get_shader(tag="sphere")

				# Load geometry, shader and projection once
				#
				gl.glUseProgram(prog)
				gl.glBindVertexArray(vao)
				gl.glUniformMatrix4fv(gl.glGetUniformLocation(prog, "projectionMatrix"), 1, True, pygloo.c_array(GLfloat, proj.flatten()))

				gl.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

				# Create and buffer the instance data
				# 
				mv_array = []
				for s in all_spheres:
					scale = mat4.scale(s.radius, s.radius, s.radius)
					position = mat4.translate(s.center.x, s.center.y, s.center.z)
					mv = (view * position * scale).transpose()
					mv_array.extend(mv.flatten())

				mv_c_array = pygloo.c_array(GLfloat, mv_array)
				gl.glBindBuffer( GL_ARRAY_BUFFER, inst_vbo )
				gl.glBufferData( GL_ARRAY_BUFFER, sizeof(mv_c_array), mv_c_array, GL_STREAM_DRAW )

				# Render
				# 	
				gl.glDrawArraysInstanced(GL_TRIANGLES, 0, vao_size, len(all_spheres))

				gl.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)


				
		# ascii needs proj matrix
		return proj
Example #9
0
	def render(self, gl, w, h, ascii_r=None):
		if ascii_r:
			titleArt = ascii.wordart('CREDITS', 'star_wars')
			ascii_r.draw_text(titleArt, color = (0.333, 1, 1), screenorigin = (0.5, 0.9), textorigin = (0.5, 0.5))
			
			ascii_r.draw_text(self.textarea, textorigin=(0.5,0.5), screenorigin=(0.5,0.5))