Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
- // Version 2, December 2004
- //
- // Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
- //
- // Everyone is permitted to copy and distribute verbatim or modified
- // copies of this license document, and changing it is allowed as long
- // as the name is changed.
- //
- // DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
- // TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- //
- // 0. You just DO WHAT THE FUCK YOU WANT TO.
- #include <stdio.h>
- #include <stdlib.h>
- #include <ncurses.h>
- #include <unistd.h>
- #include <time.h>
- #define RED 1
- #define BLUE 2
- #define YELLOW 3
- #define LEFT 260
- #define RIGHT 261
- void sleepMs(int ms) {
- usleep(ms * 1000);
- }
- void readysteadygo() {
- printw(" _____ _ \n| __ |___ ___ _| |_ _ \n| -| -_| .'| . | | |\n|__|__|___|__,|___|_ |\n |___|");
- refresh();
- sleep(1);
- clear();
- printw(" _____ _ _ \n| __| |_ ___ ___ _| |_ _ \n|__ | _| -_| .'| . | | |\n|_____|_| |___|__,|___|_ |\n |___|");
- refresh();
- sleep(1);
- clear();
- printw(" _____ \n| __|___ \n| | | . |\n|_____|___|");
- refresh();
- sleep(1);
- clear();
- }
- void tryagain(int score, int current_game) {
- int i;
- attron(A_BOLD);
- mvprintw(16, 0, "You crashed :)\nScore : %d", score);
- refresh();
- attroff(A_BOLD);
- sleep(1);
- if (current_game == 42)
- mvprintw(18, 0, "You played 42 times ! You geek.");
- else
- mvprintw(18, 0, "Game restarts in 5 seconds...");
- refresh();
- while (getch() != ERR);
- nodelay(stdscr, FALSE);
- timeout(5000);
- getch();
- nodelay(stdscr, TRUE);
- }
- void game() {
- int i, j, current_game;
- for (current_game = 1 ; current_game <= 42 ; current_game++)
- {
- int player_x = 9, police_alive[3] = {TRUE, TRUE, TRUE}, left_border[15] = {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, range = 9, delay = 250, key, random, score = 0;
- int collision = FALSE;
- while (collision == FALSE)
- {
- if (player_x <= left_border[7] || player_x >= left_border[7] + range + 1)
- collision = TRUE;
- else
- {
- clear();
- for (i = 14 ; i > 0 ; i--)
- left_border[i] = left_border[i - 1];
- random = rand() % 3 - 1;
- left_border[0] += random;
- if (left_border[0] < 0)
- left_border[0] = 0;
- else if (left_border[0] > 10)
- left_border[0] = 10;
- for (i = 0 ; i < 15 ; i++)
- {
- for (j = 0 ; j < left_border[i] ; j++)
- printw(" ");
- attron(COLOR_PAIR(3));
- printw("^");
- for (j = 0 ; j < range ; j++)
- printw(" ");
- printw("^\n");
- attroff(COLOR_PAIR(YELLOW));
- }
- attron(COLOR_PAIR(BLUE));
- attron(A_BOLD);
- for (i = 0 ; i < 3 ; i++)
- {
- if (police_alive[i] == TRUE)
- {
- random = rand() % 3 - 1;
- mvprintw(i + 9, player_x + random, "@");
- refresh();
- if (player_x + random <= left_border[7] || player_x + random >= left_border[7] + range + 1)
- police_alive[i] = FALSE;
- }
- }
- attroff(COLOR_PAIR(BLUE));
- key = getch();
- switch (key)
- {
- case RIGHT:
- player_x++;
- break;
- case LEFT:
- player_x--;
- break;
- }
- attron(COLOR_PAIR(RED));
- mvprintw(7, player_x, "$");
- attroff(COLOR_PAIR(RED));
- attroff(A_BOLD);
- move(7, player_x);
- refresh();
- score += 100;
- switch (score)
- {
- case 2000:
- range = 7;
- break;
- case 4000:
- range = 5;
- delay = 200;
- break;
- case 5000:
- range = 4;
- delay = 150;
- break;
- case 10000:
- range = 3;
- delay = 100;
- break;
- case 100000:
- range = 1;
- break;
- }
- }
- sleepMs(delay);
- }
- tryagain(score, current_game);
- }
- }
- void initialization() {
- srand(time(NULL));
- initscr();
- keypad(stdscr, TRUE);
- nodelay(stdscr, TRUE);
- scrollok(stdscr, TRUE);
- noecho();
- if (has_colors() == FALSE)
- {
- endwin();
- printf("The terminal does not support color... :w\n");
- exit(1);
- }
- else
- {
- start_color();
- init_pair(1, COLOR_RED, COLOR_BLACK);
- init_pair(2, COLOR_BLUE, COLOR_BLACK);
- init_pair(3, COLOR_YELLOW, COLOR_BLACK);
- }
- }
- int main() {
- int key, counter = 0;
- int x, y;
- initialization();
- readysteadygo();
- game();
- endwin();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement