From 55189464c1ef1d2adc671180d7e4376691bade73 Mon Sep 17 00:00:00 2001 From: Ben Green Date: Tue, 7 Jul 2009 19:01:07 -0500 Subject: [PATCH] Fixed compilation issue Everything is working beautifully --- character.cc | 98 +++++++++++++++++++++------------------------------- 1 file changed, 40 insertions(+), 58 deletions(-) diff --git a/character.cc b/character.cc index fbc751a..dfdce3e 100644 --- a/character.cc +++ b/character.cc @@ -1,66 +1,48 @@ #include #include +#include "character.h" -class Character { - protected: - int x, y; - int xVel, yVel; - int speed; - SDL_Surface *sprite; - - public: - - Character() { - x = 0; - y = 0; - xVel = 0, yVel = 0; - speed = 5; - sprite = SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 16, 0,0,0,0); - SDL_FillRect(sprite, NULL, 0x0F00); - } - - virtual void handle_move() = 0; - virtual void handle_show(SDL_Surface* screen) = 0; -}; +Character::Character() { + x = 0; + y = 0; + xVel = 0, yVel = 0; + speed = 5; + sprite = SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 16, 0,0,0,0); + SDL_FillRect(sprite, NULL, 0x0F00); +} - -class Player: Character { - - public: - - std::queue input; - - void handle_input() { - SDL_Event event; - while(!input.empty()) { - event = input.front(); - if(event.type == SDL_KEYDOWN) { - switch(event.key.keysym.sym) { - case SDLK_UP: yVel -= 1; break; - case SDLK_DOWN: yVel += 1; break; - case SDLK_LEFT: xVel -= 1; break; - case SDLK_RIGHT: xVel += 1; break; - } - } else if(event.type == SDL_KEYUP) { - switch(event.key.keysym.sym) { - case SDLK_UP: yVel += 1; break; - case SDLK_DOWN: yVel -= 1; break; - case SDLK_LEFT: xVel += 1; break; - case SDLK_RIGHT: xVel -= 1; break; - } +void Player::handle_input() { + SDL_Event event; + while(!input.empty()) { + event = input.front(); + if(event.type == SDL_KEYDOWN) { + switch(event.key.keysym.sym) { + case SDLK_UP: yVel -= 1; break; + case SDLK_DOWN: yVel += 1; break; + case SDLK_LEFT: xVel -= 1; break; + case SDLK_RIGHT: xVel += 1; break; + } + } else if(event.type == SDL_KEYUP) { + switch(event.key.keysym.sym) { + case SDLK_UP: yVel += 1; break; + case SDLK_DOWN: yVel -= 1; break; + case SDLK_LEFT: xVel += 1; break; + case SDLK_RIGHT: xVel -= 1; break; } - input.pop(); } + input.pop(); } +} - void handle_move() { - x += speed * xVel; - y += speed * yVel; - } - void handle_show(SDL_Surface* screen) { - SDL_Rect offset; - offset.x = x; - offset.y = y; - SDL_BlitSurface(sprite, NULL, screen, &offset); - } -}; +void Player::handle_move() { + x += speed * xVel; + y += speed * yVel; +} + +void Player::handle_show(SDL_Surface* screen) { + SDL_Rect offset; + offset.x = x; + offset.y = y; + SDL_BlitSurface(sprite, NULL, screen, &offset); +} +