/* * ttyvaders Textmode shoot'em up * Copyright (c) 2002 Sam Hocevar * All Rights Reserved * * $Id$ * * This program is free software. It commes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/wtfpl/COPYING for more details. */ #include "config.h" #include #include "common.h" starfield * create_starfield(game *g) { int i; starfield *s; s = malloc(STARS * sizeof(starfield)); if(s == NULL) exit(1); for(i = 0; i < STARS; i++) { s[i].x = cucul_rand(0, g->w - 1); s[i].y = cucul_rand(0, g->h - 1); s[i].z = cucul_rand(1, 3); s[i].c = cucul_rand(0, 1) ? CUCUL_COLOR_LIGHTGRAY : CUCUL_COLOR_DARKGRAY; s[i].ch = cucul_rand(0, 1) ? '.' : '\''; } return s; } void draw_starfield(game *g, starfield *s) { int i; for(i = 0; i < STARS; i++) { if(s[i].x >= 0) { cucul_set_color(g->cv, s[i].c, CUCUL_COLOR_BLACK); cucul_putchar(g->cv, s[i].x, s[i].y, s[i].ch); } } } void update_starfield(game *g, starfield *s) { int i; for(i = 0; i < STARS; i++) { if(s[i].x < 0) { s[i].x = cucul_rand(0, g->w - 1); s[i].y = 0; s[i].z = cucul_rand(1, 2); s[i].c = cucul_rand(0, 1) ? CUCUL_COLOR_LIGHTGRAY : CUCUL_COLOR_DARKGRAY; s[i].ch = cucul_rand(0, 1) ? '.' : '\''; } else if(s[i].y < g->h-1) { s[i].y += s[i].z; } else { s[i].x = -1; } } } void free_starfield(game *g, starfield *s) { free(s); }