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

plop

git-svn-id: http://svn.net-core.org/repos/t-engine4@2479 51575b47-30f0-44d4-a5cc-537603b46e54
parent 7728a382
No related branches found
No related tags found
No related merge requests found
......@@ -725,6 +725,14 @@ function _M:isOnScreen(x, y)
return false
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
local y = -self.my * self.tile_h * self.zoom + self.display_y + sy
return x, y
end
--- Import a map into the current one
-- @param map the map to import
-- @param dx coordinate where to import it in the current map
......
......@@ -82,13 +82,13 @@ return {
local Map = require "engine.Map"
local Particles = require("engine.Particles")
local ps = {}
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=5, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_01"})
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=5, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_02"})
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=5, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_03"})
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=5, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_04"})
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=5, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_05"})
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=5, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_06"})
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=5, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_07"})
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=20, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_01"})
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=20, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_02"})
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=20, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_03"})
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=20, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_04"})
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=20, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_05"})
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=20, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_06"})
ps[#ps+1] = Particles.new("weather_storm", 1, {max_nb=20, width=level.map.w*level.map.tile_w, height=level.map.h*level.map.tile_h, speed={0.5, 1.6}, alpha={0.23, 0.35}, particle_name="weather/grey_cloud_07"})
level.foreground_particle = ps
end,
......@@ -96,7 +96,7 @@ return {
local Map = require "engine.Map"
local ps = level.foreground_particle
local dx, dy = level.map:getTileToScreen(0, 0) -- Display at map border, always, so it scrolls with the map
local dx, dy = level.map:getScreenUpperCorner() -- Display at map border, always, so it scrolls with the map
for j = 1, #ps do
for i = 1, nb_keyframes do
ps[j]:update()
......
......@@ -729,6 +729,43 @@ static int map_set_scroll(lua_State *L)
return 0;
}
#define SMOOTH_SCROLL() \
float animdx = 0, animdy = 0; \
int mx = map->mx; \
int my = map->my; \
if (map->move_max) \
{ \
map->move_step += nb_keyframes; \
if (map->move_step >= map->move_max) \
{ \
map->move_max = 0; \
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); \
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); \
} \
}
static int map_get_scroll(lua_State *L)
{
map_type *map = (map_type*)auxiliar_checkclass(L, "core{map}", 1);
int nb_keyframes = 1;
SMOOTH_SCROLL();
lua_pushnumber(L, -animdx);
lua_pushnumber(L, -animdy);
return 2;
}
#define DO_QUAD(dx, dy, zoom, r, g, b, a) {\
vertices[(*vert_idx)] = (dx); vertices[(*vert_idx)+1] = (dy); \
vertices[(*vert_idx)+2] = map->tile_w * (zoom) + (dx); vertices[(*vert_idx)+3] = (dy); \
......@@ -902,29 +939,7 @@ static int map_to_screen(lua_State *L)
glColorPointer(4, GL_FLOAT, 0, colors);
// Smooth scrolling
float animdx = 0, animdy = 0;
int mx = map->mx;
int my = map->my;
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);
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);
}
}
SMOOTH_SCROLL();
x -= animdx;
y -= animdy;
......@@ -1084,6 +1099,7 @@ static const struct luaL_reg map_reg[] =
{"setRemember", map_set_remember},
{"setLite", map_set_lite},
{"setScroll", map_set_scroll},
{"getScroll", map_get_scroll},
{"toScreen", map_to_screen},
{"toScreenMiniMap", minimap_to_screen},
{"setupMiniMapGridSize", map_set_minimap_gridsize},
......
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