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

Better smooth movement

git-svn-id: http://svn.net-core.org/repos/t-engine4@4817 51575b47-30f0-44d4-a5cc-537603b46e54
parent c36b1745
No related branches found
No related tags found
No related merge requests found
......@@ -325,6 +325,8 @@ end
--- Redisplays the map, storing seen information
function _M:redisplay()
self:checkMapViewBounded()
self._map:setScroll(self.mx, self.my, 0)
for i = 0, self.w - 1 do for j = 0, self.h - 1 do
self._map:setSeen(i, j, self.seens(i, j))
self._map:setRemember(i, j, self.remembers(i, j))
......@@ -769,7 +771,8 @@ function _M:checkMapViewBounded()
if self.w < self.viewport.mwidth then self.mx = math.floor((self.w - self.viewport.mwidth) / 2) centered = true self.changed = true end
if self.h < self.viewport.mheight then self.my = math.floor((self.h - self.viewport.mheight) / 2) centered = true self.changed = true end
self._map:setScroll(self.mx, self.my, centered and 0 or self.smooth_scroll)
-- self._map:setScroll(self.mx, self.my, centered and 0 or self.smooth_scroll)
self._map:setScroll(self.mx, self.my, self.smooth_scroll)
end
--- Scrolls the map in the given direction
......@@ -778,7 +781,7 @@ function _M:scrollDir(dir)
self.mx, self.my = util.coordAddDir(self.mx, self.my, dir)
self.mx = util.bound(self.mx, 0, self.w - self.viewport.mwidth)
self.my = util.bound(self.my, 0, self.h - self.viewport.mheight)
self._map:setScroll(self.mx, self.my, self.smooth_scroll)
self:checkMapViewBounded()
end
--- Gets the tile under the mouse
......@@ -813,8 +816,8 @@ end
--- Get the screen offset where to start drawing (upper corner)
function _M:getScreenUpperCorner()
local sx, sy = self._map:getScroll()
local x = -self.mx * self.tile_w * self.zoom + self.display_x + sx * self.tile_w * zoom
local y = -self.my * self.tile_h * self.zoom + self.display_y + sy * self.tile_h * zoom
local x = -self.mx * self.tile_w * self.zoom + self.display_x + sx * zoom
local y = -self.my * self.tile_h * self.zoom + self.display_y + sy * zoom
return x, y
end
......@@ -1135,10 +1138,11 @@ end
function _M:displayEmotes(nb_keyframes)
local del = {}
local e = next(self.emotes)
local sx, sy = self._map:getScroll()
while e do
-- Dont bother with obviously out of screen stuff
if e.x >= self.mx and e.x < self.mx + self.viewport.mwidth and e.y >= self.my and e.y < self.my + self.viewport.mheight and self.seens(e.x, e.y) then
e:display(self.display_x + (e.x - self.mx + 0.5) * self.tile_w * self.zoom, self.display_y + (e.y - self.my - 0.9) * self.tile_h * self.zoom)
e:display(self.display_x + sx + (e.x - self.mx + 0.5) * self.tile_w * self.zoom, self.display_y + sy + (e.y - self.my - 0.9) * self.tile_h * self.zoom)
end
for i = 1, nb_keyframes do
......
......@@ -74,7 +74,8 @@ function _M:display(dispx, dispy)
self.target.y = self.target.y or self.source_actor.y
local ox, oy = self.display_x, self.display_y
self.display_x, self.display_y = dispx or self.display_x, dispy or self.display_y
local sx, sy = game.level.map._map:getScroll()
self.display_x, self.display_y = dispx or sx or self.display_x, dispy or sy or self.display_y
-- self.cursor:toScreen(self.display_x + (self.target.x - game.level.map.mx) * self.tile_w * Map.zoom, self.display_y + (self.target.y - game.level.map.my) * self.tile_h * Map.zoom, self.tile_w * Map.zoom, self.tile_h * Map.zoom)
......
......@@ -726,6 +726,7 @@ function _M:changeLevel(lev, zone, keep_old_lev, force_down, auto_zone_stair)
end
self.player:onEnterLevel(self.zone, self.level)
self.player:resetMoveAnim()
local musics = {}
local keep_musics = false
......
......@@ -543,6 +543,9 @@ end
--- Tries to get a target from the user
function _M:getTarget(typ)
if self:attr("encased_in_ice") then
if type(typ) ~= "table" then
return self.x, self.y, self
end
local orig_range = typ.range
typ.range = 0
local x, y, act = game:targetGetForPlayer(typ)
......
......@@ -708,7 +708,7 @@ function _M:autoExplore()
elseif terrain.mindam or terrain.maxdam then
move_cost = move_cost + 32
is_slow = true
elseif terrain.air_level and terrain.air_level < 0 and not self.can_breath.water then
elseif terrain.air_level and terrain.air_level < 0 and not ((self.can_breath.water or 0) > 0) then
move_cost = move_cost + 15
is_slow = true
end
......
......@@ -980,8 +980,8 @@ static int map_draw_seen_texture(lua_State *L)
int my = map->my;
// x -= map->tile_w * (map->used_animdx + map->used_mx);
// y -= map->tile_h * (map->used_animdy + map->used_my);
x -= map->tile_w * (map->used_animdx + map->mx);
y -= map->tile_h * (map->used_animdy + map->my);
x -= map->tile_w * (map->used_animdx + map->oldmx);
y -= map->tile_h * (map->used_animdy + map->oldmy);
tglBindTexture(GL_TEXTURE_2D, map->seens_texture);
......@@ -1044,13 +1044,18 @@ static int map_set_scroll(lua_State *L)
// Already moving, compute starting point
else
{
map->oldmx = map->oldmx - map->used_animdx;
map->oldmy = map->oldmy - map->used_animdy;
map->oldmx = map->oldmx + map->used_animdx;
map->oldmy = map->oldmy + map->used_animdy;
}
map->move_step = 0;
map->move_max = smooth;
} else {
map->oldmx = x;
map->oldmy = y;
}
map->move_step = 0;
map->move_max = smooth;
map->used_animdx = 0;
map->used_animdy = 0;
map->mx = x;
map->my = y;
map->seen_changed = TRUE;
......@@ -1060,8 +1065,8 @@ static int map_set_scroll(lua_State *L)
static int map_get_scroll(lua_State *L)
{
map_type *map = (map_type*)auxiliar_checkclass(L, "core{map}", 1);
lua_pushnumber(L, -map->used_animdx);
lua_pushnumber(L, -map->used_animdy);
lua_pushnumber(L, -map->tile_w*(map->used_animdx + map->oldmx - map->mx));
lua_pushnumber(L, -map->tile_h*(map->used_animdy + map->oldmy - map->my));
return 2;
}
......@@ -1313,15 +1318,15 @@ static int map_to_screen(lua_State *L)
{
float adx = (float)map->mx - map->oldmx;
float ady = (float)map->my - map->oldmy;
animdx = adx * map->move_step / (float)map->move_max - adx;
animdy = ady * map->move_step / (float)map->move_max - ady;
mx = map->mx + (int)(adx * map->move_step / (float)map->move_max - adx);
my = map->my + (int)(ady * map->move_step / (float)map->move_max - ady);
animdx = adx * map->move_step / (float)map->move_max;
animdy = ady * map->move_step / (float)map->move_max;
mx = (int)(map->oldmx + animdx);
my = (int)(map->oldmy + animdy);
}
changed = TRUE;
}
x -= map->tile_w * animdx;
y -= map->tile_h * animdy;
x -= map->tile_w * (animdx + map->oldmx);
y -= map->tile_h * (animdy + map->oldmy);
map->used_animdx = animdx;
map->used_animdy = animdy;
......@@ -1337,8 +1342,8 @@ static int map_to_screen(lua_State *L)
{
if ((i < 0) || (j < 0) || (i >= map->w) || (j >= map->h)) continue;
int dx = x + (i - map->mx) * map->tile_w;
int dy = y + (j - map->my) * map->tile_h;
int dx = x + i * map->tile_w;
int dy = y + j * map->tile_h;
map_object *mo = map->grids[i][j][z];
if (!mo) continue;
......
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