فهرست منبع

Update addamsfamily.c

Rudy Boudewijn van Etten 5 سال پیش
والد
کامیت
062abdf491
1فایلهای تغییر یافته به همراه136 افزوده شده و 27 حذف شده
  1. 136 27
      games/addamsfamily.c

+ 136 - 27
games/addamsfamily.c

@@ -2,7 +2,11 @@
 #include "raylib.h"
 #include <math.h>
 
-static int map[270][15];
+static int map[300][300];
+
+static const int screenWidth = 640;
+static const int screenHeight = 480;
+
 
 typedef struct game{
     RenderTexture2D back;
@@ -59,13 +63,14 @@ static void playercontrols(void);
 static bool playerright(void);
 static bool playerleft(void);
 static bool playerduck(void);
-    
+static void playerslide(void);
+static void mapscroll(void);
+static void scrolllevel(int num);
+
 int main(void)
 {
     // Initialization
     //--------------------------------------------------------------------------------------
-    const int screenWidth = 640;
-    const int screenHeight = 480;
 
     InitWindow(screenWidth, screenHeight, "raylib example.");
  
@@ -73,7 +78,7 @@ int main(void)
     g.back = LoadRenderTexture(640,480);    
 
     inigame();
- 
+
     SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
     //--------------------------------------------------------------------------------------
 
@@ -85,6 +90,8 @@ int main(void)
             
         gravity();
         playercontrols();
+        playerslide();
+        mapscroll();
         //----------------------------------------------------------------------------------
         // Draw
         //----------------------------------------------------------------------------------
@@ -92,15 +99,16 @@ int main(void)
 
             ClearBackground(BLACK);
                 
-       //     BeginTextureMode(g.back);
-       //     ClearBackground(BLACK);
+            BeginTextureMode(g.back);
+            ClearBackground(BLACK);
             drawlevel();
             drawplayer();
-       //     EndTextureMode();
+            EndTextureMode();
             //DrawTextureEx(g.back.texture,-32,0,WHITE);
-       //     DrawTextureRec(g.back.texture, (Rectangle){ 0, 0, g.back.texture.width, -g.back.texture.height }, (Vector2){ 0, 0 }, WHITE);
+            DrawTextureRec(g.back.texture, (Rectangle){ 0, 0, g.back.texture.width, -g.back.texture.height }, (Vector2){ -32, 0 }, WHITE);
             
             //if(rectmapcollision(GetMouseX(),GetMouseY(),32,32,0,0)){
+            //DrawText(FormatText("%i",g.cx),100,0,20,RED);
             if(pmcollision(0,0)){
                 DrawText("ewkfh",0,0,20,RED);
                 
@@ -138,6 +146,22 @@ void readlevel(int level){
     {0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0 },
     {0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,3,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5,1,1,1,1,1,1,1,0,0,0,0 },
     {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }};
+   int level1subb[15][70] = {
+    {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1},
+    {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1},
+    {0,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,0,0,0,0,1},
+    {0,1,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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1,1,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,0,0,0,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,2,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,1,1,1,1,0,0,0,1},
-    {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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1},
-    {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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1},
-    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5,1,1,1,1,1,5,5,5,5,1,1,1,1,1,1,1,1,1,1,1,1,1,6,6,6,1},
-    {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
+ 
 
 	//Restore level1subb
 	for(int y=0; y<15 ; y++){
@@ -192,8 +201,9 @@ void readlevel(int level){
 		int a = level1subb[y][x];
 		switch (a){
             case 1:
-            break;
+            
             map[x1][y1] = a;
+            break;
             case 2: //; ai - shooter
             //iniai(x1*32,y1*32-(48-32),0)
             break;
@@ -211,12 +221,13 @@ void readlevel(int level){
             break;
         }
     }}
+
 }
 
 void drawlevel(){
     int x1;
     int y1;
-	for (int y=0;y<14;y++){
+	for (int y=0;y<15;y++){
 	for (int x=0;x<20;x++){
 		if(RectsOverlap((g.cx)+x,(g.cy)+y,1,1,0,0,160,15)){
             switch (map[x+g.cx][y+g.cy]){
@@ -416,3 +427,101 @@ bool playerduck(){
 	if(IsKeyDown(KEY_DOWN))return true;
     return false;
 }
+
+void playerslide(){
+	if(p.slide){
+        //;	p\state = 0
+        if(p.jump){
+            p.slide = false; 
+            return;
+        }
+        if(p.fall){
+            p.slide = false;
+            return;
+        }
+        switch (p.direction){
+            case 0:
+                if(playerright()==false){
+                    if(pmcollision(p.slidespeed,0)== false){
+                        p.x = p.x + p.slidespeed;
+                        p.slidespeed = p.slidespeed - .1;
+                    }else{
+                        p.x = p.x/32*32;
+                        p.slide = false;
+                        p.slidespeed = 0;
+                    }
+                }
+            break;
+            case 1:
+                if(playerleft() == false){
+                    if(pmcollision(-p.slidespeed,0) == false){
+                        p.x = p.x - p.slidespeed; 
+                        p.slidespeed = p.slidespeed - .1;
+                        }else{
+                        p.x = p.x/32*32;
+                        p.slide = false;
+                        p.slidespeed = 0;
+                    }
+                }
+            break;
+        }
+    }   
+	if(p.slidespeed < 0)p.slide = false;
+}
+
+void mapscroll(){
+	int x = p.x - maprealx();
+	//;
+	if(playerright() == false && playerleft() == false){
+        if(p.slide){
+            switch (p.direction){
+                case 0:
+                for(int i=0;i<p.slidespeed-1;i++){
+                    scrolllevel(0);
+                }
+                break;
+                case 1:
+                for(int i=0;i<p.slidespeed-1;i++){
+                    scrolllevel(1);
+                }
+                break;
+            }
+        }
+    }	;
+	if(x+40> screenWidth / 2 && playerright()){
+		if(g.cx < 70*2-20){
+		scrolllevel(0);
+        scrolllevel(0);
+        scrolllevel(0);
+        scrolllevel(0);
+        }
+    }
+	if(x-40< screenWidth / 2 && playerleft()){
+		if(g.cx > 0){
+			scrolllevel(1);
+            scrolllevel(1);
+            scrolllevel(1);
+            scrolllevel(1);
+        }
+    }
+}
+
+
+void scrolllevel(int num){
+	switch (num){
+		case 0:// ; right
+		g.offx = g.offx - 1;
+		if(g.offx < 0){
+            g.offx = 31;
+            g.cx = g.cx + 1;
+        }
+        break;
+		case 1:	
+		g.offx = g.offx + 1;
+		if(g.offx > 31){
+            g.offx = 0;
+            g.cx = g.cx - 1;
+        }
+        break;
+    }
+}