Example #1
0
def reset_score_phase():
	Main.sprites["title"] = Main.sprites["get_ready"]
	Main.sprites["gameover"].position = hg.Vec2(0.5, convy(224 + 150))
	Main.sprites["panel"].position = hg.Vec2(0.5, convy(164 + 150))
	if Main.score > Main.score_max:
		Main.score_max = Main.score

	Main.animations = [SpriteAnimator(Main.sprites["gameover"], hg.Vec2(0.5, convy(224)), hg.Color.White, 0, 0.5),
					   SpriteAnimator(Main.sprites["panel"], hg.Vec2(0.5, convy(164)), hg.Color.White, 0, 0.5)]
Example #2
0
	def __init__(self, fileName, scale, center=None):
		self.color = hg.Color.White
		self.position = hg.Vec2(0, 0)
		self.position_prec = hg.Vec2(0, 0)
		self.vertices = hg.Vertices(Sprite.vtx_layout, 4)
		self.texture, self.textureinfo = hg.LoadTextureFromAssets(fileName, hg.TF_UClamp | hg.TF_VClamp | hg.TF_SamplerMinPoint | hg.TF_SamplerMagPoint)
		print("width: ", self.textureinfo.width, "height: ", self.textureinfo.height)
		self.scale = scale
		if center is None:
			self.center = hg.Vec2(self.textureinfo.width // 2, self.textureinfo.height // 2)
		else:
			self.center = hg.Vec2(center)
Example #3
0
	def draw_rot(self, angle=0, position=None, color=None):
		if position is None:
			position = self.position
		if color is None:
			color = self.color
		w, h = self.textureinfo.width, self.textureinfo.height
		# Rotate:
		p0 = self.center * -1
		p1 = p0 + hg.Vec2(w, h)
		Sprite.z_depth -= 0.1

		mat = hg.TransformationMat4(
			hg.Vec3(position.x * Main.resolution.x, position.y * Main.resolution.y, 0), hg.Vec3(0, 0, angle),
			hg.Vec3(self.scale, self.scale, 1))

		self.vertices.Clear()
		self.vertices.Begin(0).SetPos(mat * hg.Vec3(p0.x, p0.y, Sprite.z_depth)).SetTexCoord0(hg.Vec2(0, 1)).End()
		self.vertices.Begin(1).SetPos(mat * hg.Vec3(p0.x, p1.y, Sprite.z_depth)).SetTexCoord0(hg.Vec2(0, 0)).End()
		self.vertices.Begin(2).SetPos(mat * hg.Vec3(p1.x, p1.y, Sprite.z_depth)).SetTexCoord0(hg.Vec2(1, 0)).End()
		self.vertices.Begin(3).SetPos(mat * hg.Vec3(p1.x, p0.y, Sprite.z_depth)).SetTexCoord0(hg.Vec2(1, 1)).End()
		quad_idx = [0, 3, 2, 0, 2, 1]

		# Display:
		uniformvalues = hg.MakeUniformSetValue("color", hg.Vec4(color.r, color.g, color.b, color.a))
		hg.DrawTriangles(0, quad_idx, self.vertices, shader_texture, [uniformvalues], [hg.MakeUniformSetTexture("s_texTexture", self.texture, 0)], render_state_quad)
Example #4
0
def draw_score_panel():
	score_digits = [int(x) for x in list(str(Main.score))]
	score_max_digits = [int(x) for x in list(str(Main.score_max))]
	score_digits.reverse()
	score_max_digits.reverse()
	pos = Main.sprites["panel"].position
	y_score = pos.y + convy(2)
	y_score_max = pos.y + convy(-18)

	x = pos.x + convx(51)
	for digit in score_digits:
		x -= convx(Main.sprites['min_numbers'][digit].get_width())
		Main.sprites["min_numbers"][digit].draw(hg.Vec2(x, y_score))

	x = pos.x + convx(51)
	for digit in score_max_digits:
		x -= convx(Main.sprites['min_numbers'][digit].get_width())
		Main.sprites["min_numbers"][digit].draw(hg.Vec2(x, y_score_max))
Example #5
0
	def __init__(self, sprite: Sprite, end_position: hg.Vec2, end_color=hg.Color.White, start_delay=0,
				 duration=0.25):
		self.sprite = sprite
		self.start_position = hg.Vec2(sprite.position)
		self.start_color = sprite.color
		self.end_color = end_color
		self.end_position = end_position
		self.duration = duration
		self.start_delay = start_delay
		self.start_date = -1
Example #6
0
def draw_score():
	digits = [int(x) for x in list(str(Main.score))]
	total_width = 0  # total width of all numbers to be printed
	for digit in digits:
		total_width += Main.sprites['numbers'][digit].get_width()

	x_offset = 0.5 - convx(total_width) / 2

	for digit in digits:
		Main.sprites["numbers"][digit].draw(hg.Vec2(x_offset, convy(216)))
		x_offset += convx(Main.sprites['numbers'][digit].get_width())
Example #7
0
class Main:
	# Display settings:
	plus = None
	original_resolution = hg.Vec2(455, 256)
	resolution = hg.Vec2(1280, 720)
	game_scale = resolution.y / original_resolution.y
	antialiasing = 0

	# --- Sprites:
	sprites = []
	ship = None
	flames = None

	# --- Game parameters:
	scrolls_x = [0] * 10
	scrolling_speed = 0
	distance_min = 26 * 3.5
	num_doors = 4
	num_pillars_bottom = 16
	doors_counter = 0
	pillars_doors = []
	pillars_bottom = []
	animations = []
	game_speed = {"easy": 0.8, "normal": 1.0, "hard": 1.1}
	collision_accuracy = {"easy": 0.5, "normal": 0.75, "hard": 1.0}
	difficulty_level = "normal"

	score = 0
	score_max = 0

	delta_t = 0

	# --- Flash:
	collision_time = 0
	flash_delay = 0.5

	# --- Sfx:
	audio = None
	sounds = {}
Example #8
0
	def __init__(self, frames):
		self.position = hg.Vec2(1 / 3, 0)
		self.frames = frames
		self.angle = 0
		self.frame = 0
		self.y_speed = 0
		self.gravity = 4
		self.booster_delay = 0.25
		self.booster_counter = 0
		self.is_broken = False
		self.broken_face = False
		self.width = 32
		self.height = 16
Example #9
0
def draw_pillars(speed):
	x_restart = speed + convx(Main.original_resolution.x + 26)
	if Main.pillars_doors[0].position.x < -convx(26) + speed:
		x = Main.pillars_doors[0].position.x
		Main.pillars_doors.pop(0)
		Main.pillars_doors.pop(0)
		Main.pillars_doors.append(
			SpriteInstance(Main.sprites["pillars"][int(uniform(0, 4))], hg.Vec2(x + x_restart, 0)))
		Main.pillars_doors.append(
			SpriteInstance(Main.sprites["pillars"][int(uniform(0, 4))], hg.Vec2(x + x_restart, 0)))
		random_pillars_doors_y(Main.pillars_doors[-2], Main.pillars_doors[-1])
		Main.doors_counter -= 1
		if Main.doors_counter < 0:
			Main.doors_counter = Main.num_doors - 1

	if Main.pillars_bottom[0].position.x < -convx(26) + speed:
		x = Main.pillars_bottom[0].position.x
		Main.pillars_bottom.pop(0)
		Main.pillars_bottom.append(
			SpriteInstance(Main.sprites["pillars"][int(uniform(0, 4))], hg.Vec2(x + x_restart, 0)))
		Main.pillars_bottom[-1].position.y = random_pillar_bottom_y()

	# Movement:
	for pillar in Main.pillars_bottom:
		pillar.position.x -= speed
		pillar.draw()

	for pillar in Main.pillars_doors:
		pillar.position.x -= speed
		pillar.draw()

	# draw flag:
	pos = Main.pillars_doors[2 * Main.doors_counter + 1].position
	Main.sprites["flag"].position_prec = Main.sprites["flag"].position
	Main.sprites["flag"].position = hg.Vec2(pos.x + convx(13), pos.y + convy(121))
	Main.sprites["flag"].draw()
Example #10
0
def init_sprites():
	Sprite.createvtxlayout()
	Main.sprites = {"ship": [], "numbers": [], "min_numbers": [], "pillars": [], "parallaxes": [], "vapors": [],
					"background": Sprite("bg4_16_9.png", Main.game_scale, hg.Vec2(0, 0)),
					"flag": Sprite("checkpoint.png", Main.game_scale, hg.Vec2(5, 0)),
					"explode": Sprite("boom2.png", Main.game_scale),
					"title": Sprite("title_x2.png", Main.game_scale),
					"get_ready": Sprite("getready.png", Main.game_scale),
					"explain": Sprite("explain_space.png", Main.game_scale),
					"gameover": Sprite("gameover.png", Main.game_scale),
					"panel": Sprite("panel.png", Main.game_scale),
					"difficulty_level":{"easy":Sprite("level_easy.png", Main.game_scale),
										"normal": Sprite("level_normal.png", Main.game_scale),
										"hard": Sprite("level_hard.png", Main.game_scale)
										}
					}
	# Ship frames:
	for n in range(4):
		Main.sprites["ship"].append(Sprite("ship_" + str(n) + ".png", Main.game_scale, hg.Vec2(28, 20)))

	# Numbers font:
	for n in range(10):
		Main.sprites["numbers"].append(Sprite("" + str(n) + ".png", Main.game_scale))
		Main.sprites["min_numbers"].append(Sprite("min" + str(n) + ".png", Main.game_scale))

	# Pillars:
	for n in range(4):
		Main.sprites["pillars"].append(Sprite("pillar_" + str(n) + ".png", Main.game_scale, hg.Vec2(0, 0)))

	# Parallaxes:
	for key in ["front2bottom", "front2top", "front1bottom", "front1top", "ground", "bg1", "bg2", "bg3", "bg3b"]:
		Main.sprites["parallaxes"].append(Sprite("" + key + ".png", Main.game_scale, hg.Vec2(0, 0)))

	# Vapors:
	for key in ["vapor0", "vapor1"]:
		Main.sprites["vapors"].append(Sprite("" + key + ".png", Main.game_scale))
Example #11
0
def gui_ScreenModeRequester():
	global flag_windowed
	global current_monitor,current_mode,monitors_names,modes
	dt = hg.TickClock()

	# ImGui frame
	hg.ImGuiBeginFrame(res_w, res_h, dt, hg.ReadMouse(), hg.ReadKeyboard())
	hg.ImGuiSetNextWindowPosCenter(hg.ImGuiCond_Always)
	hg.ImGuiSetNextWindowSize(hg.Vec2(res_w, res_h), hg.ImGuiCond_Always)
	if hg.ImGuiBegin("Choose screen mode", True, hg.ImGuiWindowFlags_NoTitleBar
										  | hg.ImGuiWindowFlags_MenuBar
										  | hg.ImGuiWindowFlags_NoMove
										  | hg.ImGuiWindowFlags_NoSavedSettings
										  | hg.ImGuiWindowFlags_NoCollapse):

		if hg.ImGuiBeginCombo("Monitor", monitors_names[current_monitor]):
			for i in range(len(monitors_names)):
				f = hg.ImGuiSelectable(monitors_names[i], current_monitor == i)
				if f:
					current_monitor = i
			hg.ImGuiEndCombo()

		if hg.ImGuiBeginCombo("Screen size", modes[current_monitor][current_mode].name):
			for i in range(len(modes[current_monitor])):
				f = hg.ImGuiSelectable(modes[current_monitor][i].name+"##"+str(i), current_mode == i)
				if f:
					current_mode = i
			hg.ImGuiEndCombo()

		f, d = hg.ImGuiCheckbox("Windowed", flag_windowed)
		if f:
			flag_windowed = d

		ok=hg.ImGuiButton("Ok")
		hg.ImGuiSameLine()
		cancel=hg.ImGuiButton("Quit")
	hg.ImGuiEndFrame(0)
	
	if ok: return "ok"
	elif cancel: return "quit"
	else: return ""
Example #12
0
	def draw(self, position, scrool_x_speed):
		if Main.collision_time < self.flames_delay:
			f = Main.collision_time / self.flames_delay
			color = hg.Color(hg.Color.White * 1 - f + hg.Color.Black * f)
			self.min_scale = 1
			self.max_scale = 3
		else:
			color = hg.Color(hg.Color.Black)
			self.min_scale = 0.75
			self.max_scale = 1.25

		self.particles_cnt_f += Main.delta_t * self.flow
		n = int(self.particles_cnt_f) - self.particles_cnt
		if n > 0:
			for i in range(n):
				particle = self.particles[(self.particles_cnt + i) % self.num_particles]
				particle.scale = uniform(self.min_scale, self.max_scale)
				particle.color = color
				particle.color.a = max(0.5, 1 - (particle.scale - self.min_scale) / (self.max_scale - self.min_scale))
				particle.age = 0
				particle.position = hg.Vec2(position)

				particle.x_speed = uniform(-0.02, 0.02)
			self.particles_cnt += n

		for particle in self.particles:
			if 0 <= particle.age < self.particles_delay:
				particle.position.y += Main.delta_t * self.y_speed
				particle.position.x += scrool_x_speed + particle.x_speed * Main.delta_t
				particle.angle -= 1.8 * Main.delta_t
				particle.age += Main.delta_t
				t = particle.age / self.particles_delay
				self.sprite.scale = self.main_scale * particle.scale * (self.start_scale * (1 - t) + self.end_scale * t)
				color = hg.Color(particle.color)
				color.a *= (1 - t)
				self.sprite.draw_rot(particle.angle, particle.position, color)
Example #13
0
def reset_intro_phase():
	Main.pillars_doors, Main.pillars_bottom = [], []
	Main.ship.reset()
	Main.flames.reset()
	Main.scrolling_speed = 0.9

	Main.sprites["vapors"][0].position = hg.Vec2()
	Main.sprites["vapors"][1].position = hg.Vec2()

	random_vapor_pos(0)
	random_vapor_pos(1)

	Main.doors_counter = 0

	Main.sprites["title"].position = hg.Vec2(0.5, convy(300))
	Main.sprites["explain"].position = hg.Vec2(0.5, 0.67)
	Main.sprites["explain"].color = hg.Color(1, 1, 1, 0)

	Main.animations = [SpriteAnimator(Main.sprites["title"], hg.Vec2(0.5, convy(221)), hg.Color.White, 0, 0.5),
	 				   SpriteAnimator(Main.sprites["explain"], hg.Vec2(0.5, 0.67), hg.Color.White, 0.5, 0.5)]

	for sprite in Main.sprites["difficulty_level"].values():
	 	sprite.position=hg.Vec2(0.5,convy(120))
Example #14
0
def reset_pillars():
	Main.pillars_doors = []
	x = Main.original_resolution.x
	for n in range(Main.num_doors):
		x += (Main.original_resolution.x + 26) / Main.num_doors
		Main.pillars_doors.append(SpriteInstance(Main.sprites["pillars"][int(uniform(0, 4))], hg.Vec2(convx(x), 0)))
		Main.pillars_doors.append(SpriteInstance(Main.sprites["pillars"][int(uniform(0, 4))], hg.Vec2(convx(x), 0)))
		random_pillars_doors_y(Main.pillars_doors[-2], Main.pillars_doors[-1])

	Main.pillars_bottom = []
	x = Main.original_resolution.x
	for n in range(Main.num_pillars_bottom):
		x += (Main.original_resolution.x + 26) / Main.num_pillars_bottom
		Main.pillars_bottom.append(SpriteInstance(Main.sprites["pillars"][int(uniform(0, 4))], hg.Vec2(convx(x), 0)))
		Main.pillars_bottom[-1].position.y = random_pillar_bottom_y()
Example #15
0
import harfang as hg


res_w=520
res_h=160
monitors=None
monitors_names=[]
modes=None
current_monitor=0
current_mode=0
ratio_filter=0
flag_windowed=False

screenModes=[hg.WV_FullscreenMonitor1,hg.WV_FullscreenMonitor2,hg.WV_FullscreenMonitor3]
smr_screenMode=hg.WV_FullscreenMonitor1
smr_resolution=hg.Vec2(1280,1024)

hg.InputInit()
hg.WindowSystemInit()

win = hg.NewWindow("Screen Mode Requester", res_w, res_h, 32)#, hg.WV_Fullscreen)
hg.RenderInit(win)
hg.RenderReset(res_w, res_h, hg.RF_MSAA8X | hg.RF_FlipAfterRender | hg.RF_FlushAfterRender | hg.RF_MaxAnisotropy | hg.RF_VSync)

hg.AddAssetsFolder("../assets_compiled")


# initialize ImGui
imgui_prg = hg.LoadProgramFromAssets('shaders/imgui')
imgui_img_prg = hg.LoadProgramFromAssets('shaders/imgui_image')
Example #16
0
	def __init__(self, sprite, position=hg.Vec2.Zero):
		self.sprite = sprite
		self.position = hg.Vec2(position)
Example #17
0
def draw_parallaxes():
	# plan 10
	Main.sprites["parallaxes"][8].draw(hg.Vec2(Main.scrolls_x[9], convy(65)))
	Main.sprites["parallaxes"][8].draw(hg.Vec2(Main.scrolls_x[9] + convx(256), convy(65)))
	Main.sprites["parallaxes"][8].draw(hg.Vec2(Main.scrolls_x[9] + convx(512), convy(65)))

	# plan 9
	Main.sprites["parallaxes"][7].draw(hg.Vec2(Main.scrolls_x[8], convy(65)))
	Main.sprites["parallaxes"][7].draw(hg.Vec2(Main.scrolls_x[8] + convx(256), convy(65)))
	Main.sprites["parallaxes"][7].draw(hg.Vec2(Main.scrolls_x[8] + convx(512), convy(65)))

	# plan 8: vapor 1
	draw_vapor(1, Main.scrolls_x[7])

	# plan 7
	Main.sprites["parallaxes"][6].draw(hg.Vec2(Main.scrolls_x[6], convy(24)))
	Main.sprites["parallaxes"][6].draw(hg.Vec2(Main.scrolls_x[6] + convx(256), convy(24)))
	Main.sprites["parallaxes"][6].draw(hg.Vec2(Main.scrolls_x[6] + convx(512), convy(24)))

	# plan 6 vapor 0
	draw_vapor(0, Main.scrolls_x[5])

	# plan 5
	Main.sprites["parallaxes"][5].draw(hg.Vec2(Main.scrolls_x[4], convy(14)))
	Main.sprites["parallaxes"][5].draw(hg.Vec2(Main.scrolls_x[4] + convx(256), convy(14)))
	Main.sprites["parallaxes"][5].draw(hg.Vec2(Main.scrolls_x[4] + convx(512), convy(14)))

	# plan 4 : pillars
	if len(Main.pillars_doors) > 0:
		draw_pillars(Main.scrolls_x[3])

	# plan ship:
	Main.ship.draw()

	if Main.ship.is_broken:
		Main.flames.draw(Main.ship.position, -Main.scrolls_x[3] * 0.75)
		draw_flash()

	# plan 3
	Main.sprites["parallaxes"][4].draw(hg.Vec2(Main.scrolls_x[2], convy(-6)))
	Main.sprites["parallaxes"][4].draw(hg.Vec2(Main.scrolls_x[2] + convx(256), convy(-6)))
	Main.sprites["parallaxes"][4].draw(hg.Vec2(Main.scrolls_x[2] + convx(512), convy(-6)))

	# plan 2
	Main.sprites["parallaxes"][3].draw(hg.Vec2(Main.scrolls_x[1], convy(195)))
	Main.sprites["parallaxes"][2].draw(hg.Vec2(Main.scrolls_x[1], 0))
	Main.sprites["parallaxes"][3].draw(hg.Vec2(Main.scrolls_x[1] + convx(512), convy(195)))
	Main.sprites["parallaxes"][2].draw(hg.Vec2(Main.scrolls_x[1] + convx(512), 0))

	# plan 1
	Main.sprites["parallaxes"][1].draw(hg.Vec2(Main.scrolls_x[0], convy(195)))
	Main.sprites["parallaxes"][0].draw(hg.Vec2(Main.scrolls_x[0], -convy(5)))
	Main.sprites["parallaxes"][1].draw(hg.Vec2(Main.scrolls_x[0] + convx(512), convy(195)))
	Main.sprites["parallaxes"][0].draw(hg.Vec2(Main.scrolls_x[0] + convx(512), -convy(5)))