Permalink
Browse files

some random update

  • Loading branch information...
RomainGailleton committed Apr 30, 2012
1 parent 70e2451 commit f460eab4503881bd95d40141992ec1a8870e0cfc
Showing with 86 additions and 29 deletions.
  1. +28 −10 src/block.cpp
  2. +4 −1 src/block.h
  3. +12 −1 src/camera.cpp
  4. +4 −1 src/camera.h
  5. +1 −1 src/config.cpp
  6. +13 −6 src/display.cpp
  7. +2 −1 src/display.h
  8. +18 −5 src/game.cpp
  9. +1 −0 src/game.h
  10. 0 src/menu.cpp
  11. +3 −3 src/menu.h
View
@@ -3,13 +3,31 @@
using namespace std;
- Block::Block(){
- t=0;
- }
-
- void Block::setT(int ta){ // sets the type
- t=ta;
- }
- int Block::getT(){
- return t;
- }
+Block::Block(){
+ t=0; // If not set the block is an error :)
+ speed = 1;
+}
+void
+Block::setT(int ta){ // sets the types and thus the speed.
+ t=ta;
+ if (t=1) speed = 0.5;
+ if (t=2) speed = 0.8;
+ if (t=3) speed = 1;
+ if (t=4) speed = 0.7;
+ if (t=0) speed = 1; // just so you can escape errors cells
+}
+
+int
+Block::getT(){
+ return t;
+}
+
+float
+Block::getSpeed(){
+ return speed;
+}
+
+void
+Block::setSpeed(float sp){
+ speed = sp;
+}
View
@@ -9,12 +9,15 @@
public:
int t; // the type of block : 1 is watter, 2 is sand, 3 is grass,4 is mountain 0 is an error of type.
+ float speed; // 0 to 1 multiplicator
Block();
void setT(int);
int getT();
+ float getSpeed();
+ void setSpeed(float);
};
-#endif
+#endif
View
@@ -5,9 +5,20 @@ Camera::Camera(){
setX(26);
setY(20);
+ zoom=1;
}
+void
+Camera::setZoom(int z){
+ zoom=z;
+}
+
+int
+Camera::getZoom(){
+ return zoom;
+}
+
void
Camera::setX(int px){
positionx = px;
@@ -23,4 +34,4 @@ Camera::getX(){
int
Camera::getY(){
return positiony;
-}
+}
View
@@ -12,12 +12,15 @@ class Camera{
private :
int positionx;
int positiony;
+ int zoom;
public:
Camera();
void setX(int);
void setY(int);
+ void setZoom(int);
+ int getZoom();
int getX();
int getY();
};
-#endif
+#endif
View
@@ -49,7 +49,7 @@ Config::Load (string filestring) {
lua_getglobal(L, "fps");
if (!lua_isnumber(L, -1)){
cout << "`fps' should be a number\n";
- Set_FPS(60);
+ Set_FPS(1);
}else{
Set_FPS ( (int)lua_tonumber(L, -1) );
}
View
@@ -98,6 +98,11 @@ Display::blit_text(string t, string font, int s, SDL_Color c, SDL_Rect p){
SDL_FreeSurface(texte);
}
+void
+Display::blit_menu(){
+
+}
+
void
Display::blit_map(Map& w, int tw, int th){
SDL_Rect p;
@@ -111,9 +116,9 @@ Display::blit_map(Map& w, int tw, int th){
for(i=mcam.getX()-25; i<mcam.getX()+25;i++){
k++;
- for(j=mcam.getY()-19; j<mcam.getY()+19;j++){
+ for(j=mcam.getY()-19; j<mcam.getY()+20;j++){
p.x =(k-1)*tw;
- if (m<37){
+ if (m<38){
m++;
}else{
m=0;
@@ -145,7 +150,9 @@ Display::blit_map(Map& w, int tw, int th){
void
Display::Set_Cam(int px,int py){
- mcam.setX(px);
- mcam.setY(py);
- cout << "nouvelle position de camera x : " << px << " y : " << py <<endl;
-}
+ int x=px;
+ int y=py;
+ mcam.setX(x);
+ mcam.setY(y);
+ // cout << "nouvelle position de camera x : " << px << " y : " << py <<endl;
+}
View
@@ -36,6 +36,7 @@ class Display {
void blit_image(string, SDL_Rect, int);
void blit_text(string, string, int, SDL_Color, SDL_Rect);
void blit_map(Map&, int,int);
+ void blit_menu();
// Geters
FPSmanager Get_FPSmanager() const;
@@ -50,4 +51,4 @@ class Display {
};
-#endif
+#endif
View
@@ -15,13 +15,11 @@ Game::~Game(){
void
Game::Loop(){
-
-
- int done = 1;
SDL_Color couleur = {100, 255, 50};
SDL_Event event;
SDL_Rect position;
+ int mousex=400,mousey=400;
Config cfg;
Display disp;
Map w;
@@ -32,12 +30,19 @@ Game::Loop(){
disp.Set_Surface(cfg.Get_screen_width(), cfg.Get_screen_height(), 32,SDL_HWSURFACE|SDL_DOUBLEBUF);
while (done)
{
+ start = SDL_GetTicks();
while (SDL_PollEvent(&event)){
switch(event.type)
{
case SDL_QUIT:
done = 0;
break;
+
+
+ case SDL_MOUSEMOTION:
+ mousex=event.motion.x;
+ mousey=event.motion.y;
+
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
@@ -61,12 +66,20 @@ Game::Loop(){
break;
}
}
+
+ if (mousex > 0 && mousex < 0.03*cfg.Get_screen_width() && disp.mcam.getX()>26) disp.Set_Cam(disp.mcam.getX()-1,disp.mcam.getY());
+ if (mousex > 0.97*cfg.Get_screen_width() && mousey < cfg.Get_screen_width() && disp.mcam.getX()<229) disp.Set_Cam(disp.mcam.getX()+1,disp.mcam.getY());
+ if (mousey > 0 && mousey < (0.03*cfg.Get_screen_height()) && disp.mcam.getY()>20) disp.Set_Cam(disp.mcam.getX(),disp.mcam.getY()-1);
+ if (mousey > (0.97*cfg.Get_screen_height()) && mousey < cfg.Get_screen_height() && disp.mcam.getY()<235) disp.Set_Cam(disp.mcam.getX(),disp.mcam.getY()+1);
+ cout << mousex << " " << mousey << endl;
disp.Black();
- disp.blit_map(w, cfg.Get_Tile_size("w"), cfg.Get_Tile_size("h"));
+ disp.blit_map(w, cfg.Get_Tile_size("w")/disp.mcam.getZoom(), cfg.Get_Tile_size("h")/disp.mcam.getZoom());
//disp.blit_text("text", cfg.Get_font(), 72, couleur, position);
//disp.Delay();
SDL_Flip(disp.Get_Surface());
+ if (1000/cfg.Get_FPS()>SDL_GetTicks()-start)
+ SDL_Delay(1000/cfg.Get_FPS()-(SDL_GetTicks()-start));
disp.Delay();
}
disp.Klean();
@@ -77,4 +90,4 @@ Game::Loop(){
void
Game::Set_Done(){
done = 0;
-}
+}
View
@@ -15,6 +15,7 @@ class Game {
private :
int done;
+ Uint32 start;
public :
Game();
View
No changes.
View
@@ -6,9 +6,9 @@ class Menu{
private:
public:
- Menu();
- ~Menu();
+
+
};
-#endif
+#endif

0 comments on commit f460eab

Please sign in to comment.