Browse Source

making it rain

pixelbath 3 years ago
parent
commit
a186ae83ae
1 changed files with 78 additions and 25 deletions
  1. 78 25
      alter-ego-by-kyuchumimo.lua

+ 78 - 25
alter-ego-by-kyuchumimo.lua

@@ -60,7 +60,7 @@ aey=0
 v=0
 
 options = {
-	music = true,
+	music = false,
 	debug = true,
 }
 
@@ -101,44 +101,100 @@ end
 
 -- PARTICLE/VFX STUFF
 waterlevel = 120 -- y coordinate of the water
-particletype='stars' -- snow|rain|stars
+particletype='rain' -- snow|rain|stars
 particles = {}
 local starcolors = { 1, 2, 13, 15}
-function particleinit()
-    if particletype == 'stars' then
-        for i = 0,15 do
+function particleinit(numparticles)
+    -- if particletype == 'stars' then
+    --     for i = 0, numparticles do
+    --         table.insert(particles, {
+    --             x = math.random() * 240,
+    --             y = math.random() * waterlevel,
+    --             twinkle = math.random() > 0.49, -- randomly pick true/false
+	-- 			lastx = 0,
+	-- 			lasty = 0,
+    --             color = starcolors[math.random(#starcolors)],
+	-- 			t = 0,
+    --         })
+	-- 	end
+	-- 	trace("created some stars")
+	-- end
+	if particletype == 'rain' or particletype == 'snow' then
+		for i = 0, numparticles do
+			color = 2
+			if particletype == 'snow' then color=15 end
             table.insert(particles, {
                 x = math.random() * 240,
-                y = math.random() * waterlevel,
-                twinkle = math.random() > 0.49, -- randomly pick true/false
-                color = starcolors[math.random(#starcolors)],
+				y = math.random() * waterlevel,
+				last_x = math.random() * 0,
+				last_y = math.random() * 0,
+                color = 2,
                 t = 0,
-            })
+			})
         end
-    end
+		trace("created some " .. particletype)
+	end
 end
 
+function dump(o)
+	if type(o) == 'table' then
+	   local s = '{ '
+	   for k,v in pairs(o) do
+		  if type(k) ~= 'number' then k = '"'..k..'"' end
+		  s = s .. '['..k..'] = ' .. dump(v) .. ','
+	   end
+	   return s .. '} '
+	else
+	   return tostring(o)
+	end
+ end
+ 
 function particleupdate()
-    if particletype == 'stars' then
-        for i = 1,#particles do
-            local p = particles[i]
-            if not p.twinkle then goto continue end
-            ::continue::
-            if t % 15 == 0 and math.random() > 0.1 then
-                p.color = starcolors[math.random(#starcolors)]
-            end
-        end
-    end
+    -- if particletype == 'stars' then
+    --     for i = 1,#particles do
+    --         local p = particles[i]
+    --         if not p.twinkle then goto continueTwinkle end
+    --         ::continueTwinkle::
+    --         if t % 15 == 0 and math.random() > 0.1 then
+    --             p.color = starcolors[math.random(#starcolors)]
+    --         end
+    --     end
+    -- end
+    if particletype == 'rain' then
+		for i = 1,#particles do
+			local p = particles[i]
+			if p.last_y then
+				trace("particle: " .. i .. ", lasty: " .. p.last_y)
+			else
+				trace("particle: " .. i .. ", " .. dump(p))
+			end
+			if p.last_y and p.last_y > 136 then
+				p.y = 0
+				p.last_y = 0
+				p.x = math.random() * 240
+			end
+			p.last_y = y
+			p.lastx = x
+			p.y = p.y + 2
+		end
+	end
 end
 
 function particledraw()
+	if (particletype == 'rain') then
+		for i = 1,#particles do
+			local p = particles[i]
+			line(p.x, p.y, p.lastx, p.lasty, color)
+		end
+		return
+	end
     for i = 1,#particles do
         local p = particles[i]
         pix(p.x, p.y, p.color)
     end
 end
 
-particleinit()
+particleinit(150)
 
 --(shx: Xpos, shy: Ypos, shf: flip, sht: timer) CHECK THIS
 function skullh(shx,shy,shf,sht)
@@ -167,13 +223,10 @@ function skullh(shx,shy,shf,sht)
 	--print(shx*8,22,24)
 	--print((shy*8)+8,22,30)
 
-end	
+end
 	
 --LEVEL PROPERTIES (ANIMX/Y LIMITS(1-28,1-14))
 function level(m)
-	
-	sync(0,0,false)
-
 	c=0
 	f=0
 	px=nil