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

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.exe
.vscode/*

View File

@@ -183,6 +183,7 @@ byte llig(word x, word y) {
case 6: return (virt[y*80+(x>>3)] & 0x02) >> 1; break; case 6: return (virt[y*80+(x>>3)] & 0x02) >> 1; break;
case 7: return virt[y*80+(x>>3)] & 0x01; break; case 7: return virt[y*80+(x>>3)] & 0x01; break;
} }
return 0;
} }
void posavga(word x, word y, byte color) { void posavga(word x, word y, byte color) {
@@ -256,7 +257,7 @@ boolean linea(word x1, word y1, word x2, word y2, word color) {
integer xs = x2-x1, ys = y2-y1; integer xs = x2-x1, ys = y2-y1;
integer xm = sign(xs), ym = sign(ys); integer xm = sign(xs), ym = sign(ys);
integer xs = fabs(xs), ys = fabs(ys); xs = fabs(xs); ys = fabs(ys);
if (llig(x,y)==1) col++; if (llig(x,y)==1) col++;
posa(x,y,color); posa(x,y,color);
@@ -317,18 +318,23 @@ void rota_pol(poligon pol, real angul, byte color) {
void mou_orni(poligon &orni) { void mou_orni(poligon &orni) {
orni.angle = orni.angle/*+(random(256)/512)*(random(3)-1)*/; orni.angle = orni.angle/*+(random(256)/512)*(random(3)-1)*/;
real dy = round(orni.velocitat*sin(orni.angle-pi/2))+orni.centre.y; real dy = round(orni.velocitat*sin(orni.angle-pi/2.0))+orni.centre.y;
real dx = round(orni.velocitat*cos(orni.angle-pi/2))+orni.centre.x; real dx = round(orni.velocitat*cos(orni.angle-pi/2.0))+orni.centre.x;
if ((dy>marge_dalt) && (dy<marge_baix)) { if ((dy>marge_dalt) && (dy<marge_baix)) {
orni.centre.y = round(dy); orni.centre.y = round(dy);
} else { } else {
orni.angle = orni.angle+(random(256)/512)*(random(3)-1); // NOTA3: No he pogut reproduir el moviment dels ORNIs amb el codi que hi havia en l'original. Si el fique talqual no va be.
// (els ORNIs se queden atascats a les vores). El codi original es la linea comentada despres de la actual. Seguiré investigant...
orni.angle = orni.angle+(pi*(random(200)/100));
//orni.angle = orni.angle+(random(256)/512)*(random(3)-1);
} }
if ((dx>marge_esq) && (dx<marge_dret)) { if ((dx>marge_esq) && (dx<marge_dret)) {
orni.centre.x = round(dx); orni.centre.x = round(dx);
} else { } else {
orni.angle = orni.angle+(random(256)/512)*(random(3)-1); // vore NOTA3
orni.angle = orni.angle+(pi*(random(200)/100));
//orni.angle = orni.angle+(random(256)/512)*(random(3)-1);
} }
orni.rotacio = orni.rotacio+orni.drotacio; orni.rotacio = orni.rotacio+orni.drotacio;
} }
@@ -395,7 +401,7 @@ void tocado() {
if (itocado>250) itocado=0; if (itocado>250) itocado=0;
} }
int main(int argc, char argv[]) { int main(int argc, char *argv[]) {
randomize(); randomize();
//getmem(virt,38400); virt es un array estatic, no fa falta reservar memòria //getmem(virt,38400); virt es un array estatic, no fa falta reservar memòria
itocado = 0; itocado = 0;
@@ -413,22 +419,22 @@ int main(int argc, char argv[]) {
do { do {
clsvirt(); clsvirt();
if (teclapuls(KEYarrowright)) nau.angle += 0.157079632; if (teclapuls(keyArrowRight)) nau.angle += 0.157079632;
if (teclapuls(KEYarrowleft)) nau.angle -= 0.157079632; if (teclapuls(keyArrowLeft)) nau.angle -= 0.157079632;
if (teclapuls(KEYarrowup)) { if (teclapuls(keyArrowUp)) {
if (nau.velocitat<velocitat_max) nau.velocitat += 0.2; if (nau.velocitat<velocitat_max) nau.velocitat += 0.2;
} }
if (teclapuls(KEYspace) && (!bales[1].esta)) { if (teclapuls(keySpace) && (!bales[1].esta)) {
bales[1].esta = true; bales[1].esta = true;
bales[1].centre.x = nau.centre.x; bales[1].centre.x = nau.centre.x;
bales[1].centre.y = nau.centre.y; bales[1].centre.y = nau.centre.y;
bales[1].n = 2; bales[1].n = 2;
bales[1].velocitat = 7; bales[1].velocitat = 7;
bales[1].ipuntx[1].r = 10; bales[1].ipuntx[1].r = 10;
bales[1].ipuntx[1].angle = pi/2+nau.angle; bales[1].ipuntx[1].angle = pi/2+nau.angle;
bales[1].ipuntx[2].r = 20; bales[1].ipuntx[2].r = 20;
bales[1].ipuntx[2].angle = pi/2+nau.angle; bales[1].ipuntx[2].angle = pi/2+nau.angle;
bales[1].angle = nau.angle; bales[1].angle = nau.angle;
} }
word dy = round(nau.velocitat*sin(nau.angle-pi/2))+nau.centre.y; word dy = round(nau.velocitat*sin(nau.angle-pi/2))+nau.centre.y;
word dx = round(nau.velocitat*cos(nau.angle-pi/2))+nau.centre.x; word dx = round(nau.velocitat*cos(nau.angle-pi/2))+nau.centre.x;
@@ -461,14 +467,16 @@ int main(int argc, char argv[]) {
mou_bales(bales[1]); mou_bales(bales[1]);
rota_pol(bales[1],0,1); rota_pol(bales[1],0,1);
} }
waitretrace(); // fiquem "volca" i "waitretrace" al reves, ja que waitretrace fa tota la faena de enviar-ho a sdl
volca(); volca();
waitretrace();
/* if aux=1 then begin {gotoxy(0,0);write('tocado')tocado;delay(200);end;*/ /* if aux=1 then begin {gotoxy(0,0);write('tocado')tocado;delay(200);end;*/
gotoxy(50,24); gotoxy(50,24);
write("¸ Visente i Sergi"); write("¸ Visente i Sergi");
gotoxy(50,25); gotoxy(50,25);
write("áETA 2.2 2/6/99"); write("áETA 2.2 2/6/99");
} while (!teclapuls(keyesc)); } while (!teclapuls(keyEsc) && !shouldexit() ); // afegim el shouldexit, ja que si tanquen la finestra, deuriem eixir
desinstalarkb(); desinstalarkb();
ang = 0; ang = 0;
do { do {
@@ -476,7 +484,7 @@ int main(int argc, char argv[]) {
rota_pol(pol,ang,0); rota_pol(pol,ang,0);
ang += 0.031415; ang += 0.031415;
rota_pol(pol,ang,1); rota_pol(pol,ang,1);
} while (!keypressed()); } while (!keypressed() && !shouldexit() );
text(); text();
return 0; return 0;
} }

43
crt.h
View File

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

View File

@@ -24,105 +24,105 @@ interface
#define keySysReq SDL_SCANCODE_SYSREQ #define keySysReq SDL_SCANCODE_SYSREQ
#define keyCapsLock SDL_SCANCODE_CAPSLOCK #define keyCapsLock SDL_SCANCODE_CAPSLOCK
#define keyNumLock 0x45 #define keyNumLock SDL_SCANCODE_NUMLOCKCLEAR
#define keyScrollLock 0x46 #define keyScrollLock SDL_SCANCODE_SCROLLLOCK
#define keyLeftCtrl 0x1D #define keyLeftCtrl SDL_SCANCODE_LCTRL
#define keyLeftAlt 0x38 #define keyLeftAlt SDL_SCANCODE_LALT
#define keyLeftShift 0x2A #define keyLeftShift SDL_SCANCODE_LSHIFT
#define keyRightCtrl 0x9D #define keyRightCtrl SDL_SCANCODE_RCTRL
#define keyAltGr 0xB8 #define keyAltGr SDL_SCANCODE_RALT
#define keyRightShift 0x36 #define keyRightShift SDL_SCANCODE_RSHIFT
#define keyEsc 0x01 #define keyEsc SDL_SCANCODE_ESCAPE
#define keyBackspace 0x0E #define keyBackspace SDL_SCANCODE_BACKSPACE
#define keyEnter 0x1C #define keyEnter SDL_SCANCODE_RETURN
#define keySpace 0x39 #define keySpace SDL_SCANCODE_SPACE
#define keyTab 0x0F #define keyTab SDL_SCANCODE_TAB
#define keyF1 0x3B #define keyF1 SDL_SCANCODE_F1
#define keyF2 0x3C #define keyF2 SDL_SCANCODE_F2
#define keyF3 0x3D #define keyF3 SDL_SCANCODE_F3
#define keyF4 0x3E #define keyF4 SDL_SCANCODE_F4
#define keyF5 0x3F #define keyF5 SDL_SCANCODE_F5
#define keyF6 0x40 #define keyF6 SDL_SCANCODE_F6
#define keyF7 0x41 #define keyF7 SDL_SCANCODE_F7
#define keyF8 0x42 #define keyF8 SDL_SCANCODE_F8
#define keyF9 0x43 #define keyF9 SDL_SCANCODE_F9
#define keyF10 0x44 #define keyF10 SDL_SCANCODE_F10
#define keyF11 0x57 #define keyF11 SDL_SCANCODE_F11
#define keyF12 0x58 #define keyF12 SDL_SCANCODE_F12
#define keyA 0x1E #define keyA SDL_SCANCODE_A
#define keyB 0x30 #define keyB SDL_SCANCODE_B
#define keyC 0x2E #define keyC SDL_SCANCODE_C
#define keyD 0x20 #define keyD SDL_SCANCODE_D
#define keyE 0x12 #define keyE SDL_SCANCODE_E
#define keyF 0x21 #define keyF SDL_SCANCODE_F
#define keyG 0x22 #define keyG SDL_SCANCODE_G
#define keyH 0x23 #define keyH SDL_SCANCODE_H
#define keyI 0x17 #define keyI SDL_SCANCODE_I
#define keyJ 0x24 #define keyJ SDL_SCANCODE_J
#define keyK 0x25 #define keyK SDL_SCANCODE_K
#define keyL 0x26 #define keyL SDL_SCANCODE_L
#define keyM 0x32 #define keyM SDL_SCANCODE_M
#define keyN 0x31 #define keyN SDL_SCANCODE_N
#define keyO 0x18 #define keyO SDL_SCANCODE_O
#define keyP 0x19 #define keyP SDL_SCANCODE_P
#define keyQ 0x10 #define keyQ SDL_SCANCODE_Q
#define keyR 0x13 #define keyR SDL_SCANCODE_R
#define keyS 0x1F #define keyS SDL_SCANCODE_S
#define keyT 0x14 #define keyT SDL_SCANCODE_T
#define keyU 0x16 #define keyU SDL_SCANCODE_U
#define keyV 0x2F #define keyV SDL_SCANCODE_V
#define keyW 0x11 #define keyW SDL_SCANCODE_W
#define keyX 0x2D #define keyX SDL_SCANCODE_X
#define keyY 0x15 #define keyY SDL_SCANCODE_Y
#define keyZ 0x2C #define keyZ SDL_SCANCODE_Z
#define key1 0x02 #define key1 SDL_SCANCODE_1
#define key2 0x03 #define key2 SDL_SCANCODE_2
#define key3 0x04 #define key3 SDL_SCANCODE_3
#define key4 0x05 #define key4 SDL_SCANCODE_4
#define key5 0x06 #define key5 SDL_SCANCODE_5
#define key6 0x07 #define key6 SDL_SCANCODE_6
#define key7 0x08 #define key7 SDL_SCANCODE_7
#define key8 0x09 #define key8 SDL_SCANCODE_8
#define key9 0x0A #define key9 SDL_SCANCODE_9
#define key0 0x0B #define key0 SDL_SCANCODE_0
#define keyMinus 0x0C #define keyMinus SDL_SCANCODE_MINUS
#define keyEqual 0x0D #define keyEqual SDL_SCANCODE_EQUALS
#define keyLBracket 0x1A #define keyLBracket SDL_SCANCODE_LEFTBRACKET
#define keyRBracket 0x1B #define keyRBracket SDL_SCANCODE_RIGHTBRACKET
#define keySemicolon 0x27 #define keySemicolon SDL_SCANCODE_SEMICOLON
#define keyTick 0x28 #define keyTick SDL_SCANCODE_GRAVE
#define keyApostrophe 0x29 #define keyApostrophe SDL_SCANCODE_APOSTROPHE
#define keyBackslash 0x2B #define keyBackslash SDL_SCANCODE_BACKSLASH
#define keyComma 0x33 #define keyComma SDL_SCANCODE_COMMA
#define keyPeriod 0x34 #define keyPeriod SDL_SCANCODE_PERIOD
#define keySlash 0x35 #define keySlash SDL_SCANCODE_SLASH
#define keyInsert 0xD2 #define keyInsert SDL_SCANCODE_INSERT
#define keyDelete 0xD3 #define keyDelete SDL_SCANCODE_DELETE
#define keyHome 0xC7 #define keyHome SDL_SCANCODE_HOME
#define keyEnd 0xCF #define keyEnd SDL_SCANCODE_END
#define keyPageUp 0xC9 #define keyPageUp SDL_SCANCODE_PAGEUP
#define keyArrowLeft 0xCB #define keyArrowLeft SDL_SCANCODE_LEFT
#define keyArrowRight 0xCD #define keyArrowRight SDL_SCANCODE_RIGHT
#define keyArrowUp 0xC8 #define keyArrowUp SDL_SCANCODE_UP
#define keyArrowDown 0xD0 #define keyArrowDown SDL_SCANCODE_DOWN
#define keyKeypad0 0x52 #define keyKeypad0 SDL_SCANCODE_KP_0
#define keyKeypad1 0x4F #define keyKeypad1 SDL_SCANCODE_KP_1
#define keyKeypad2 0x50 #define keyKeypad2 SDL_SCANCODE_KP_2
#define keyKeypad3 0x51 #define keyKeypad3 SDL_SCANCODE_KP_3
#define keyKeypad4 0x4B #define keyKeypad4 SDL_SCANCODE_KP_4
#define keyKeypad5 0x4C #define keyKeypad5 SDL_SCANCODE_KP_5
#define keyKeypad6 0x4D #define keyKeypad6 SDL_SCANCODE_KP_6
#define keyKeypad7 0x47 #define keyKeypad7 SDL_SCANCODE_KP_7
#define keyKeypad8 0x48 #define keyKeypad8 SDL_SCANCODE_KP_8
#define keyKeypad9 0x49 #define keyKeypad9 SDL_SCANCODE_KP_9
#define keyKeypadComma 0x53 #define keyKeypadComma SDL_SCANCODE_KP_COMMA
#define keyKeypadStar 0x37 #define keyKeypadStar SDL_SCANCODE_KP_MULTIPLY
#define keyKeypadMinus 0x4A #define keyKeypadMinus SDL_SCANCODE_KP_MINUS
#define keyKeypadPlus 0x4E #define keyKeypadPlus SDL_SCANCODE_KP_PLUS
#define keyKeypadEnter 0x9C #define keyKeypadEnter SDL_SCANCODE_KP_ENTER
#define keyCtrlPrtScr 0xB7 #define keyCtrlPrtScr SDL_SCANCODE_PRINTSCREEN
#define keyShiftPrtScr 0xB7 #define keyShiftPrtScr SDL_SCANCODE_PAUSE
#define keyKeypadSlash 0xB5 #define keyKeypadSlash SDL_SCANCODE_KP_DIVIDE
const char *keyNames[256] { const char *keyNames[256] {
/* $00 */ NULL, "Esc", "1", "2", "3", "4", "5", "6", /* $00 */ NULL, "Esc", "1", "2", "3", "4", "5", "6",
@@ -150,7 +150,7 @@ const char *keyNames[256] {
/* $F0 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* $F0 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
}; };
/*
procedure InstalarKb; procedure InstalarKb;
procedure DesinstalarKb; procedure DesinstalarKb;
function TeclaPuls( b : byte ) : Boolean; function TeclaPuls( b : byte ) : Boolean;
@@ -198,81 +198,29 @@ asm
sti sti
end; end;
{$F-} {$F-}
*/
const Uint8 *uKeys;
void instalarkb() {
uKeys = SDL_GetKeyboardState(NULL);
}
void desinstalarkb() {
// Res que vore ací, dispersensé...
}
procedure InstalarKb; bool teclapuls( unsigned char b ) {
begin return uKeys[b] == 1;
GetIntVec( $09, uOldInt9); { save old location of INT 09 handler } }
SetIntVec( $09, Addr( NewInt9)); { point to new routine }
FillChar( uKeys, SizeOf( uKeys), 0); { clear the keys array }
end;
bool keypressed() {
for (int i=0;i<256;++i) if (uKeys[i]==1) return true;
return false;
}
procedure DesinstalarKb; unsigned char agarrartecla() {
begin for (int i=0;i<256;++i) if (uKeys[i]==1) return i;
SetIntVec( $09, uOldInt9); { point back to original routine } return 0;
uOldInt9 := nil; }
end;
function TeclaPuls( b : byte ) : Boolean;
begin
TeclaPuls := uKeys[b];
end;
function QTeclaPuls : Boolean;
var b : Integer;
begin
QTeclaPuls := True;
for b := 0 to 255 do
if uKeys[b] and (keyNames[b] <> nil) then
Exit;
QTeclaPuls := False;
end;
function AgarrarTecla : Byte;
var b : Integer;
begin
AgarrarTecla := 0;
for b := 1 to 255 do
if uKeys[b] and (keyNames[b] <> nil) then
begin
AgarrarTecla := b;
Exit;
end;
end;
procedure BorrarKb;
begin
FillChar( uKeys, SizeOf( uKeys), 0); { clear the keys array }
end;
{$F+}
procedure CleanUp;
begin
ExitProc := uExitProc;
if uOldInt9 <> nil then
DesinstalarKb;
end;
procedure EscriuKb;
var b:byte;
begin
for b := 0 to 255 do
if uKeys[b] and (keyNames[b] <> nil) then
write(keyNames[b],' | ');
writeln;
end;
{$F-}
begin
uExitProc := ExitProc;
ExitProc := @CleanUp;
uOldInt9 := nil;
end.