Changeset - c1561bd81710
[Not reviewed]
default
0 4 8
Silverwing - 8 years ago 2016-10-02 18:04:03

Added new files
12 files changed with 366 insertions and 4 deletions:
0 comments (0 inline, 0 general)
battlefield.lua
Show inline comments
 
battlefield = function(tab) {
 
}
 
\ No newline at end of file
 
_kh.bf_calcDistance = function(x1, y1, x2, y2)
 
    return math.max(math.abs(x2 - x1), math.abs(y2 - y1));
 
end;
 

	
 
_kh.bf_calcDirection = function(x1, y1, x2, y2)
 
    -- 0 - close by, 1-8 - north to north-west clockwise, 9 - too far
 
    local dist = _kh.bf_calcDistance(x1,y1,x2,y2);
 
    if (dist == 0) then
 
        return 0;
 
    elseif (dist == 1) then
 
        if (x1 == x2 and y1 > y2) then
 
            return 1;
 
        elseif (x1 < x2 and y1 > y2) then
 
            return 2;
 
        elseif (x1 < x2 and y1 == y2) then
 
            return 3;
 
        elseif (x1 < x2 and y1 < y2) then
 
            return 4;
 
        elseif (x1 == x2 and y1 < y2) then
 
            return 5;
 
        elseif (x1 > x2 and y1 < y2) then
 
            return 6;
 
        elseif (x1 > x2 and y1 == y2) then
 
            return 7;
 
        elseif (x1 > x2 and y1 > y2) then
 
            return 8;
 
        end;
 
    else
 
        return 9;
 
    end;
 
end;
 

	
 
battlefield = function(tab)
 
    local make_turn = tab.make_turn;
 
    tab.check_walk = function(s)
 
        bf_north:enable();
 
        bf_northeast:enable();
 
        bf_east:enable();
 
        bf_southeast:enable();
 
        bf_south:enable();
 
        bf_southwest:enable();
 
        bf_west:enable();
 
        bf_northwest:enable();
 
        
 
        if (s.plY == 1) then
 
            bf_north:disable();
 
            bf_northeast:disable();
 
            bf_northwest:disable();
 
        elseif (s.plY == 5) then
 
            bf_south:disable();
 
            bf_southeast:disable();
 
            bf_southwest:disable();
 
        end;
 
        
 
        if (s.plX == 1) then
 
            bf_west:disable();
 
            bf_southwest:disable();
 
            bf_northwest:disable();
 
        elseif (s.plX == 5) then
 
            bf_east:disable();
 
            bf_southeast:disable();
 
            bf_northeast:disable();
 
        end;
 
    end;
 
    
 
    local entered = tab.entered;
 
    
 
    tab.entered = function(s)
 
        s:check_walk();
 
        if (type(entered) == 'function') then
 
            entered(s);
 
        else
 
            return entered;
 
        end;
 
    end;
 
    
 
    tab.make_turn = function(s)
 
        for i = 1, #s.obj do
 
            if (type(s.obj[i].make_turn) == 'function') then
 
                s.obj[i]:make_turn();
 
            end;
 
        end;
 
        
 
        if (make_turn) then
 
            make_turn(s);
 
        end;
 
        
 
        s:check_walk();
 
    end;
 
    
 
    tab.getDistance = _kh.bf_calcDistance;
 
    tab.getDirection = _kh.bf_calcDirection;
 
    
 
    if (not tab.obj) then
 
        tab.obj = {};
 
    end;
 
    
 
    if (not tab.pic) then
 
        tab.pic = function(s)
 
            local v = "images/battle_bcg.png;images/player.png@" .. tostring(s.plX * 32 - 32) .. "," .. tostring(s.plY * 32 - 32);
 
            for i = 1, #s.obj do
 
                if (not(s.obj[i]:disabled()) and s.obj[i].pic and s.obj[i].x and s.obj[i].y) then
 
                    v = v .. ";" .. s.obj[i].pic .. "@" .. tostring(s.obj[i].x * 32 - 32) .. "," .. tostring(s.obj[i].y * 32 - 32);
 
                end;
 
            end;
 
            print(v);
 
            return v;
 
        end;
 
    end;
 
    
 
    table.insert(tab.obj, 'bf_north');
 
    table.insert(tab.obj, 'bf_northeast');
 
    table.insert(tab.obj, 'bf_east');
 
    table.insert(tab.obj, 'bf_southeast');
 
    table.insert(tab.obj, 'bf_south');
 
    table.insert(tab.obj, 'bf_southwest');
 
    table.insert(tab.obj, 'bf_west');
 
    table.insert(tab.obj, 'bf_northwest');
 
    table.insert(tab.obj, 'bf_wait');
 

	
 
    return room(tab);
 
end;
 

	
 
bf_north = obj {
 
    nam = "north",
 
    dsc = "{На север}",
 
    act = function(s)
 
        here().plY = here().plY - 1;
 
        p("Вы идете на север");
 
        here():make_turn();
 
    end;
 
};
 

	
 
