Skip to content

Commit

Permalink
Fixed compilation issue
Browse files Browse the repository at this point in the history
Everything is working beautifully
  • Loading branch information
Ben Green committed Jul 8, 2009
1 parent 5236644 commit 5518946
Showing 1 changed file with 40 additions and 58 deletions.
98 changes: 40 additions & 58 deletions character.cc
Original file line number Diff line number Diff line change
@@ -1,66 +1,48 @@
#include <SDL/SDL.h>
#include <queue>
#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<SDL_Event> 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);
}

0 comments on commit 5518946

Please sign in to comment.