comparison lamertetris/sources/shape.C @ 0:2787f5e749ae

INIT
author prymula <prymula76@outlook.com>
date Thu, 21 Sep 2023 22:33:57 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:2787f5e749ae
1 #include "shape.h"
2
3 Shape::Shape() {}
4
5 SDL_Surface * Shape::createBoxMask(int width, int height) {
6
7 /* Create a 32-bit surface with the bytes of each pixel in R,G,B,A order,
8 as expected by OpenGL for textures */
9 SDL_Surface *surface;
10 Uint32 rmask, gmask, bmask, amask;
11 //int width=80;
12 //int height=80;
13
14 /* SDL interprets each pixel as a 32-bit number, so our masks must depend
15 on the endianness (byte order) of the machine */
16 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
17 rmask = 0xff000000;
18 gmask = 0x00ff0000;
19 bmask = 0x0000ff00;
20 amask = 0x000000ff;
21 #else
22 rmask = 0x000000ff;
23 gmask = 0x0000ff00;
24 bmask = 0x00ff0000;
25 amask = 0xff000000;
26 #endif
27
28 surface = SDL_CreateRGBSurface(0, width, height, 32,
29 rmask, gmask, bmask, amask);
30
31 if (surface == NULL) {
32 SDL_Log("SDL_CreateRGBSurface() failed: %s", SDL_GetError());
33 exit(1);
34 }
35
36 /* or using the default masks for the depth: */
37 //surface = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0);
38
39
40 return surface;
41 }
42
43
44 SDL_Surface * Shape::createField(int w,int h, int r, int g, int b){
45
46 SDL_Surface *s;
47 //s=Szlam::createBoxMask(w,h);
48 s=Shape::createBoxMask(w,h);
49 SDL_FillRect(s, NULL, SDL_MapRGB(s->format, r, g, b));
50 return s;
51 }
52
53 void Shape::setColor(int color, int *r, int *g, int*b){
54
55 switch(color){
56 case 0:
57 *r=255, *g=255, *b=255;
58 break;
59 case 1:
60 *r=255, *g=0, *b=0; //czerwony
61 break;
62 case 2:
63 *r=0, *g=255, *b=0; //zielony
64 break;
65 case 3:
66 *r=0, *g=0, *b=255; //niebieski
67 break;
68 case 4:
69 *r=0, *g=255, *b=255; //seledynowy
70 break;
71 case 5:
72 *r=255, *g=255, *b=0; //żółty
73 break;
74 case 6:
75 *r=170, *g=0, *b=255; //fiolet
76 break;
77 case 7:
78 *r=113, *g=255, *b=0; //fiolet
79 break;
80
81 }
82 }