--- a/src/GameState.cc Sun Dec 07 18:21:44 2008 +0000
+++ b/src/GameState.cc Sun Dec 07 18:23:18 2008 +0000
@@ -31,8 +31,9 @@
}
void GameState::draw(Graphics *g, bool displayWeapon) {
+ Vector camera = local_player->getPosition()-Vector(800/2, 600/2);
// Draw world/terrain
- world.draw(g->get_gc());
+ world.draw(g->get_gc(), camera);
// Draw players
for (std::list<Player*>::iterator it = player_list.begin(); it != player_list.end(); it++) {
@@ -40,14 +41,14 @@
// our LocalPlayer has it's own draw method
if (p == local_player)
- local_player->draw(g, displayWeapon);
+ local_player->draw(g, displayWeapon, camera);
else
- p->draw(g);
+ p->draw(g, camera);
}
// Draw projectiles
for (std::list<Projectile*>::iterator it = projectiles.begin(); it != projectiles.end(); it++) {
- (*it)->draw(g);
+ (*it)->draw(g, camera);
}
}
--- a/src/Graphics.cc Sun Dec 07 18:21:44 2008 +0000
+++ b/src/Graphics.cc Sun Dec 07 18:23:18 2008 +0000
@@ -53,7 +53,7 @@
CL_GraphicContext *gc = get_gc();
// White background
- gc->clear(CL_Color::white);
+ gc->clear(CL_Color::black);
// Draw the game
state.draw(this, flags & GUI_INPUT_DISPLAY_WEAPON);
--- a/src/Player.cc Sun Dec 07 18:21:44 2008 +0000
+++ b/src/Player.cc Sun Dec 07 18:23:18 2008 +0000
@@ -14,10 +14,10 @@
CL_Surface Player::skin_surface;
// XXX: give these better names and move elsewhere
-const int img_num_aim = 9;
+const int img_num_aim = 2;
const int img_num_step = 4;
-const int img_height = 9;
-const int img_width = 10;
+const int img_height = 20;
+const int img_width = 17;
Player::Player(GameState &state, Vector position, bool visible) :
PhysicsObject(state.world, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible),
@@ -182,8 +182,9 @@
return weapons[selectedWeapon % weapons.size()];
}
-void Player::draw (Graphics *g) {
+void Player::draw (Graphics *g, Vector camera) {
CL_GraphicContext *gc = g->get_gc();
+ int cx = (int)camera.x, cy = (int)camera.y;
int aim_img_idx = (int)((1 - (getAim()+KG_PI/2)/KG_PI)*img_num_aim);
int step_img_idx = animation_step%img_num_step;
@@ -195,25 +196,25 @@
}
// XXX: this logic looks weird
- CL_Rectf destination(position.x - 4, position.y - 4, position.x + 5, position.y + 4);
+ CL_Rectf destination(position.x - 4 -cx, position.y - 4 -cy, position.x + 5 -cx, position.y + 4 -cy);
if (!getFacing()) {
- destination = CL_Rect(position.x + 5, position.y - 4, position.x - 4, position.y + 4);
+ destination = CL_Rect(position.x + 5 -cx, position.y - 4 -cy, position.x - 4 -cx, position.y + 4 -cy);
}
skin_surface.draw_subpixel(
CL_Rectf(
- 1 + step_img_idx * img_width,
- aim_img_idx * img_height + 1,
- 1 + (1 + step_img_idx) * img_width,
- (aim_img_idx + 1) * img_height + 1
+ step_img_idx * img_width,
+ aim_img_idx * img_height,
+ (1 + step_img_idx) * img_width,
+ (aim_img_idx + 1) * img_height
),
destination, gc
);
const uint16_t chlen = 10;
- uint16_t x = position.x;
- uint16_t y = position.y;
+ int x = position.x -cx;
+ int y = position.y -cy;
// draw "crosshair"
if (facingRight) {
@@ -230,20 +231,20 @@
CL_Color::black);
}
- rope.draw(g);
+ rope.draw(g, camera);
}
-void LocalPlayer::draw (Graphics *g, bool displayWeapon) {
+void LocalPlayer::draw (Graphics *g, bool displayWeapon, Vector camera) {
// superclass draw
- Player::draw(g);
+ Player::draw(g, camera);
// display weapon name?
if (displayWeapon && getCurrentWeapon()) {
const std::string weaponName = getCurrentWeapon()->getName();
g->getSimpleFont().draw(
- position.x - g->getSimpleFont().get_width(weaponName) / 2,
- position.y - 20,
+ position.x - camera.x - g->getSimpleFont().get_width(weaponName) / 2,
+ position.y - camera.y - 20,
weaponName,
g->get_gc()
);
--- a/src/Player.hh Sun Dec 07 18:21:44 2008 +0000
+++ b/src/Player.hh Sun Dec 07 18:23:18 2008 +0000
@@ -71,7 +71,7 @@
*/
static bool skin_loaded;
static CL_Surface skin_surface;
- virtual void draw (Graphics *g);
+ virtual void draw (Graphics *g, Vector camera = Vector(0, 0));
};
class LocalPlayer : public virtual Player {
@@ -97,7 +97,7 @@
/*
* As Player, but also draws the current weapon name if displayWeapon
*/
- virtual void draw (Graphics *g, bool displayWeapon);
+ virtual void draw (Graphics *g, bool displayWeapon, Vector camera);
};
class RemotePlayer : public virtual Player {
--- a/src/Projectile.cc Sun Dec 07 18:21:44 2008 +0000
+++ b/src/Projectile.cc Sun Dec 07 18:23:18 2008 +0000
@@ -43,23 +43,23 @@
PhysicsObject::tick(dt);
}
-void Projectile::draw(Graphics *g) const {
+void Projectile::draw(Graphics *g, Vector cam) const {
CL_GraphicContext *gc = g->get_gc();
if (visible) {
CL_Quad projectile(
- (int)((position).x+1), (int)((position).y+1),
- (int)((position).x-1), (int)((position).y+1),
- (int)((position).x+1), (int)((position).y-1),
- (int)((position).x-1), (int)((position).y-1)
+ (int)((position).x+1-cam.x), (int)((position).y+1-cam.y),
+ (int)((position).x-1-cam.x), (int)((position).y+1-cam.y),
+ (int)((position).x+1-cam.x), (int)((position).y-1-cam.y),
+ (int)((position).x-1-cam.x), (int)((position).y-1-cam.y)
);
gc->fill_quad(projectile, CL_Color::green);
const uint16_t chlen = 10;
- uint16_t x = projectile.center().x;
- uint16_t y = projectile.center().y;
+ int x = projectile.center().x -cam.x;
+ int y = projectile.center().y -cam.y;
if (target_visible) {
if (facingRight) {
gc->draw_line(x, y,
--- a/src/Projectile.hh Sun Dec 07 18:21:44 2008 +0000
+++ b/src/Projectile.hh Sun Dec 07 18:23:18 2008 +0000
@@ -22,7 +22,7 @@
Projectile (GameState &state, Vector position, Vector velocity, bool visible, float radius, TickCount age=1000000000);
virtual ~Projectile (void);
- virtual void draw (Graphics *g) const;
+ virtual void draw (Graphics *g, Vector camera = Vector(0, 0)) const;
protected:
/*
--- a/src/Rope.cc Sun Dec 07 18:21:44 2008 +0000
+++ b/src/Rope.cc Sun Dec 07 18:23:18 2008 +0000
@@ -120,13 +120,13 @@
return 0;
}
-void Rope::draw (Graphics *g) const {
+void Rope::draw (Graphics *g, Vector cam) const {
if (state == ROPE_FOLDED)
return;
g->get_gc()->draw_line(
- player.getPosition().x, player.getPosition().y,
- position.x, position.y,
+ player.getPosition().x-cam.x, player.getPosition().y-cam.y,
+ position.x-cam.x, position.y-cam.y,
CL_Color::black
);
}
--- a/src/Rope.hh Sun Dec 07 18:21:44 2008 +0000
+++ b/src/Rope.hh Sun Dec 07 18:23:18 2008 +0000
@@ -74,7 +74,7 @@
/*
* Just draws it
*/
- virtual void draw (Graphics *c) const;
+ virtual void draw (Graphics *c, Vector camera = Vector(0, 0)) const;
};
#endif
--- a/src/Terrain.cc Sun Dec 07 18:21:44 2008 +0000
+++ b/src/Terrain.cc Sun Dec 07 18:23:18 2008 +0000
@@ -389,9 +389,9 @@
this->generatePixelBuffer();
}
-void Terrain::draw(CL_GraphicContext *gc) {
+void Terrain::draw(CL_GraphicContext *gc, Vector camera) {
CL_Surface surf(this->pixbuf);
- surf.draw(0,0,gc);
+ surf.draw((int)-camera.x, (int)-camera.y ,gc);
}
std::vector<std::vector<TerrainType> > Terrain::getTerrain() const {
--- a/src/Terrain.hh Sun Dec 07 18:21:44 2008 +0000
+++ b/src/Terrain.hh Sun Dec 07 18:23:18 2008 +0000
@@ -150,8 +150,9 @@
* Draw the terrain for given graphicscontext.
*
* @param gc CL_GraphicContext
+ * @param camera - upper left corner of screen
*/
- virtual void draw(CL_GraphicContext *gc);
+ virtual void draw(CL_GraphicContext *gc, Vector camera = Vector(0, 0));
/**
* Draw part of the terrain for given graphiscontext.