Browse Source

input handling, DAS

pixelbath 2 years ago
parent
commit
89d985ccd6
1 changed files with 79 additions and 9 deletions
  1. 79 9
      blockbattle/blockbattle.lua

+ 79 - 9
blockbattle/blockbattle.lua

@@ -137,7 +137,7 @@ local pieces = {
 
 
 local board = {}
 local board = {}
 
 
-local pieceType = 1
+local pieceType = 3
 local pieceRotation = 1
 local pieceRotation = 1
 local piece_x = 3
 local piece_x = 3
 local piece_y = 0
 local piece_y = 0
@@ -159,29 +159,95 @@ function draw_piece()
                 local blockSize = 8
                 local blockSize = 8
                 local blockDrawSize = blockSize - 1
                 local blockDrawSize = blockSize - 1
                 rect(
                 rect(
-                    (x - 1) * blockSize,
-                    (y - 1) * blockSize,
+                    (piece_x + x - 1) * blockSize,
+                    (piece_y + y - 1) * blockSize,
                     blockDrawSize,
                     blockDrawSize,
                     blockDrawSize,
                     blockDrawSize,
-					4
+					block
                 )
                 )
             end
             end
         end
         end
     end
     end
 end
 end
 
 
+local factor_are = 4 -- piece spawn delay
+local factor_das = 20
+local factor_keyrepeat = 5
+local t_move = 0
+local is_move_pressed = false
+local is_das_triggered = false
+
+function hard_drop()
+end
+function soft_drop()
+    piece_y = piece_y + 1
+end
+function try_move_right()
+    piece_x = piece_x + 1
+end
+function try_move_left()
+    piece_x = piece_x - 1
+end
+
 function handle_input()
 function handle_input()
+    is_move_pressed = false
+    if btn(0) then
+        hard_drop()
+	end
+	if btn(1) then
+        is_move_pressed = true
+        if t_move <= 0 then
+            if not is_das_triggered then
+                t_move = factor_das
+            else
+                t_move = factor_keyrepeat
+            end
+            is_das_triggered = true
+            soft_drop()
+        end
+	end
+	if btn(2) then
+        is_move_pressed = true
+        if t_move <= 0 then
+            if not is_das_triggered then
+                t_move = factor_das
+            else
+                t_move = factor_keyrepeat
+            end
+            is_das_triggered = true
+            try_move_left()
+        end
+	end
+	if btn(3) then
+        is_move_pressed = true
+        if t_move <= 0 then
+            if not is_das_triggered then
+                t_move = factor_das
+            else
+                t_move = factor_keyrepeat
+            end
+            is_das_triggered = true
+            try_move_right()
+        end
+	end
     if btnp(4) then
     if btnp(4) then
+        pieceRotation = pieceRotation - 1
+        if pieceRotation < 1 then
+            pieceRotation = #pieces[pieceType]
+        end
+    end
+    if btnp(5) then
         pieceRotation = pieceRotation + 1
         pieceRotation = pieceRotation + 1
         if pieceRotation > #pieces[pieceType] then
         if pieceRotation > #pieces[pieceType] then
             pieceRotation = 1
             pieceRotation = 1
         end
         end
     end
     end
-    if btnp(5) then
-        pieceRotation = pieceRotation - 1
-        if pieceRotation < 1 then
-            pieceRotation = #pieces[pieceType]
-        end
+
+    if is_move_pressed then
+        t_move = t_move - 1
+    else
+        t_move = -1
+        is_das_triggered = false
     end
     end
 end
 end
 
 
@@ -190,6 +256,10 @@ function TIC()
 
 
 	cls(0)
 	cls(0)
 	draw_piece()
 	draw_piece()
+
+    print("is_move_pressed: " .. tostring(is_move_pressed), 0, 0)
+    print("is_das_triggered: " .. tostring(is_das_triggered), 0, 7)
+    print("t_move: " .. tostring(t_move), 0, 14)
 end
 end
 
 
 -- <PALETTE>
 -- <PALETTE>