Browse Source

added text, trails

pixelbath 3 years ago
parent
commit
94f34d64ec
1 changed files with 58 additions and 16 deletions
  1. 58 16
      fireworks.lua

+ 58 - 16
fireworks.lua

@@ -4,16 +4,18 @@
 -- script: lua
 
 t=0
-color_fuse = {12,4}
 colors = {
 	{3,2,1},
-	{7,6,5},
+	{5,6,7},
 	{11,10,9},
 	{15,14,13},
+	{12,4,2}, -- fuse colors
 }
 
 seeds = {}
 
+flashy_color = 1
+
 -- basic todo:
 
 --	seed
@@ -34,17 +36,20 @@ seeds = {}
 --		crossette - multiple large stars that burst into smaller stars with a loud crackling
 --		falling leaves - stars twinkle and flutter down
 
-function create_star(xpos, ypos, xvel, yvel, color)
-	local star_color = color or math.random(3)+1
+function create_star(xpos, ypos, xvel, yvel, colorgroup)
+	local group = colorgroup or math.random(3)+1
 	local new_star = {
 		vel_x = xvel,
 		vel_y = yvel,
-		color = star_color,
+		color = colors[group][1],
+		color_group = group,
 		x = xpos, y = ypos,
 		num_children = 0,
 		t = 0, det = 200,
 		shape = nil,
 		is_seed = false,
+		is_spark = false,
+		has_trail = false,
 	}
 	return new_star
 end
@@ -53,32 +58,56 @@ function fireworks_update()
 	local delete_seeds = {}
 	for i = 1, #seeds do
 		local this_seed = seeds[i]
+		local will_delete = false
 		
 		-- friction and gravity
-		this_seed.vel_y = this_seed.vel_y + 0.012
+		this_seed.vel_y = this_seed.vel_y + 0.011
 		this_seed.x = this_seed.x + (this_seed.vel_x * 0.9)
 		this_seed.y = this_seed.y + (this_seed.vel_y * 0.9)
 
-		pix(this_seed.x, this_seed.y, this_seed.color)
-		-- print(this_seed.t..','..this_seed.det, this_seed.x + 2, this_seed.y, this_seed.color, false, 1, true)
-
 		-- ways to remove particles
 		if this_seed.y > 136 then
-			table.insert(delete_seeds, i)
+			will_delete = true
 		end
 		if this_seed.det > 0 and this_seed.t > this_seed.det then
 			spawn_explosion(this_seed)
-			table.insert(delete_seeds, i)
+			will_delete = true
 		end
 		if this_seed.is_seed then
 			if this_seed.vel_y > -0.1 and math.random() > 10 * math.abs(this_seed.vel_y) then
 				spawn_explosion(this_seed)
-				table.insert(delete_seeds, i)
+				will_delete = true
 			end
 		end
 
+		-- spawn a trail
+		if this_seed.is_seed then
+			local spark = create_star(this_seed.x, this_seed.y, math.random() * 0.5 - 0.25, math.random() * 0.5 - 0.25, 5)
+			spark.det = 12
+			spark.is_spark = true
+			table.insert(seeds, spark)
+		end
+
+		if this_seed.has_trail then
+			local spark = create_star(this_seed.x, this_seed.y, math.random() * 0.5 - 0.25, math.random() * 0.5 - 0.25, this_seed.color_group)
+			spark.det = 6
+			table.insert(seeds, spark)
+		end
+
+		-- color updates
+		if this_seed.det > 0 then
+			local perc = this_seed.t / this_seed.det
+			if perc > 0.3 then this_seed.color = colors[this_seed.color_group][2] end
+			if perc > 0.6 then this_seed.color = colors[this_seed.color_group][3] end
+		end
+
+		-- draw this guy
+		if not this_seed.is_seed then pix(this_seed.x, this_seed.y, this_seed.color) end
+
 		this_seed.t = this_seed.t + 1
+		if will_delete then table.insert(delete_seeds, i) end
 	end
+
 	for i = #delete_seeds, 1, -1 do
 		table.remove(seeds, delete_seeds[i])
 	end
@@ -91,10 +120,11 @@ function spawn_explosion(star)
 	if star.shape == 'peony' then
 		local angle = 2 * math.pi / star.num_children
 		for i = 1, star.num_children do
-			local xvel = math.cos(angle * i) * ((math.random() * 0.5) + 0.3)
-			local yvel = math.sin(angle * i) * ((math.random() * 0.5) + 0.3)
-			local child_star = create_star(star.x, star.y, xvel, yvel, star.color)
+			local xvel = math.cos(angle * i) * ((math.random() * 0.7) + 0.05)
+			local yvel = math.sin(angle * i) * ((math.random() * 0.7) + 0.05)
+			local child_star = create_star(star.x, star.y, xvel, yvel, star.color_group)
 			child_star.det = math.random() * 30 + 50
+			child_star.has_trail = true
 			table.insert(seeds, child_star)
 		end
 	end
@@ -105,13 +135,25 @@ function TIC()
 		local seed_yvel = -1 + (math.random() * -1)
 		local seed = create_star(math.random(240), 136, 0, seed_yvel)
 		seed.shape = 'peony'
-		seed.num_children = 100
+		seed.num_children = 150
 		seed.is_seed = true
 		table.insert(seeds, seed)
 	end
 
 	cls(0)
 	fireworks_update()
+
+	if t % 3 == 0 then flashy_color = math.floor(math.random(14)) + 1 end
+
+	print("WELL DONE!", 240/2-35, 10, 12, false, 1, false)
+	print("Time: 30:00", 240/2-26, 28, 12, false, 1, true)
+	print("Deaths: 10", 240/2-26, 36, 12, false, 1, true)
+	print("Cat memes: 25/25", 240/2-38, 44, 12, false, 1, true)
+
+	print("More motivational text!", 240/2-48, 60, flashy_color, false, 1, true)
+
+	print("Press A to continue", 240/2-42, 90, 12, false, 1, true)
+	print("Press B to go to the main menu", 240/2-58, 98, 12, false, 1, true)
 	t=t+1
 end