VPN termux about China.net

Xand0 part.2 problem switch two players

/*now I am really all moist to close this game but I can't switch two players to finish this game. I must think it */
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <EGL/egl.h>
#include <GLES/gl.h>
#define WIDTH 800
#define HEIGHT 600
/* path to jpeg fille */
#define IMG_PATH "img2.jpg"
/*maybe beeter i use maping*/
int i,j;
char *ff[3][3] = {"a","a","a",
"a","a","a",
"a","a","a",};
static int SHAPE_SIZE = 1;
// sprite in picture
SDL_Rect SrcR,darea;
// sprite in progra
SDL_Rect DestR;
SDL_Renderer *renderer = NULL;
SDL_Texture *img = NULL;

int x,y;
SDL_Rect enemy = { x, y, 100, 100 };
SDL_Rect mouse = { 400, 600, 5, 5 };

/* colision two rect */
bool CheckCollision(SDL_Rect r1, SDL_Rect * r2)
{
if (r2->x > r1.x + r1.w)
{
return false;
}
else if (r2->y > r1.y + r1.h)
{
return false;
}
else if (r2->x + r2->w < r1.x)
{
return false;
}
else if (r2->y + r2->h < r1.y)
{
return false;
}
else
{
return true;
}
}

bool playerOne = true;
bool playerTwo = false;
bool cpu = false;
// load JPEG
int JPEG()
{
img = IMG_LoadTexture(renderer, IMG_PATH);
SDL_SetRenderTarget(renderer, img);
}


bool nr(int i)                                                               //deklaracja funkcji typu prawda/falsz
{                                                                       //sluzy do sprawdzania ktorego gracza tura
    return i%2;                                                         //i%2 czyli sprawdza ten warunek
}                                                                       //i odpowiednio zwraca prawde albo falsz
 


// mouse
void mouseKontrol(SDL_Renderer * renderer)
{ /* draw kursor mouse */
SDL_SetRenderDrawColor(renderer, 255, 255, 0, SDL_ALPHA_OPAQUE);
SDL_RenderFillRect(renderer, &mouse);
}
void Mapa(SDL_Renderer * render)
{
int i, j, lx = 0, ly = 0, ch;
static int player;


// SDL_RenderGetViewport(renderer, &darea);
SDL_Rect egl;
/* i need two rect one statistic in postion 0 0 and sec. rect to draw
  enemy */
SDL_Rect enemy;
/* rect egl is LEVER to draw enemy */
egl.x = 0;
egl.y = 0;
egl.w = 99;
egl.h = 99;
/* rect enemy */

enemy.x = lx;

enemy.y = ly;

enemy.w = 99;

enemy.h = 98;

/* form the word BRICKS */

// SDL_RenderFillRect(renderer, &enemy);

/* draw chessboard */
bool gracz;
 static int a=1;
a+;
for (i = 0; i < 3;i++)
{
for (j = 0; j < 3; j++)
{
/* if ff =1 then draw rect enemy */
if (ff[i][j] == "a")
{
 SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE);
enemy.x = egl.x + j * 100 + 1;
enemy.y = egl.y + i * 100 + 1;
SDL_RenderFillRect(renderer, &enemy);

}
if (ff[i][j] == "b")

{
enemy.x = egl.x + j * 100 + 1;
enemy.y = egl.y + i * 100 + 1;
SDL_SetRenderDrawColor(renderer, 255, 255, 0, SDL_ALPHA_OPAQUE);
SDL_RenderFillRect(renderer, &enemy);
}
if (ff[i][j] == "c")

{
enemy.x = egl.x + j * 100 + 1;
enemy.y = egl.y + i * 100 + 1;
SDL_SetRenderDrawColor(renderer, 25, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderFillRect(renderer, &enemy);
}

/* if colision don't draw enemy rect */
if (CheckCollision(mouse, &enemy))
{

bool gracz =nr(a);            
    if (!gracz) {
    ff[i][j] = "c";
 
    }
else
ff[i][j] = "b";

// player=2;

}
}
}
}





int main(int argc, char *argv[])
{
// variable declarations
SDL_Window *win = NULL;
int w, h; // texture width & height
Uint32 *pixelFormat;
// Initialize SDL.
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return 1;
// create the window and renderer
// note that the renderer is accelerated
win = SDL_CreateWindow("Image Loading", 100, 100, WIDTH, HEIGHT, SDL_WINDOW_OPENGL);
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
JPEG();

// main loop
while (1)
{
// event handling
SDL_Event e;
if (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT)
break;
else if (e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_ESCAPE)
break;
if (e.type == SDL_MOUSEMOTION)
{
mouse.x = e.motion.x;
mouse.y = e.motion.y;
}
}
// clear the screen
SDL_RenderClear(renderer);
// kolor of rect
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0xFF);
// render img
SDL_RenderCopy(renderer, img, NULL, NULL);
// /draw rect game
Mapa(renderer);
// drawMap(renderer) ;
//
mouseKontrol(renderer);
SDL_RenderPresent(renderer);
SDL_GL_SwapWindow(win);
/* game color */
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 0xFF);

}
SDL_DestroyTexture(img);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(win);
return 0;
}

No comments:

Post a Comment