Changeset 522

Show
Ignore:
Timestamp:
04/26/08 07:30:17 (9 months ago)
Author:
LeoD
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/defend/game/hud/Mouse.d

    r520 r522  
    749749 
    750750        // Render health bar above selected objects 
    751         foreach(objt; gameObjects) 
    752         { 
    753             auto obj = cast(GameObject)objt; 
    754  
     751        foreach(obj; gameObjects) 
     752        { 
    755753            if(!obj.selected) 
    756754                continue; 
     
    763761        glBegin(GL_QUADS); 
    764762 
    765         foreach(objt; gameObjects) 
    766         { 
    767             auto obj = cast(GameObject)objt; 
    768  
     763        foreach(obj; gameObjects) 
     764        { 
    769765            if(!obj.selected) 
    770766                continue; 
     
    791787            glVertex2f(end.x, start.y); 
    792788 
    793             glColor3f(0, 1, 0); 
    794  
     789            glColor3f(1, 0, 0); 
     790             
    795791            glVertex2f(start.x + BORDER_SIZE, start.y + BORDER_SIZE); 
    796792            glVertex2f(start.x + BORDER_SIZE, end.y - BORDER_SIZE); 
    797793            glVertex2f(end.x - BORDER_SIZE, end.y - BORDER_SIZE); 
    798794            glVertex2f(end.x - BORDER_SIZE, start.y + BORDER_SIZE); 
     795 
     796            { 
     797                glColor3f(0, 1, 0); 
     798 
     799                auto percent = obj.life / obj.property(GameObject.Property.MaxLife); 
     800                uint endX = cast(int)(start.x + BAR_WIDTH * percent); 
     801 
     802                glVertex2f(start.x + BORDER_SIZE, start.y + BORDER_SIZE); 
     803                glVertex2f(start.x + BORDER_SIZE, end.y - BORDER_SIZE); 
     804                glVertex2f(endX - BORDER_SIZE, end.y - BORDER_SIZE); 
     805                glVertex2f(endX - BORDER_SIZE, start.y + BORDER_SIZE); 
     806            } 
    799807 
    800808            glColor3f(1, 1, 1); 
  • trunk/src/defend/objects/Core.d

    r521 r522  
    834834        const uint radius = 1; 
    835835        assert(radius >= 1); 
    836          
    837         uint startX = mapPos.x > radius - 1 ? mapPos.x - radius : 0; 
    838         uint startY = mapPos.y > radius - 1 ? mapPos.y - radius : 0; 
    839          
    840         uint endX = mapPos.x + typeInfo.dimension.x + radius < map.size.x ? 
    841                     mapPos.x + typeInfo.dimension.x + radius : 
    842                     mapPos.x + typeInfo.dimension.x; 
    843          
    844         uint endY = mapPos.y + typeInfo.dimension.y + radius < map.size.y ? 
    845                     mapPos.y + typeInfo.dimension.y + radius : 
    846                     mapPos.y + typeInfo.dimension.y; 
    847  
    848         for(uint y = startY; y < endY; y++) 
    849         { 
    850             for(uint x = startX; x < endX; x++) 
    851             { 
    852                 if(map.getTile(x, y).free) 
    853                     return MapPos(x, y); 
    854             } 
     836 
     837        foreach(x, y; mapRectangle(1)) 
     838        { 
     839            if(map.getTile(x, y).free) 
     840                return MapPos(x, y); 
    855841        } 
    856842         
     
    862848        const uint radius = 1; 
    863849        assert(radius >= 1); 
    864          
    865         uint startX = mapPos.x > radius - 1 ? mapPos.x - radius : 0; 
    866         uint startY = mapPos.y > radius - 1 ? mapPos.y - radius : 0; 
    867          
    868         uint endX = mapPos.x + typeInfo.dimension.x + radius < map.size.x ? 
    869                     mapPos.x + typeInfo.dimension.x + radius : 
    870                     mapPos.x + typeInfo.dimension.x; 
    871          
    872         uint endY = mapPos.y + typeInfo.dimension.y + radius < map.size.y ? 
    873                     mapPos.y + typeInfo.dimension.y + radius : 
    874                     mapPos.y + typeInfo.dimension.y; 
    875850 
    876851        bool hasResult = false; 
     
    878853        MapPos result; 
    879854 
    880         for(uint y = startY; y < endY; y++) 
    881         { 
    882             for(uint x = startX; x < endX; x++) 
    883             { 
    884                 if(!map.getTile(x, y).free) 
    885                     continue; 
    886                  
    887                 MapPos pos = MapPos(x, y); 
    888                  
    889                 auto distance = pos.distance(from); 
    890                  
    891                 if(!hasResult || distance < minDistance) 
    892                 { 
    893                     minDistance = distance; 
    894                     result = pos; 
    895                     hasResult = true; 
    896                 } 
     855        foreach(x, y; mapRectangle(1)) 
     856        { 
     857            if(!map.getTile(x, y).free) 
     858                continue; 
     859             
     860            MapPos pos = MapPos(x, y); 
     861             
     862            auto distance = pos.distance(from); 
     863             
     864            if(!hasResult || distance < minDistance) 
     865            { 
     866                minDistance = distance; 
     867                result = pos; 
     868                hasResult = true; 
    897869            } 
    898870        }