Browse Source

basic water effect

pixelbath 1 year ago
parent
commit
f1fd705fd8
1 changed files with 16 additions and 14 deletions
  1. 16 14
      einhander/einhander.lua

+ 16 - 14
einhander/einhander.lua

@@ -64,6 +64,10 @@ active_enemies={}
 t=0
 t=0
 math.randomseed(seed)
 math.randomseed(seed)
 
 
+-- create a mapping for darkening palette colors
+-- note: this is for the default sweetie16 palette
+drk={[0]=0,0,1,2,3,6,7,15,0,8,9,10,13,14,15,0}
+
 
 
 function drawParallelogram(x, y, w, h, skewpx, color)
 function drawParallelogram(x, y, w, h, skewpx, color)
     tri(x+skewpx, y, x+w, y+h, x, y+h, color)
     tri(x+skewpx, y, x+w, y+h, x, y+h, color)
@@ -314,19 +318,17 @@ function drawUI()
 end
 end
 
 
 function drawWater(waterHeight)
 function drawWater(waterHeight)
-    -- TODO: ripples, distortion
-    for i=0,waterHeight-1 do
-        local row = (135 - i - waterHeight) * 120
-        local rowDest = (135 + i - waterHeight + 1) * 120
-        memcpy(rowDest, row, 120)
-    end
-end
-
--- shiftValue   1, 0, -1, -2   From brightest to darkest, respectively. 0 is no change
-function filterColor(inputColor, shiftValue)
-    if shiftValue == 0 then return end
-
-
+	tm=time()/200
+	for x=0,239 do
+		for y=waterHeight,135 do
+			-- introduce some wobble
+			ox=x+2*math.sin(tm+y)
+			oy=waterHeight-(y-waterHeight)-1
+			oc=pix(ox,oy)
+			-- darken reflected pixel
+			pix(x,y,drk[oc])
+		end
+	end
 end
 end
 
 
 function drawDebug()
 function drawDebug()
@@ -430,7 +432,7 @@ function TIC()
     cls(0)
     cls(0)
     drawPlayer()
     drawPlayer()
     drawEnemies()
     drawEnemies()
-    -- drawWater(10)
+    drawWater(120)
     drawUI()
     drawUI()
     drawDebug()
     drawDebug()
 end
 end