Add some fancy colors and interaction

This commit is contained in:
Aaron Mueller 2009-12-14 14:22:28 +01:00
parent 5b4847d15c
commit e13cc36bee
2 changed files with 32 additions and 4 deletions

View file

@ -78,8 +78,6 @@ void drawCircle(int x, int y, int radius, int color, bool filled) {
}
int* generateTerrain(float peakheight, float flatness) {
time_t start; srand(start);
float offset = (float)SCREEN_HEIGHT/2;
float r1 = _random(1.0, 5.0);
float r2 = _random(1.0, 5.0);
@ -100,7 +98,18 @@ int* generateTerrain(float peakheight, float flatness) {
}
void drawScreen() {
Uint32 white = SDL_MapRGB(screen->format, 255, 255, 255);
for (int x=0; x<SCREEN_WIDTH; x++) drawLine(x, terrain[x], x, SCREEN_HEIGHT, white);
Uint32 sky = SDL_MapRGB(screen->format, 186, 215, 217);
Uint32 green = SDL_MapRGB(screen->format, 101, 200, 21);
Uint32 darkGreen = SDL_MapRGB(screen->format, 52, 99, 14);
Uint32 ground = SDL_MapRGB(screen->format, 124, 88, 10);
for (int x=0; x<SCREEN_WIDTH; x++) {
int y = terrain[x];
drawLine(x, 0, x, y, sky);
if (y <= SCREEN_HEIGHT-15) drawLine(x, y, x, y+15, green);
if (y <= SCREEN_HEIGHT-20) drawLine(x, y+15, x, y+20, darkGreen);
if (y <= SCREEN_HEIGHT-21) drawLine(x, y+20, x, SCREEN_HEIGHT, ground);
}
}

View file

@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include "SDL.h"
#include "config.h"
#include "draw.h"
@ -11,6 +12,7 @@ int main(int argc, char **argv) {
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
// Initialize internal game state
srand(time(NULL));
terrain = generateTerrain(150.0, 180.0);
// the main game loop
@ -19,6 +21,23 @@ int main(int argc, char **argv) {
if (SDL_PollEvent(&event)) {
// Make it possible to close the game window
if (event.type == SDL_QUIT) gameRunning = false;
// Keyboard interaction
if (event.type == SDL_KEYDOWN) {
switch (event.key.keysym.sym) {
case SDLK_RETURN:
free(terrain);
terrain = generateTerrain(150.0, 180.0);
printf("New terrain generated.\n");
break;
case SDLK_ESCAPE:
case SDLK_F10:
gameRunning = false;
break;
default:
break;
}
}
}
// Draw the stuff on the screen and "flip" th the next frame