#include <ClanLib/core.h>
#include <ClanLib/gl.h> //do I need this in linux?
#include <ClanLib/display.h>
#include <ClanLib/application.h>
#include "coor.hh"
#include "game_state.hh"
#include "Player.hh"
class CL_Game : public CL_ClanApplication {
private:
bool keep_going;
void check_input() {
if(CL_Keyboard::get_keycode(CL_KEY_ESCAPE))
keep_going = false;
if(CL_Keyboard::get_keycode(CL_KEY_UP)) {
if(gs.cave[(int)(gs.players[0].xy.x+
((int)gs.players[0].xy.y+1)*640)] == 0) {
gs.players[0].xy2.y += 4;
}
}
if(CL_Keyboard::get_keycode(CL_KEY_LEFT)) {
gs.players[0].xy2.x += 0.2;
}
if(CL_Keyboard::get_keycode(CL_KEY_RIGHT)) {
gs.players[0].xy2.x -= 0.2;
}
}
public:
game_state gs;
CL_Game() : keep_going(true) {}
virtual int main(int argc, char **argv) {
CL_SetupCore setup_init;
CL_SetupDisplay setup_disp;
CL_SetupGL setup_gl;
gs.addPlayer(Player());
CL_DisplayWindow win("ikkuna", 640, 480);
// CL_Surface bg(CL_PNGProvider("image.png");
unsigned int last_draw = CL_System::get_time();
int r = 100, g = 100, b = 100;
unsigned int frame_count = 0;
bool R = false, G = false, B = false;
while(keep_going) { //not good idea to put infinite loop
CL_Display::clear(CL_Color(r, g, b));
// bg.draw(0, 0);
// CL_Display::fill_rect(CL_Rect((int)(x-10.0), (int)(y-10.0),
// (int)(x+10.0),
// (int)(y+10.0)), CL_Color(255-r, 255-g, 255-b));
for(int i = 0; i < 640*480; i++) {
int x = i%640;
int y = i/640;
CL_Color col = CL_Color(200, 100, 60);
if(gs.cave[i] == 1) {
col = CL_Color(50, 50, 200);
}
CL_Display::draw_pixel(x, y, col);
}
Player& pl1 = gs.players[0];
int pl1xi = (int)(pl1.xy.x);
int pl1yi = (int)(pl1.xy.y);
CL_Display::fill_rect(CL_Rect(pl1xi-10, pl1yi-10,
pl1xi+10, pl1yi+10), CL_Color(255-r, 255-g, 255-b));
for(int i = 0; i < gs.players.size(); i++) {
Player& pl2 = gs.players[i];
pl2.xy2.y -= 0.2;
double tmpx = pl2.xy.x, tmpy = pl2.xy.y;
pl2.xy.x = 2*pl2.xy.x-pl2.xy2.x;
pl2.xy.y = 2*pl2.xy.y-pl2.xy2.y;
pl2.xy2.x = tmpx;
pl2.xy2.y = tmpy;
if(gs.cave[((int)(pl2.xy.x +
((int)pl2.xy.y)*640))%(640*480)] == 0) {
pl2.xy = pl2.xy2;
}
}
CL_Display::flip(1);
frame_count++;
unsigned int cur_draw = CL_System::get_time();
check_input();
if(R) { r++;
} else { r--; }
if(G) { g++;
} else { g--; }
if(B) { b++;
} else { b--; }
if(r < 0) r = 0;
if(g < 0) g = 0;
if(b < 0) b = 0;
if(r > 255) r = 255;
if(g > 255) g = 255;
if(b > 255) b = 255;
if(frame_count % 100 == 0) {
R = rand()%2;
G = rand()%2;
B = rand()%2;
}
last_draw = cur_draw;
CL_System::keep_alive();
// sleep(10); //flip already wait a short amount of time
}
return 0;
}
};
CL_Game inst;