diff --git a/game/engines/default/engine/Map.lua b/game/engines/default/engine/Map.lua index a96876c30cc1fda5460f6e2373fb1d6de071db63..f49adc0ac1f64f8e1bd6638f61c3709d19374cd0 100644 --- a/game/engines/default/engine/Map.lua +++ b/game/engines/default/engine/Map.lua @@ -515,8 +515,8 @@ function _M:display(x, y, nb_keyframe) local z local adx, ady local friend - for i = self.mx, self.mx + self.viewport.mwidth - 1 do - for j = self.my, self.my + self.viewport.mheight - 1 do + for i = self.mx, self.mx + self.viewport.mwidth do + for j = self.my, self.my + self.viewport.mheight do local z = i + j * self.w if self.seens[z] then @@ -687,6 +687,28 @@ end --- Sets the current view area if x and y are out of bounds function _M:moveViewSurround(x, y, marginx, marginy) local omx, omy = self.mx, self.my + + if marginx * 2 > self.viewport.mwidth then + self.mx = x - math.floor(self.viewport.mwidth / 2) + self.changed = true + elseif self.mx + marginx >= x then + self.mx = x - marginx + self.changed = true + elseif self.mx + self.viewport.mwidth - marginx <= x then + self.mx = x - self.viewport.mwidth + marginx + self.changed = true + end + if marginy * 2 > self.viewport.mheight then + self.my = y - math.floor(self.viewport.mheight / 2) + self.changed = true + elseif self.my + marginy >= y then + self.my = y - marginy + self.changed = true + elseif self.my + self.viewport.mheight - marginy <= y then + self.my = y - self.viewport.mheight + marginy + self.changed = true + end +--[[ if self.mx + marginx >= x or self.mx + self.viewport.mwidth - marginx <= x then self.mx = x - math.floor(self.viewport.mwidth / 2) self.changed = true @@ -695,6 +717,7 @@ function _M:moveViewSurround(x, y, marginx, marginy) self.my = y - math.floor(self.viewport.mheight / 2) self.changed = true end +]] self:checkMapViewBounded() return self.mx - omx, self.my - omy end diff --git a/src/map.c b/src/map.c index 0a56e79fae645cb5feadb064a53d75ac9a4001ac..0db75ae1035bf7fe2db3016b33b0815db07f6af2 100644 --- a/src/map.c +++ b/src/map.c @@ -695,8 +695,20 @@ static int map_set_scroll(lua_State *L) if (smooth) { - map->oldmx = map->mx; - map->oldmy = map->my; + // Not moving, use starting point + if (!map->move_max) + { + map->oldmx = map->mx; + map->oldmy = map->my; + } + // Already moving, compute starting point + else + { + float adx = map->mx - map->oldmx; + float ady = map->my - map->oldmy; + map->oldmx = -adx * map->move_step / (float)map->move_max + map->mx; + map->oldmy = -ady * map->move_step / (float)map->move_max + map->my; + } map->move_step = 0; map->move_max = smooth; }