Name: Anonymous 2012-02-20 15:30
Player.h
Player.cpp
Game.cpp
I made those 3 files for the game I'm working on, but I have no idea of how to compile/link them with g++, any idea?
#ifndef PLAYER_H
#define PLAYER_H
class Player {
private:
Player() {};
public:
int x;
int y;
};
#endifPlayer.cpp
#include "Player.h"
Player::Player (int player_x, int player_y) {
x = player_x;
y = player_y;
}Game.cpp
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include "Player.h"
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
#define SCREEN_DEPTH 8
using namespace std;
int main(int argc, char *argv[]);
void draw_player(SDL_Surface *screen, int x, int y);
void clear_screen(SDL_Surface *screen);
void draw_player(SDL_Surface *screen, int x, int y) {
/* Blits the player to the screen */
SDL_Rect player_block = {x, y, 25, 25};
Uint8 player_color = SDL_MapRGB(screen->format, 255, 255, 255);
SDL_FillRect(screen, &player_block, player_color);
}
void clear_screen(SDL_Surface *screen) {
/* Clear the screen to black */
Uint8 color_black = SDL_MapRGB(screen->format, 0, 0, 0);
SDL_FillRect(screen, NULL, color_black);
}
int main(int argc, char *argv[]) {
/* Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) == -1)
printf("Error: unable to initialize SDL: '%s'\n", SDL_GetError());
SDL_Surface *screen;
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);
SDL_WM_SetCaption("Game", "Game");
SDL_Event event;
int running = 1;
Player player (20, 20);
/****************************** Main Game Loop ******************************/
while (running) {
SDL_PollEvent(&event);
if (event.type == SDL_QUIT) {
SDL_Quit();
return 0;
}
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_ESCAPE) {
SDL_Quit();
return 0;
}
}
draw_player(screen, player.x, player.y);
SDL_Flip(screen);
clear_screen(screen);
}
return 0;
}I made those 3 files for the game I'm working on, but I have no idea of how to compile/link them with g++, any idea?