Build a initial structure to build the game
This includes: * Change the Makefile so we can build the source with SDL * Create a config file for all global variables * Initialize a simple game loop to see something on the screen * Stub for building a drawing lib * Modify the README a little bit
This commit is contained in:
parent
104a4b1d49
commit
e12b581fc8
7 changed files with 108 additions and 11 deletions
21
Makefile
21
Makefile
|
@ -4,9 +4,7 @@ CC= gcc
|
|||
# Compiler flags
|
||||
CFLAGS= -Wall -Os -std=c99
|
||||
# Libraries
|
||||
CLIBS=
|
||||
# Includes
|
||||
CINCL=
|
||||
CLIBS= `sdl-config --cflags` -lSDL -lGL
|
||||
####### Commands
|
||||
RM= rm -r
|
||||
MKDIR= mkdir -p
|
||||
|
@ -29,25 +27,28 @@ SRCS = $(shell ls -1 $(SRCDIR)/*.$(SRCEND))
|
|||
BINS = $(SRCS:$(SRCDIR)%.$(SRCEND)=$(OBJDIR)%.$(OBJEND))
|
||||
|
||||
# default task depends on compile
|
||||
all: compile
|
||||
all: init compile
|
||||
|
||||
# create object-folder
|
||||
init:
|
||||
$(MKDIR) $(OBJDIR)
|
||||
|
||||
# compile depends on object files and executable
|
||||
compile: $(BINS) $(EXE)
|
||||
|
||||
# executable depends on all object files
|
||||
$(EXE): $(BINS)
|
||||
$(CC) $(CINCL) -o $(OUTDIR)/$(NAME) -export-dynamic $(BINS) $(CLIBS) $(CFLAGS)
|
||||
$(CC) -o $(OUTDIR)/$(NAME) -export-dynamic $(BINS) $(CLIBS) $(CFLAGS)
|
||||
|
||||
# each file in OBJDIR/*.o depends on corresponding source file in SRCDIR
|
||||
# $@ = name of target (*.o)
|
||||
# $< = first dependency (*.c)
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.$(SRCEND)
|
||||
$(MKDIR) $(OBJDIR) # create object-folder
|
||||
# $@ = name of target (*.o)
|
||||
# $< = first dependency (*.c)
|
||||
$(CC) $(CINCL) -c $< -o $@ $(CFLAGS)
|
||||
$(CC) -c $< -o $@ $(CLIBS) $(CFLAGS)
|
||||
|
||||
# delete OUTDIR
|
||||
# don't raise an error if directory not exists
|
||||
clean:
|
||||
# don't raise an error if directory not exists
|
||||
$(RM) $(OUTDIR) || true
|
||||
|
||||
# start programm
|
||||
|
|
10
README.rdoc
10
README.rdoc
|
@ -1,10 +1,20 @@
|
|||
|
||||
== Adventskalender 2009
|
||||
Viele reden von Open Source, doch die wenigsten beteiligen sich aktiv. Mit dieser Serie von Artikeln will ich den Open Source Gedanken etwas näher bringen und ein interaktives Projekt zum mitmachen schaffen. Verpackt als Adventskalender (in kooperation mit Florian) gibt es jeden zweiten Tag im Advent ein Teil dieser Serie. Florian stellt wiederum jeden zweiten Tag ein CLI-Tool vor. Der Adventskalender ist unter {Florians Blog}[http://feitel.indeedgeek.de/2009/adventskalender/] zu finden.
|
||||
|
||||
== Über dieses Projekt
|
||||
In diesem Projekt soll (der Anfang) eines kleinen 2D-Spiels erstellt werden. Dieses soll dazu dienen Open Source Entwicklungstools und den Prozess im allgemeinen kennenzulernen. Das Projekt lebt vom Mitmachen, jeder ist herzlich eingeladen sich daran zu beteiligen.
|
||||
|
||||
== Vorbedingungen
|
||||
Folgende Pakete/Programme/Libs sollten im System installiert sein:
|
||||
* libSDL
|
||||
* gcc, make
|
||||
|
||||
== Installation
|
||||
Um das Projekt zu starten, wird das Makefile verwendet. "make" baut das Projekt.
|
||||
|
||||
== Teilnehmer
|
||||
* Aaron Mueller <mail@aaron-mueller.de>
|
||||
* Ruben Mueller <r.mueller@purzwei.de>
|
||||
* Florian Eitel <feitel indeedgeek de>
|
||||
|
||||
|
|
10
src/config.c
Normal file
10
src/config.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
#include "SDL.h"
|
||||
#include <stdbool.h>
|
||||
#include "config.h"
|
||||
|
||||
// Initialization for the global variables
|
||||
SDL_Surface *screen = NULL;
|
||||
SDL_Event event;
|
||||
bool gameRunning = true;
|
||||
|
19
src/config.h
Normal file
19
src/config.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
#include "SDL.h"
|
||||
|
||||
// In this file we define all global variables for the whole project. All
|
||||
// variables definied here can be accessed from all other source files.
|
||||
|
||||
// Global variables and definitions
|
||||
extern SDL_Surface *screen; // Screen to paint on
|
||||
extern SDL_Event event; // Event storage
|
||||
extern bool gameRunning; // Set this variable to false to shutdown the game
|
||||
|
||||
|
||||
// Constants
|
||||
|
||||
// Screen size
|
||||
static const int SCREEN_WIDTH = 800;
|
||||
static const int SCREEN_HEIGHT = 600;
|
||||
|
17
src/draw.c
Normal file
17
src/draw.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
|
||||
#include "SDL.h"
|
||||
#include "draw.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
void drawPixel(int x, int y, int color) {
|
||||
unsigned int *p = (unsigned int*)screen->pixels;
|
||||
int lineOffset = y * (screen->pitch/4);
|
||||
p[lineOffset+x] = color;
|
||||
}
|
||||
|
||||
void drawScreen() {
|
||||
Uint32 black = SDL_MapRGB(screen->format, 0xff, 0xff, 0xff);
|
||||
drawPixel(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, black);
|
||||
}
|
||||
|
19
src/draw.h
Normal file
19
src/draw.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
#ifndef DRAW_H
|
||||
#define DRAW_H
|
||||
|
||||
/*
|
||||
* Draw a single pixel on the surface with the given color. This is the basic
|
||||
* function to paint on the screen. We will be use this function for all paint
|
||||
* stuff.
|
||||
*/
|
||||
void drawPixel(int x, int y, int color);
|
||||
|
||||
/*
|
||||
* This function will be called for every frame. Here you can actual draw things
|
||||
* on the screen.
|
||||
*/
|
||||
void drawScreen();
|
||||
|
||||
#endif
|
||||
|
23
src/main.c
23
src/main.c
|
@ -1,8 +1,29 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "SDL.h"
|
||||
#include "config.h"
|
||||
#include "draw.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
printf("Bald kommt der Nikolaus\n");
|
||||
// Initialize SDL and open up a screen
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
|
||||
|
||||
// the main game loop
|
||||
while (gameRunning == true) {
|
||||
// Check for events
|
||||
if (SDL_PollEvent(&event)) {
|
||||
// Make it possible to close the game window
|
||||
if (event.type == SDL_QUIT) gameRunning = false;
|
||||
}
|
||||
|
||||
// Draw the stuff on the screen and "flip" th the next frame
|
||||
drawScreen();
|
||||
SDL_Flip(screen);
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue