]> gitweb.ps.run Git - npengine/blobdiff - src/main.cpp
movement done
[npengine] / src / main.cpp
index 13778d5895f0585b34a66ba7d7e5d5088d11050a..c0272ac72651fee4944ba675bdbc29748be71955 100644 (file)
@@ -16,19 +16,20 @@ const int WIDTH = 43, HEIGHT = 25;
 int x = 0, y = 0;\r
 bool right = true;\r
 \r
+clock_t update_clock = clock();\r
+double update_time = 40;\r
+\r
 bool keys[4] = { false, false, false, false };\r
 bool keys_old[4] = { false, false, false, false };\r
 \r
 int jumping = 0;\r
 \r
 clock_t jump_clock = clock();\r
-double jump_time1 = 0.01;\r
-double jump_time2 = 0.05;\r
+double jump_time1 = 50;\r
+double jump_time2 = 100;\r
 int jump_height = 3;\r
 \r
-DWORD wait_time = 50;\r
-\r
-\r
+DWORD wait_time = 10;\r
 \r
 void press_down(WORD vk) {\r
   INPUT ip;\r
@@ -208,33 +209,20 @@ void print_text(int text_x, int text_y, const char *text, int delay) {
   Sleep(100);\r
 }\r
 \r
-enum GameState {\r
-  GS_START, GS_INTRO1, GS_INTRO2\r
-};\r
+void update_play(bool can_jump = true, int x_min = 0, int x_max = WIDTH - 1) {\r
+  if (get_dur(update_clock) >= update_time) {\r
+    update_clock = clock();\r
 \r
-clock_t update_clock = clock();\r
-double update_time = 30;\r
+    if (keys[0] &&\r
+        x > x_min &&\r
+        get_block(x - 1, y) != 'x')\r
+      move(-1, 0);\r
+    if (keys[1] &&\r
+        x < x_max &&\r
+        get_block(x + 1, y) != 'x')\r
+      move(+1, 0);\r
+  }\r
 \r
-void update_play(bool can_jump = true) {\r
-  if (get_dur(update_clock) >= update_time)\r
-    update_clock = clock();\r
-  else\r
-    return;\r
-\r
-  // bool left = false;\r
-  // bool right = false;\r
-  // bool up = false;\r
-  // bool down = false;\r
-\r
-  if (keys[0] &&\r
-      x > 0 &&\r
-      get_block(x - 1, y) != 'x')\r
-    move(-1, 0);\r
-  if (keys[1] &&\r
-      x < WIDTH - 1 &&\r
-      get_block(x + 1, y) != 'x')\r
-    move(+1, 0);\r
-  // else \r
   if (keys[2] && !keys_old[2] && jumping == 0 && can_jump) {\r
     jumping = 1;\r
     move(0, -1);\r
@@ -256,26 +244,14 @@ void update_play(bool can_jump = true) {
   }\r
   if (!jumping && get_block(x, y + 1) != 'x' && y < HEIGHT - 1)\r
       move(0, +1);\r
-\r
-  char block = get_block(x, y);\r
-  switch (block) {\r
-  case '/':\r
-  case '\\':\r
-    move_to(0, 24);\r
-    break;\r
-  case '?':\r
-    puts("?");\r
-    break;\r
-  case 'O':\r
-    puts("O");\r
-    break;\r
-  }\r
 }\r
 \r
-enum GameState game_state = GS_START;\r
-void update_game() {\r
-  switch (game_state) {\r
-  case GS_START:\r
+int lvl = 0;\r
+\r
+void intro() {\r
+  static int progress = 0;\r
+  switch (progress) {\r
+  case 0:\r
     press(VK_DOWN);\r
     press(VK_RIGHT);\r
     press(VK_RIGHT);\r
@@ -284,21 +260,44 @@ void update_game() {
 \r
     print_text(4, 2, "Move with left/right.", 30);\r
 \r
-    game_state = GS_INTRO1;\r
+    progress++;\r
     break;\r
-  case GS_INTRO1:\r
+  case 1:\r
     update_play(false);\r
     if (x == 5) {\r
       print_text(4, 4, "Jump with up.", 30);\r
-      game_state = GS_INTRO2;\r
+      print_text(4, 6, "Stand on x.", 30);\r
+      progress++;\r
+    }\r
+    break;\r
+  case 2:\r
+    update_play();\r
+    if (x == 8) {\r
+      print_text(4, 8, "Collect ? for ???.", 30);\r
+      progress++;\r
+    }\r
+    break;\r
+  case 3:\r
+    update_play(true, 0, 22);\r
+    if (get_block(x, y) == '?') {\r
+      print_text(4, 10, "Avoid /\\.", 30);\r
+      progress++;\r
     }\r
     break;\r
-  case GS_INTRO2:\r
+  case 4:\r
     update_play();\r
     break;\r
   }\r
 }\r
 \r
+void update_game() {\r
+  switch (lvl) {\r
+  case 0:\r
+    intro();\r
+    break;\r
+  }\r
+}\r
+\r
 /*\r
   Todo:\r
   - Restart\r
@@ -369,7 +368,7 @@ int main(int argc, char **argv) {
     keys_old[2] = keys[2];\r
     keys_old[3] = keys[3];\r
 \r
-    WaitForSingleObject( pi.hProcess, 10);\r
+    WaitForSingleObject( pi.hProcess, wait_time);\r
 \r
     SetWindowPos(hwnd, HWND_TOPMOST, 100, 100, 750, 750, SWP_SHOWWINDOW);\r
   }\r