bf_northeast = obj {
 
    nam = "northeast",
 
    dsc = "{На северо-восток}",
 
    act = function(s)
 
        here().plX = here().plX + 1;
 
        here().plY = here().plY - 1;
 
        p("Вы идете на северо-восток.");
 
        here():make_turn();
 
    end;
 
};
 

	
 
bf_east = obj {
 
    nam = "east",
 
    dsc = "{На восток}",
 
    act = function(s)
 
        here().plX = here().plX + 1;
 
        p("Вы идете на восток.");
 
        here():make_turn();
 
    end;
 
};
 

	
 
bf_southeast = obj {
 
    nam = "southeast",
 
    dsc = "{На юго-восток}",
 
    act = function(s)
 
        here().plX = here().plX + 1;
 
        here().plY = here().plY + 1;
 
        p("Вы идете на юго-восток.");
 
        here():make_turn();
 
    end;
 
};
 

	
 
bf_south = obj {
 
    nam = "south",
 
    dsc = "{На юг}",
 
    act = function(s)
 
        here().plY = here().plY + 1;
 
        p("Вы идете на юг.");
 
        here():make_turn();
 
    end;
 
};
 

	
 
bf_southwest = obj {
 
    nam = "southwest",
 
    dsc = "{На юго-запад}",
 
    act = function(s)
 
        here().plX = here().plX - 1;
 
        here().plY = here().plY + 1;
 
        p("Вы идете на юго-запад.");
 
        here():make_turn();
 
    end;
 
};
 

	
 
bf_west = obj {
 
    nam = "west",
 
    dsc = "{На запад}",
 
    act = function(s)
 
        here().plX = here().plX - 1;
 
        p("Вы идете на запад.");
 
        here():make_turn();
 
    end;
 
};
 

	
 
bf_northwest = obj {
 
    nam = "northwest",
 
    dsc = "{На северо-запад}",
 
    act = function(s)
 
        here().plX = here().plX - 1;
 
        here().plY = here().plY - 1;
 
        p("Вы идете на северо-запад.");
 
        here():make_turn();
 
    end;
 
};
 

	
 
bf_wait = obj {
 
    nam = "wait",
 
    dsc = "{Ждать}",
 
    act = function(s)
 
        p("Вы ждете");
 
        here():make_turn();
 
    end;
 
};
 

	
 
combatant = function(tab)
 
    tab.canshoot = function(s)
 
        local dist = here().getDistance(here().plX, here().plY, s.x, s.y);
 
        return dist < 4 and not tab.ally;
 
    end;
 
    
 
    tab.onshoot = function(s)
 
        local dist = here().getDistance(here().plX, here().plY, s.x, s.y);
 
        
 
        if (rnd(4) > dist) then
 
            if (dist == 0) then
 
                tab.hp = tab.hp - 2;
 
            end;
 
            
 
            tab.hp = tab.hp - 1;
 
            if (tab.hp > 0) then
 
                p(tab.shootHit);
 
            else
 
                p(tab.shootKill);
 
            end;
 
        else
 
            p(tab.shootMiss);
 
        end;
 
        
 
        here():make_turn();
 
    end;
 
    
 
    tab.canhit = function(s)
 
        local dist = here().getDistance(here().plX, here().plY, s.x, s.y);
 
        return dist == 0 and not tab.ally;
 
    end;
 
    
 
    
 
    tab.onhit = function(s)
 
        local dist = here().getDistance(here().plX, here().plY, s.x, s.y);
 
        if (dist == 0) then
 
            tab.hp = tab.hp - 2;
 
            if (tab.hp > 0) then
 
                p(tab.wpnHit);
 
            else
 
                p(tab.wpnKill);
 
            end;
 
            
 
            here():make_turn();
 
        else
 
            p(tab.wpnFar);
 
        end;
 
    end;
 
    
 
    if (not tab.act) then
 
        tab.act = function(s)
 
            if tab.ally then
 
                return tab.nohit;
 
            end;
 
            
 
            local dist = here().getDistance(here().plX, here().plY, s.x, s.y);
 
            
 
            if (dist == 0) then
 
                tab.hp = tab.hp - 1;
 
                if (tab.hp > 0) then
 
                    p(tab.handHit);
 
                else
 
                    p(tab.handKill);
 
                end;
 
                
 
                here():make_turn();
 
            else
 
                p(tab.handFar);
 
            end;
 
        end;
 
    end;
 
    if (not tab.make_turn) then
 
        tab.make_turn = function(s)
 
        end;
 
    end;
 
    
 
    return obj(tab);
 
end;
 
\ No newline at end of file
images/anna.png
Show inline comments
 
new file 100644
 
binary diff not shown
Show images
images/battle_bcg.png
Show inline comments
 
new file 100644
 
binary diff not shown
Show images
images/jack.png
Show inline comments
 
new file 100644
 
binary diff not shown
Show images
images/learr.png
Show inline comments
 
new file 100644
 
binary diff not shown
Show images
images/navjiarr_guard.png
Show inline comments
 
