Add new invisible item functionality. Visualize user holding shield.
authorDaniel G <giri@nwrk.biz>
Fri, 6 Dec 2019 19:14:07 +0000 (20:14 +0100)
committerDaniel G <giri@nwrk.biz>
Fri, 6 Dec 2019 19:14:07 +0000 (20:14 +0100)
src/GameWindow.cxx
src/GameWindow.h
src/Makefile
src/Model.cxx

index ab49f55..84f4f18 100644 (file)
@@ -86,6 +86,7 @@ void GameWindow::draw(){
       // load textures
       load_texture(m_texture_player, m_ResourceDir + "Player.png");
       load_texture(m_texture_player_mask, m_ResourceDir + "Player_mask.png");
+      load_texture(m_texture_player_shield, m_ResourceDir + "Player_shield.png");
       load_texture(m_texture_wall, m_ResourceDir + "BrickWallSolid.png");
       load_texture(m_texture_wall_breakable, m_ResourceDir + "BrickWallBreakable.png");
       load_texture(m_texture_bomb, m_ResourceDir + "Bomb.png");
@@ -96,6 +97,7 @@ void GameWindow::draw(){
       load_texture(m_texture_speed, m_ResourceDir + "SpeedCountUp.png");
       load_texture(m_texture_more_bombs, m_ResourceDir + "BombCountUp.png");
       load_texture(m_texture_flame, m_ResourceDir + "Flame.png");
+      load_texture(m_texture_invisible, m_ResourceDir + "Invisible.png");
 
     }
 
@@ -125,21 +127,23 @@ void GameWindow::draw(){
 
     for(size_t i=0; i<m_map_n; i++){
       for(size_t j=0; j<m_map_n; j++){
-       if(map[i*m_map_n+j] == MapField::Fixed){
-         draw_wall(i, j);
-       }else if(map[i*m_map_n+j] == MapField::Breakable){
-         draw_wall_breakable(i, j);
-       }else if(map[i*m_map_n+j] == MapField::ItemMoreBombs){
-         draw_item(i, j, m_texture_more_bombs);
-       }else if(map[i*m_map_n+j] == MapField::ItemMoreSpeed){
-         draw_item(i, j, m_texture_speed);
-       }else if(map[i*m_map_n+j] == MapField::ItemMoreFlame){
-         draw_item(i, j, m_texture_more_flames);
-       }else if(map[i*m_map_n+j] == MapField::ItemLife){
-         draw_item(i, j, m_texture_life);
-       }else if(map[i*m_map_n+j] == MapField::ItemShield){
-         draw_item(i, j, m_texture_shield);
-       }
+        if(map[i*m_map_n+j] == MapField::Fixed){
+          draw_wall(i, j);
+        }else if(map[i*m_map_n+j] == MapField::Breakable){
+          draw_wall_breakable(i, j);
+        }else if(map[i*m_map_n+j] == MapField::ItemMoreBombs){
+          draw_item(i, j, m_texture_more_bombs);
+        }else if(map[i*m_map_n+j] == MapField::ItemMoreSpeed){
+          draw_item(i, j, m_texture_speed);
+        }else if(map[i*m_map_n+j] == MapField::ItemMoreFlame){
+          draw_item(i, j, m_texture_more_flames);
+        }else if(map[i*m_map_n+j] == MapField::ItemLife){
+          draw_item(i, j, m_texture_life);
+        }else if(map[i*m_map_n+j] == MapField::ItemShield){
+          draw_item(i, j, m_texture_shield);
+        }else if(map[i*m_map_n+j] == MapField::ItemInvisible){
+          draw_item(i, j, m_texture_invisible);
+        }
       }
     }
 
@@ -235,7 +239,14 @@ void GameWindow::draw_player(packet::types::Player p){
 
     glEnable(GL_BLEND);
 
-    glColor4f(red/255.0, green/255.0, blue/255.0, 1);
+    GLfloat rgb_alpha = 1.0;
+    if(p.invisibleTimeout > 3.0)
+      rgb_alpha = (4.0-3.0)/4.0;
+    else
+      rgb_alpha = (4.0-p.invisibleTimeout)/4.0;
+
+    std::cout  << "Invisible: " << p.invisibleTimeout << std::endl;
+    glColor4f(red/255.0, green/255.0, blue/255.0, rgb_alpha);
     glBindTexture(GL_TEXTURE_2D, m_texture_player_mask);
     glEnable(GL_TEXTURE_2D);
     glBegin(GL_QUADS);
@@ -248,8 +259,13 @@ void GameWindow::draw_player(packet::types::Player p){
     // glBlendFunc (GL_SRC_ALPHA, GL_ONE);
     glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
-    glColor4f(1, 1, 1, 1);
-    glBindTexture(GL_TEXTURE_2D, m_texture_player);
+    glColor4f(1, 1, 1, rgb_alpha);
+    std::cout  << "Shield: " << p.immortalTimeout << std::endl;
+    if(p.immortalTimeout > 0.0)
+      glBindTexture(GL_TEXTURE_2D, m_texture_player_shield);
+    else
+      glBindTexture(GL_TEXTURE_2D, m_texture_player);
+    
     glEnable(GL_TEXTURE_2D);
     glBegin(GL_QUADS);
     glTexCoord2f(offs_x, 0.25); glVertex2f(p.y-0.5, m_map_n-p.x-0.5);
@@ -296,21 +312,21 @@ void GameWindow::draw_player_lives(packet::types::Player p){
 
       // cross out "used" lives
       if(p.live <= i){
-       glColor4f(1, 0, 0, 1);
-       glBindTexture(GL_TEXTURE_2D, 0);
-       glBegin(GL_QUADS);
-       glVertex2f(c_cross_thickness+i, 0);
-       glVertex2f(1+i, 1-c_cross_thickness);
-       glVertex2f(1+i-c_cross_thickness, 1);
-       glVertex2f(i, c_cross_thickness);
-       glEnd();
-
-       glBegin(GL_QUADS);
-       glVertex2f(1-c_cross_thickness+i, 0);
-       glVertex2f(1+i, c_cross_thickness);
-       glVertex2f(i+c_cross_thickness, 1);
-       glVertex2f(i, 1-c_cross_thickness);
-       glEnd();
+        glColor4f(1, 0, 0, 1);
+        glBindTexture(GL_TEXTURE_2D, 0);
+        glBegin(GL_QUADS);
+        glVertex2f(c_cross_thickness+i, 0);
+        glVertex2f(1+i, 1-c_cross_thickness);
+        glVertex2f(1+i-c_cross_thickness, 1);
+        glVertex2f(i, c_cross_thickness);
+        glEnd();
+
+        glBegin(GL_QUADS);
+        glVertex2f(1-c_cross_thickness+i, 0);
+        glVertex2f(1+i, c_cross_thickness);
+        glVertex2f(i+c_cross_thickness, 1);
+        glVertex2f(i, 1-c_cross_thickness);
+        glEnd();
       }
 
     }
index b497b0a..0c1a554 100644 (file)
@@ -51,6 +51,7 @@ class GameWindow : public Fl_Gl_Window {
 
   GLuint m_texture_player;
   GLuint m_texture_player_mask;
+  GLuint m_texture_player_shield;
   GLuint m_texture_wall;
   GLuint m_texture_wall_breakable;
   GLuint m_texture_more_bombs;
@@ -62,6 +63,7 @@ class GameWindow : public Fl_Gl_Window {
   GLuint m_texture_speed;
   GLuint m_texture_flame;
   GLuint m_texture_item;
+  GLuint m_texture_invisible;
 
   ModelIF::SPtr mModel;
 
index 59abd6f..813f2e1 100644 (file)
@@ -13,7 +13,7 @@ SOURCES := $(shell ls *.cxx)
 PROJNAME = esdbomber-client
 LIBDIR =
 INC = -I$(WORKDIR)/../include -I$(WORKDIR)/../../include -I$(WORKDIR)/../../server/src -I$(WORKDIR)/../../resources/sprites
-LDFLAGS = -m32 -std=c++11 -static-libstdc++ -static-libgcc -Wl,-Bstatic -pthread
+LDFLAGS = -m32 -std=c++17 -static-libstdc++ -static-libgcc -Wl,-Bstatic -pthread
 CFLAGS = -m32 -Wall -fexceptions -std=c++11 -static-libstdc++ -static-libgcc
 LIB =  -lboost_date_time -lboost_system -lboost_regex -lboost_thread -lfltk_images -lfltk_png -lfltk_z -lfltk_jpeg -lfltk_gl -lfltk -lsndfile
 
@@ -53,7 +53,7 @@ LIB_WIN = $(LIB) -static -lao -mwindows -lole32 -luuid -lcomctl32 -lopengl32 -lg
 #RELEASE GCC SETTINGS | EDIT: 4/7
 ###################################
 INC_RELEASE_GCC = $(INC_GCC)
-CFLAGS_RELEASE_GCC = $(CFLAGS_GCC) -O2
+CFLAGS_RELEASE_GCC = $(CFLAGS_GCC) -O3
 RESINC_RELEASE_GCC = $(RESINC_GCC)
 RCFLAGS_RELEASE_GCC = $(RCFLAGS_GCC)
 LIBDIR_RELEASE_GCC = $(LIBDIR_GCC)
@@ -81,7 +81,7 @@ OUT_DEBUG_GCC = bin/Debug_Linux
 #RELEASE MinGW SETTINGS | EDIT: 6/7
 ###################################
 INC_RELEASE_WIN = $(INC_WIN)
-CFLAGS_RELEASE_WIN = $(CFLAGS_WIN) -O2
+CFLAGS_RELEASE_WIN = $(CFLAGS_WIN) -O3
 RESINC_RELEASE_WIN = $(RESINC_WIN)
 RCFLAGS_RELEASE_WIN = $(RCFLAGS_WIN)
 LIBDIR_RELEASE_WIN = $(LIBDIR_WIN)
index fa1e4e0..8a4af55 100644 (file)
@@ -123,6 +123,8 @@ Model::Players Model::GetPlayers()
         curPlayer.id = curPlayerJSON["id"].ToInt();
         curPlayer.x = curPlayerJSON["x"].ToFloat();
         curPlayer.y = curPlayerJSON["y"].ToFloat();
+        curPlayer.immortalTimeout = curPlayerJSON["immortalTimeout"].ToFloat();
+        curPlayer.invisibleTimeout = curPlayerJSON["invisibleTimeout"].ToFloat();
         curPlayer.direction = static_cast<packet::types::PlayerDirection>(curPlayerJSON["dir"].ToInt());
         curPlayer.live = curPlayerJSON["live"].ToInt();