Преглед на файлове

Create Example_-_Rayio.c

Rudy Boudewijn van Etten преди 5 години
родител
ревизия
a7118bb0d8
променени са 1 файла, в които са добавени 72 реда и са изтрити 0 реда
  1. 72 0
      Example_-_Rayio.c

+ 72 - 0
Example_-_Rayio.c

@@ -0,0 +1,72 @@
+// WIP
+#include "raylib.h"
+
+const TILEWIDTH = 64;
+const TILEHEIGHT = 48;
+
+int main(void)
+{
+    // Initialization
+    //--------------------------------------------------------------------------------------
+    const int screenWidth = 800;
+    const int screenHeight = 450;
+
+    InitWindow(screenWidth, screenHeight, "raylib example.");
+
+    int map[10][40]={   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+                        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+                        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0},
+                        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+                        {0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,0},
+                        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
+                        {1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+                        {1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+                        {1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+                        {1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
+
+    int tilesh = screenWidth/TILEWIDTH;
+    int tilesv = screenHeight/TILEHEIGHT;
+    Vector2 camera;
+    camera.x = 0;
+    camera.y = 0;
+ 
+    SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
+    //--------------------------------------------------------------------------------------
+
+    // Main game loop
+    while (!WindowShouldClose())    // Detect window close button or ESC key
+    {
+        // Update
+        //----------------------------------------------------------------------------------
+        for(int i=0;i<3;i++){
+            if(IsKeyDown(KEY_RIGHT) && camera.x<(40-(tilesh+3))*TILEWIDTH)camera.x++;
+            if(IsKeyDown(KEY_LEFT) && camera.x>0)camera.x--;
+        }
+        //----------------------------------------------------------------------------------
+        // Draw
+        //----------------------------------------------------------------------------------
+        BeginDrawing();
+
+            ClearBackground(RAYWHITE);
+            int tx = camera.x / TILEWIDTH;            
+            int offx = tx * TILEWIDTH - camera.x;
+            for(int y=0;y<tilesv;y++){
+            for(int x=0;x<tilesh+3;x++){
+                if(x+tx<40 && x+tx>0 && map[y][x+tx]==1){
+                    DrawRectangle(x*TILEWIDTH+offx-TILEWIDTH,y*TILEHEIGHT,TILEWIDTH,TILEHEIGHT,GREEN);
+                }
+            }}
+
+        EndDrawing();
+        //----------------------------------------------------------------------------------
+    }
+
+    // De-Initialization
+    //--------------------------------------------------------------------------------------
+    CloseWindow();        // Close window and OpenGL context
+    //--------------------------------------------------------------------------------------
+
+    return 0;
+
+
+}