Joc funcional, rebot dels ORNIs no original

This commit is contained in:
2022-08-14 16:55:10 +02:00
parent 3f53e503af
commit ca8a8fb9a1
4 changed files with 179 additions and 218 deletions

43
crt.h
View File

@@ -12,28 +12,29 @@ typedef unsigned char byte;
typedef bool boolean;
typedef uint16_t word;
byte video[38400];
byte video[38400];
SDL_Window *sdlWindow;
SDL_Renderer *sdlRenderer;
SDL_Texture *sdlTexture;
SDL_Event sdlEvent;
SDL_Window *sdlWindow;
SDL_Renderer *sdlRenderer;
SDL_Texture *sdlTexture;
SDL_Event sdlEvent;
Uint32 *pixels;
int pitch;
Uint32 *pixels;
int pitch;
bool eixir = false;
void randomize() {
srand(SDL_GetTicks());
}
int random(int x) {
return rand()%x;
float random(int x) {
return float(rand() % x);
}
void mcga() {
SDL_Init(SDL_INIT_EVERYTHING);
sdlWindow = SDL_CreateWindow("Asteroids", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, 0);
sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_PRESENTVSYNC);
sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, 640, 480);
}
@@ -41,22 +42,24 @@ void text() {
SDL_Quit();
}
bool shouldexit() { return eixir; }
void waitretrace() {
while (!SDL_PollEvent(&sdlEvent)) {
if (sdlEvent.type == SDL_QUIT) { /*Ja vorem*/ }
while (SDL_PollEvent(&sdlEvent)) {
if (sdlEvent.type == SDL_QUIT) { eixir = true; }
}
SDL_LockTexture(sdlTexture, NULL, (void**)&pixels, &pitch);
int pos=0;
for (int y=0; y<480;y++) {
for (int x=0; x<80;x++) {
pixels[pos++] = ((video[y*480+x]>>7)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*480+x]>>6)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*480+x]>>5)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*480+x]>>4)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*480+x]>>3)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*480+x]>>2)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*480+x]>>1)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*480+x] )&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x]>>7)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x]>>6)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x]>>5)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x]>>4)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x]>>3)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x]>>2)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x]>>1)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x] )&1)?0xffffffff:0x000000ff;
}
}
SDL_UnlockTexture(sdlTexture);