#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 "img.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 pictureSDL_Rect SrcR, darea;// sprite in prograSDL_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;}}// load JPEGint JPEG(){img = IMG_LoadTexture(renderer, IMG_PATH);SDL_SetRenderTarget(renderer, img);}// mousevoid 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 = 1, j = 1, lx = 0, ly = 0, ch;static int player = false;SDL_Rect egl;/* i need two rect one statistic in postion 0 0 and sec. rect to drawenemy */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;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) && ff[i][j] == "a"){// two player solved;if (player % 2){ff[i][j] = "c";player = !player;}else{ff[i][j] = "b";player = !player;}}}}}int main(int argc, char *argv[]){// variable declarationsSDL_Window *win = NULL;int w, h; // texture width & heightUint32 *pixelFormat;// Initialize SDL.if (SDL_Init(SDL_INIT_VIDEO) < 0)return 1;// create the window and renderer// note that the renderer is acceleratedwin = SDL_CreateWindow("Image Loading", 100, 100, WIDTH, HEIGHT, SDL_WINDOW_OPENGL);renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);JPEG();// main loopwhile (1){// event handlingSDL_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 screenSDL_RenderClear(renderer);// kolor of rectSDL_SetRenderDrawColor(renderer, 255, 255, 255, 0xFF);// render imgSDL_RenderCopy(renderer, img, NULL, NULL);// /draw rect gameMapa(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;}
VPN termux about China.net
XandO part3 two players problem solved
Subscribe to:
Posts (Atom)
No comments:
Post a Comment