new file 100644
 
binary diff not shown
Show images
images/phaetlarr.png
Show inline comments
 
new file 100644
 
binary diff not shown
Show images
images/player.png
Show inline comments
 
new file 100644
 
binary diff not shown
Show images
images/walter.png
Show inline comments
 
new file 100644
 
binary diff not shown
Show images
items.lua
Show inline comments
 
@@ -76,12 +76,17 @@ item_colt = obj {
 
				Вы перезаряжаете ваш револьвер и оружие снова готово к бою
 
			]];
 
		end;
 
	end;
 
};
 
 
item_harpoon = obj {
 
    nam = "item_harpoon";
 
    
 
};
 
 
item_first_city_key = obj {
 
	nam = "first_city_key";
 
	disp = "Ключ от города";
 
	inv = [[
 
		Небольшой светящийся кубик со стороной около 2-х сантиметров. Он плавно меняет цвета: синий, зеленый, желтый, белый, красный, черный.
 
	]];
journey_zayslanotrr.lua
Show inline comments
 
@@ -55,8 +55,72 @@ za_gate = dlg {
 
        {"[Двигаться вдоль стен]", ""};
 
        {"[Отправиться в другое место]", code = [[
 
            walk("leviathan_wheelhouse");
 
        ]]};
 
        {"[Отойти от штурвала]"};
 
    };
 
};
 
    
 
};
 
\ No newline at end of file
 
za_plaetlarr_fight = battlefield {
 
    nam = "Заисланотр, улица";
 
    plX = 3;
 
    plY = 1;
 
    entered = function(s)
 
        --TODO prepend player associate - anna, learr, walter or jack
 
    end;
 
    obj = {
 
        'za_cmbt_phaetlarr',
 
        'za_cmbt_guard1',
 
        'za_cmbt_guard2',
 
        'za_cmbt_guard3',
 
        'za_cmbt_guard4'
 
    };
 
};
 
 
 
za_cmbt_phaetlarr = combatant {
 
    nam = "za_cmbt_phaetlarr";
 
    x = 3;
 
    y = 5;
 
    pic = "images/phaetlarr.png";
 
    ally = "Я не буду атаковать союзника.";
 
    nohit = "Я не буду атаковать союзника.";
 
    noshoot = "Я не буду атаковать союзника.";
 
    hp = 10;
 
    make_turn = function(s)
 
        p("socking socks");
 
    end;
 
    dsc = function(s)
 
        return [[ Моя {тут}. ]];
 
    end;
 
};
 

	
 
za_cmbt_guard = function(nam, x, y) 
 
    return combatant {
 
        nam = nam;
 
        x = x;
 
        y = y;
 
        hp = 8;
 
        pic = "images/navjiarr_guard.png";
 
        shootHit = "Вы стреляете в стражника и попадаете в него. ";
 
        shootMiss = "Вы стреляете в стражника, но не попадаете в него. ";
 
        shootKill = "Вы стреляете в стражника и он падает замертво. ";
 
        handHit = "Вы ударяете стражника. ";
 
        handKill = "После вашего удара стражник падает. ";
 
        handFar = "Слишком далеко. ";
 
        dsc = function(s)
 
            return [[
 
                Моя {здеся}.
 
            ]];
 
        end;
 
        make_turn = function(s)
 
            if (s.hp <= 0) then
 
                s:disable();
 
            end;
 
            p("staring madly");
 
        end;
 
    };
 
end;
 

	
 
za_cmbt_guard1 = za_cmbt_guard("za_cmbt_guard1", 1, 4);
 
za_cmbt_guard2 = za_cmbt_guard("za_cmbt_guard2", 2, 4);
 
za_cmbt_guard3 = za_cmbt_guard("za_cmbt_guard3", 4, 4);
 
za_cmbt_guard4 = za_cmbt_guard("za_cmbt_guard4", 5, 4);
main.lua
Show inline comments
 
@@ -8,12 +8,13 @@ require "dash"
 
require "quotes"
 
require "hideinv"
 
require "kbd"
 
 
-- Код и ядро
 
dofile "utils.lua"
 
dofile "battlefield.lua";
 
-- Общее
 
dofile "items.lua"
 
dofile "party.lua"
 
dofile "game_over.lua";
 
-- Часть 1
 
dofile "london.lua"
 
@@ -219,13 +220,13 @@ function init()
 
	move(submarine_leviathan, "atl_aqua_leviathan_dock");
 
    submarine_leviathan:enable();   
 
    	   
 
    --ven_temple_l1.position = "66";   
 
    put(item_ven_tablet, pl);
 
    --ven_shark.position = "55";
 
	pl.where = "ven_towers_machine_look";
 
	pl.where = "za_plaetlarr_fight";
 
    move(submarine_leviathan, "ven_center");
 
    --pl.where = "ven_chest_look";
 
    --move(ven_shark, "ven_temple_l1");
 
    
 
	--put(item_suit, pl);
 
	
0 comments (0 inline, 0 general)