Skip to content
Snippets Groups Projects
Commit ae4a9e40 authored by dg's avatar dg
Browse files

Map smooth scrolling

git-svn-id: http://svn.net-core.org/repos/t-engine4@2325 51575b47-30f0-44d4-a5cc-537603b46e54
parent eb0f5ceb
No related branches found
No related tags found
No related merge requests found
......@@ -59,6 +59,7 @@ end
color_shown = { 1, 1, 1, 1 }
color_obscure = { 0.6, 0.6, 0.6, 1 }
smooth_scroll = 0
-- The minimap data
MM_FLOOR = 1
......@@ -525,7 +526,7 @@ function _M:display(x, y, nb_keyframe)
if e.faction then
if not self.actor_player then friend = Faction:factionReaction(self.view_faction, e.faction)
else friend = self.actor_player:reactionToward(e) end
if e._mo then adx, ady = e._mo:getMoveAnim(i, j) else adx, ady = 0, 0 end -- Make sure we display on the real screen coords: handle current move anim position
if e._mo then adx, ady = e._mo:getMoveAnim(self._map, i, j) else adx, ady = 0, 0 end -- Make sure we display on the real screen coords: handle current move anim position
if friend > 0 then
self.tilesTactic:get(nil, 0,0,0, 0,0,0, self.faction_friend):toScreen(self.display_x + (adx + i - self.mx) * self.tile_w * self.zoom, self.display_y + (ady + j - self.my) * self.tile_h * self.zoom, self.tile_w * self.zoom, self.tile_h * self.zoom)
elseif friend < 0 then
......@@ -709,7 +710,7 @@ function _M:checkMapViewBounded()
if self.w < self.viewport.mwidth then self.mx = math.floor((self.w - self.viewport.mwidth) / 2) end
if self.h < self.viewport.mheight then self.my = math.floor((self.h - self.viewport.mheight) / 2) end
self._map:setScroll(self.mx, self.my)
self._map:setScroll(self.mx, self.my, self.smooth_scroll)
end
--- Gets the tile under the mouse
......@@ -965,7 +966,7 @@ function _M:displayParticles(nb_keyframes)
local del = {}
local e = next(self.particles)
while e do
if e._mo then adx, ady = e._mo:getMoveAnim(e.x, e.y) else adx, ady = 0, 0 end -- Make sure we display on the real screen coords: handle current move anim position
if e._mo then adx, ady = e._mo:getMoveAnim(self._map, e.x, e.y) else adx, ady = 0, 0 end -- Make sure we display on the real screen coords: handle current move anim position
if nb_keyframes == 0 and e.x and e.y then
-- Just display it, not updating, no emitting
......
......@@ -332,7 +332,7 @@ function _M:spawnWorldAmbush(enc)
floor = "GRASS",
wall = "TREE",
down = "DOWN",
up = "UP_WILDERNESS",
up = "GRASS_UP_WILDERNESS",
}
local g = game.level.map(game.player.x, game.player.y, engine.Map.TERRAIN)
if not g.can_encounter then return false end
......
game/modules/tome/data/gfx/shockbolt/terrain/maze_floor.png

9.56 KiB

game/modules/tome/data/gfx/shockbolt/terrain/maze_floor_2.png

9.57 KiB

game/modules/tome/data/gfx/shockbolt/terrain/maze_floor_3.png

9.57 KiB

game/modules/tome/data/gfx/shockbolt/terrain/maze_floor_4.png

9.55 KiB

......@@ -46,7 +46,7 @@ return {
pond = {{0.6, "DEEP_WATER"}, {0.8, "SHALLOW_WATER"}},
},
nb_rooms = {5},
nb_rooms = {0,0,0,1},
rooms = {"lesser_vault"},
lesser_vaults_list = {"honey_glade", "forest-ruined-building1", "forest-ruined-building2", "forest-ruined-building3", "forest-snake-pit", "mage-hideout-dark"},
lite_room_chance = 100,
......
......@@ -96,6 +96,7 @@ function _M:generateList()
game:registerDialog(GetQuantity.new("Enter movement speed(lower is faster)", "From 0 to 60", config.settings.tome.smooth_move, 60, function(qty)
game:saveSettings("tome.smooth_move", ("tome.smooth_move = %d\n"):format(qty))
config.settings.tome.smooth_move = qty
engine.Map.smooth_scroll = qty
self.c_list:drawItem(item)
end))
end,}
......
......@@ -28,7 +28,7 @@ Entity.ascii_outline = {x=2, y=2, r=0, g=0, b=0, a=0.8}
local KeyBind = require "engine.KeyBind"
local DamageType = require "engine.DamageType"
local Faction = require "engine.Faction"
local Map = require "engine.Map"
local ActorStats = require "engine.interface.ActorStats"
local ActorResource = require "engine.interface.ActorResource"
local ActorTalents = require "engine.interface.ActorTalents"
......@@ -184,5 +184,6 @@ end
if type(config.settings.tome.autosave) == "nil" then config.settings.tome.autosave = true end
if not config.settings.tome.smooth_move then config.settings.tome.smooth_move = 3 end
if not config.settings.tome.gfx then config.settings.tome.gfx = {size="32x32", tiles="mushroom"} end
Map.smooth_scroll = config.settings.tome.smooth_move
return {require "mod.class.Game", require "mod.class.World"}
......@@ -190,20 +190,30 @@ static int map_object_set_move_anim(lua_State *L)
static int map_object_get_move_anim(lua_State *L)
{
map_object *obj = (map_object*)auxiliar_checkclass(L, "core{mapobj}", 1);
int i = luaL_checknumber(L, 2);
int j = luaL_checknumber(L, 3);
map_type *map = (map_type*)auxiliar_checkclass(L, "core{map}", 2);
int i = luaL_checknumber(L, 3);
int j = luaL_checknumber(L, 4);
float mapdx = 0, mapdy = 0;
if (map->move_max)
{
float adx = (float)map->mx - map->oldmx;
float ady = (float)map->my - map->oldmy;
mapdx = map->tile_w * (adx * map->move_step / (float)map->move_max - adx);
mapdy = map->tile_h * (ady * map->move_step / (float)map->move_max - ady);
}
if (!obj->move_max || obj->display_last == DL_NONE)
{
lua_pushnumber(L, 0);
lua_pushnumber(L, 0);
lua_pushnumber(L, mapdx);
lua_pushnumber(L, mapdy);
}
else
{
float adx = (float)i - obj->oldx;
float ady = (float)j - obj->oldy;
lua_pushnumber(L, (adx * obj->move_step / (float)obj->move_max - adx));
lua_pushnumber(L, (ady * obj->move_step / (float)obj->move_max - ady));
lua_pushnumber(L, mapdx + (adx * obj->move_step / (float)obj->move_max - adx));
lua_pushnumber(L, mapdy + (ady * obj->move_step / (float)obj->move_max - ady));
}
return 2;
}
......@@ -681,6 +691,15 @@ static int map_set_scroll(lua_State *L)
map_type *map = (map_type*)auxiliar_checkclass(L, "core{map}", 1);
int x = luaL_checknumber(L, 2);
int y = luaL_checknumber(L, 3);
int smooth = luaL_checknumber(L, 4);
if (smooth)
{
map->oldmx = map->mx;
map->oldmy = map->my;
map->move_step = 0;
map->move_max = smooth;
}
map->mx = x;
map->my = y;
......@@ -775,6 +794,8 @@ void display_map_quad(map_type *map, int dx, int dy, float dz, map_object *m, in
m->display_last = DL_TRUE;
}
#define MIN(a,b) ((a < b) ? a : b)
static int map_to_screen(lua_State *L)
{
map_type *map = (map_type*)auxiliar_checkclass(L, "core{map}", 1);
......@@ -786,11 +807,39 @@ static int map_to_screen(lua_State *L)
/* Enables Depth Testing */
glEnable(GL_DEPTH_TEST);
// Smooth scrolling
float animdx = 0, animdy = 0;
if (map->move_max)
{
map->move_step += nb_keyframes;
if (map->move_step >= map->move_max)
{
map->move_max = 0; // Reset once in place
map->oldmx = map->mx;
map->oldmy = map->my;
}
if (map->move_max)
{
float adx = (float)map->mx - map->oldmx;
float ady = (float)map->my - map->oldmy;
animdx = map->tile_w * (adx * map->move_step / (float)map->move_max - adx);
animdy = map->tile_h * (ady * map->move_step / (float)map->move_max - ady);
}
}
x -= animdx;
y -= animdy;
// Always display some more of the map to make sure we always see it all
int smx = MIN(map->mx, map->oldmx) - 1;
int smy = MIN(map->my, map->oldmy) - 1;
int emx = smx + abs(map->mx - map->oldmx) + 2;
int emy = smy + abs(map->my - map->oldmy) + 2;
for (z = 0; z < map->zdepth; z++)
{
for (j = map->my; j < map->my + map->mheight; j++)
for (j = smy; j < emy + map->mheight; j++)
{
for (i = map->mx; i < map->mx + map->mwidth; i++)
for (i = smx; i < emx + map->mwidth; i++)
{
if ((i < 0) || (j < 0) || (i >= map->w) || (j >= map->h)) continue;
......
......@@ -68,6 +68,8 @@ typedef struct {
// Scrolling
int mx, my, mwidth, mheight;
float oldmx, oldmy;
int move_step, move_max;
} map_type;
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment