Question
1. Add streets. Put no houses in the streets but on the blocks. 2. Have a horizon (blue). Draw distant houses first. Houses in front
1. Add streets. Put no houses in the streets but on the blocks. 2. Have a horizon (blue). Draw distant houses first. Houses in front occlude houses behind (a 3D visual cue). 3. Draw the town using the on the street view but 5-6 feet tall view (as we do in class). 4. Even add a street lamp (use functions) or a tree where tree = ((triangle-fills & rectangle) for evergreen or (circlefills & rectangle) for deciduous).
#include
#include
#include
void init();
void deinit();
void param_house(int x, int y, int width, int height, int roof_height, int door_height, int door_width, int wall_color, int roof_color, int door_color);
int main() {
init();
srand(time(NULL)); // initialize random seed
while (!key[KEY_ESC]) {
clear_to_color(screen, makecol(0, 0, 255)); // blue sky
rectfill(screen, 0, 599, 799, 200, makecol(0, 255, 0)); // green lawn
int x = 50, y = 350;
int min_distance = 150; // minimum distance between houses
// generate random houses
for (int i = 0; i < 10; i++) {
// generate random house parameters
int width = rand() % 150 + 100;
int height = rand() % 100 + 150;
int roof_height = rand() % 50 + 50;
int door_height = rand() % 50 + 70;
int door_width = rand() % 30 + 20;
int wall_color = makecol(rand() % 256, rand() % 256, rand() % 256);
int roof_color = makecol(rand() % 256, rand() % 256, rand() % 256);
int door_color = makecol(rand() % 256, rand() % 256, rand() % 256);
// check for collision with previous houses
int collided = 0;
for (int j = 0; j < i; j++) {
if (abs(x - (50 + j * (min_distance + width))) < (min_distance + width) / 2) {
collided = 1;
break;
}
}
// draw house if no collision
if (!collided) {
param_house(x, y, width, height, roof_height, door_height, door_width, wall_color, roof_color, door_color);
}
// move to next house position
x += min_distance + width;
}
rest(50); // sleep for 50 ms to avoid high CPU usage
}
deinit();
return 0;
}
END_OF_MAIN()
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}
install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}
void deinit() {
clear_keybuf();
/* add other deinitializations here */
}
void param_house(int x, int y, int width, int height, int roof_height, int door_height, int door_width, int wall_color, int roof_color, int door_color) {
int roof[] = { x, y - roof_height, x + width, y - roof_height, x + width * 0.8, y - roof_height - width * 0.3, x + width * 0.2, y - roof_height - width * 0.3 };
int wall[] = { x, y, x + width, y, x + width, y - height, x, y - height };
int door[] = { x + width / 2 - door_width / 2, y, x + width / 2 + door_width / 2, y, x + width / 2 + door_width / 2, y - door_height, x + width / 2 - door_width / 2, y - door_height };
// draw roof
triangle(screen, roof[0], roof[1], roof[2], roof[3], roof[4], roof[5], roof_color);
triangle(screen, roof[0], roof[1], roof[6], roof[7], roof[4], roof[5], roof_color);
// draw wall
rectfill(screen, wall[0], wall[1], wall[2], wall[5], wall_color);
// draw door
rectfill(screen, door[0], door[1], door[2], door[3], door_color);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started