This commit is contained in:
2022-11-15 20:03:05 +01:00
parent 32bdc6dcb6
commit a31b069cb0

View File

@@ -37,7 +37,7 @@ bool is_valid_move() {
}
void stack_piece() {
if (piece_pos.y==0) exit(0);
if (piece_pos.y==0) { state=STATE_ENNERYORNEIM; return; };
int x = piece_pos.x+3, y = piece_pos.y+3;
Uint16 piece = tetromino[current_piece].figure;
for (int i=0; i<16; i++) {
@@ -128,7 +128,7 @@ void doGame() {
void doMenu() {
while(SDL_PollEvent(&sdlEvent)) {
if (sdlEvent.type == SDL_QUIT) { should_exit = true; break; }
if (sdlEvent.type == SDL_KEYDOWN) {
if (sdlEvent.type == SDL_KEYDOWN && sdlEvent.key.repeat==0) {
level=score=lines=0;
current_piece = starting[rand()%7];
next_piece = starting[rand()%7];
@@ -162,6 +162,40 @@ void doMenu() {
SDL_RenderPresent(sdlRenderer);
}
char initials[4]={"AAA"};
int pos =0;
void doEnd() {
while(SDL_PollEvent(&sdlEvent)) {
if (sdlEvent.type == SDL_QUIT) { should_exit = true; break; }
if (sdlEvent.type == SDL_KEYDOWN && sdlEvent.key.repeat==0) {
if (sdlEvent.key.keysym.scancode>=SDL_SCANCODE_A && sdlEvent.key.keysym.scancode<=SDL_SCANCODE_0) {
if (sdlEvent.key.keysym.scancode<=SDL_SCANCODE_Z) {
initials[pos] = sdlEvent.key.keysym.scancode+61;
} else if (sdlEvent.key.keysym.scancode<SDL_SCANCODE_0) {
initials[pos] = sdlEvent.key.keysym.scancode+19;
} else {
initials[pos] = '0';
}
pos++; if (pos==3) pos=0;
} else if (sdlEvent.key.keysym.scancode==SDL_SCANCODE_RETURN) {
state=STATE_MENU;
}
}
}
//SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 0, 255);
//SDL_RenderClear(sdlRenderer);
print(90, 100, "GAME OVER", 7);
if (score>0 && (jscore::getNumUsers()<10 || score>jscore::getPoints(jscore::getNumUsers()-1))) {
print(40, 150, "CONGRATULATIONS", 1);
print(40, 180, "ENTER YOU NAME", 2);
print(40, 250, initials, 3);
}
SDL_RenderPresent(sdlRenderer);
}
int main(int argc, char* argv[]) {
srand(time(NULL));
current_piece = starting[rand()%7];
@@ -181,6 +215,7 @@ int main(int argc, char* argv[]) {
doGame();
break;
case STATE_ENNERYORNEIM:
doEnd();
break;
};
}