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

rebalance

particles
trolls


git-svn-id: http://svn.net-core.org/repos/t-engine4@211 51575b47-30f0-44d4-a5cc-537603b46e54
parent 987d6b2c
No related branches found
No related tags found
No related merge requests found
Showing
with 317 additions and 12 deletions
game/data/gfx/particle.png

827 B

......@@ -56,7 +56,6 @@ function _M:display()
s:toScreen(self.display_x + (lx - game.level.map.mx) * self.tile_w, self.display_y + (ly - game.level.map.my) * self.tile_h)
lx, ly = l()
end
print(self.display_x, self.display_y, "::", self.display_x + (self.target.x - game.level.map.mx) * self.tile_w, self.display_y + (self.target.y - game.level.map.my) * self.tile_h)
self.cursor:toScreen(self.display_x + (self.target.x - game.level.map.mx) * self.tile_w, self.display_y + (self.target.y - game.level.map.my) * self.tile_h, self.tile_w, self.tile_h)
if s == self.b then stopx, stopy = self.target.x, self.target.y end
......
......@@ -9,6 +9,7 @@ function _M:init(zone, map, grid_list, data)
self.data.tunnel_change = self.data.tunnel_change or 30
self.data.tunnel_random = self.data.tunnel_random or 10
self.data.door_chance = self.data.door_chance or 50
self.data.lite_room_chance = self.data.lite_room_chance or 25
self.grid_list = grid_list
self.rooms = {}
......@@ -79,6 +80,8 @@ function _M:roomAlloc(room, id)
end
if ok then
local is_lit = rng.percent(self.data.lite_room_chance)
-- ok alloc it
for i = 1, room.w do
for j = 1, room.h do
......@@ -91,6 +94,7 @@ function _M:roomAlloc(room, id)
else
self.map(i-1+x, j-1+y, Map.TERRAIN, self.grid_list[self:resolve(c)])
end
if is_lit then self.map.lites(i-1+x, j-1+y, true) end
end
end
print("room allocated at", x, y,"with center",math.floor(x+(room.w-1)/2), math.floor(y+(room.h-1)/2))
......
......@@ -6,6 +6,7 @@ dofile("/engine/colors.lua")
dofile("/engine/resolvers.lua")
require "config"
require "engine.Game"
require "engine.KeyCommand"
require "engine.Savefile"
require "engine.Tiles"
......@@ -22,6 +23,7 @@ fs.setWritePath(fs.getHomePath())
fs.mount(engine.homepath, "/")
config.loadString[[
keyboard.locale = "en_US"
window.size = "1024x768"
]]
config.load("/settings.cfg")
fs.umount(engine.homepath)
......@@ -33,4 +35,6 @@ key:setCurrent()
-- Load the game module
game = false
engine.Game:setResolution(config.settings.window.size)
util.showMainMenu()
......@@ -35,3 +35,17 @@ function resolvers.calc.talents(t, e)
for tid, level in pairs(t[1]) do ts[tid] = level end
return ts
end
--- Talents masteries
function resolvers.tmasteries(list)
return {__resolver="tmasteries", list}
end
function resolvers.calc.tmasteries(t, e)
local ts = {}
for tt, level in pairs(t[1]) do
assert(e.talents_types_def[tt], "unknown talent type "..tt)
e.talents_types[tt] = true
e.talents_types_mastery[tt] = level
end
return nil
end
......@@ -104,7 +104,6 @@ end
function _M:onResolutionChange()
print("[RESOLUTION] changed to ", self.w, self.h)
self:setupDisplayMode()
print(self.level.map.display_x, self.level.map.display_y)
self.flash:resize(0, 0, self.w, 20)
self.logdisplay:resize(0, self.h * 0.8, self.w * 0.5, self.h * 0.2)
self.player_display:resize(0, 20, 200, self.h * 0.8 - 20)
......
......@@ -126,7 +126,7 @@ function _M:attackTargetWith(target, weapon, damtype, mult)
-- If hit is over 0 it connects, if it is 0 we still have 50% chance
local hitted = false
if self:checkHit(atk, def) then
local dam = dam - math.max(0, armor - apr)
local dam = math.max(0, dam - math.max(0, armor - apr))
local damrange = self:combatDamageRange(weapon)
dam = rng.range(dam, dam * damrange)
print("[ATTACK] after range", dam)
......@@ -236,7 +236,7 @@ end
--- Gets spellspeed
function _M:combatSpellSpeed()
return self.combat_spellspeed or 1
return self.combat_spellspeed + 1
end
--- Computes physical crit for a damage
......
......@@ -4,9 +4,11 @@ setDefaultProjector(function(src, x, y, type, dam)
if target then
-- Reduce damage with resistance
local res = target.resists[type] or 0
print("[PROJECTOR] res", res, (100 - res) / 100, " on dam", dam)
if res >= 100 then dam = 0
else dam = dam / (100 * (100 - res))
else dam = dam * ((100 - res) / 100)
end
print("[PROJECTOR] final dam", dam)
local flash = game.flash.NEUTRAL
if target == game.player then flash = game.flash.BAD end
......
......@@ -16,6 +16,8 @@ newEntity{
energy = { mod=1 },
stats = { str=14, dex=12, mag=10, con=12 },
tmasteries = resolvers.tmasteries{ ["physical/other"]=0.3, ["physical/2hweapon"]=0.3 },
blind_immune = 1,
see_invisible = 2,
}
......
......@@ -5,10 +5,9 @@ newEntity{
type = "giant", subtype = "troll",
display = "T", color=colors.UMBER,
combat = { dam=resolvers.rngavg(15,25), atk=3, apr=6, physspeed=1.2 },
combat = { dam=resolvers.rngavg(15,20), atk=2, apr=6, physspeed=2 },
body = { INVEN = 10, MAINHAND=1, OFFHAND=1, BODY=1 },
equipment = resolvers.equip{ {type="weapon", subtype="greatsword"} },
drops = resolvers.drops{chance=20, nb=1, {} },
life_rating = 15,
......@@ -20,6 +19,8 @@ newEntity{
energy = { mod=1 },
stats = { str=20, dex=8, mag=6, con=16 },
tmasteries = resolvers.tmasteries{ ["physical/other"]=0.3 },
resists = { [DamageType.FIRE] = -50 },
}
......
......@@ -28,7 +28,7 @@ newTalent{
local x, y = self:getTarget(tg)
if not x or not y then return nil end
self:project(tg, x, y, DamageType.COLD, self:spellCrit(12 + self:combatSpellpower(0.25) * self:getTalentLevel(t)))
self:project(tg, x, y, DamageType.FREEZE, 2 + math.floor(self:getTalentLevel(t) / 3))
self:project(tg, x, y, DamageType.FREEZE, 3 + math.floor(self:getTalentLevel(t) / 3))
return true
end,
require = { stat = { mag=14 }, },
......
......@@ -12,6 +12,7 @@ return {
class = "engine.generator.map.Roomer",
nb_rooms = 10,
rooms = {"simple", "pilar"},
lite_room_chance = 100,
['.'] = "FLOOR",
['#'] = "WALL",
up = "UP",
......@@ -27,8 +28,9 @@ return {
},
object = {
class = "engine.generator.object.Random",
nb_object = {2, 5},
nb_object = {4, 6},
ood = {chance=5, range={1, 10}},
filters = { {type="potion" }, {type="potion" }, {type="potion" }, {type="scroll" }, {}, {} }
},
},
levels =
......
......@@ -5,7 +5,7 @@ return {
max_level = 5,
width = 50, height = 50,
-- all_remembered = true,
-- all_lited = true,
all_lited = true,
-- persistant = true,
generator = {
map = {
......@@ -27,8 +27,9 @@ return {
},
object = {
class = "engine.generator.object.Random",
nb_object = {200, 500},
nb_object = {4, 6},
ood = {chance=5, range={1, 10}},
filters = { {type="potion" }, {type="potion" }, {type="potion" }, {type="scroll" }, {}, {} }
},
},
levels =
......
......@@ -23,17 +23,45 @@ function _M:run()
-- Ok everything is good to go, activate the game in the engine!
self:setCurrent()
self.particle = core.display.loadImage("/data/gfx/particle.png")
self.gl = self.particle:glTexture()
self.test = core.particles.newEmitter(1000, {
base = 1000,
angle = { 10, 60 }, anglev = { 3, 3000 }, anglea = { 1, 1000 },
life = { 30, 30 },
size = { 3, 50 }, sizev = {0, 0}, sizea = {0, 0},
-- x_min = 0, x_max = 0,
-- y_min = 0, y_max = 0,
r = {0, 0}, rv = {0, 0}, ra = {0, 0},
g = {0, 0}, gv = {0, 0}, ga = {0, 0},
b = {255, 255}, bv = {0, 0}, ba = {10, 50},
a = {0, 0}, av = {0, 0}, aa = {0, 0},
}, self.gl)
self.cnt = 0
end
function _M:display()
--[[
if self.background then
local bw, bh = self.background:getSize()
self.background:toScreen((self.w - bw) / 2, (self.h - bh) / 2)
end
]]
self.step:display()
self.step:toScreen(self.step.display_x, self.step.display_y)
engine.Game.display(self)
self.cnt = self.cnt + 1
-- if self.cnt < 10 then
self.test:emit(100)
-- end
self.test:toScreen(600, 600)
end
--- Skip to a module directly ?
......
......@@ -400,6 +400,7 @@ int main(int argc, char *argv[])
luaopen_profiler(L);
luaopen_lanes(L);
luaopen_map(L);
luaopen_particles(L);
// Make the uids repository
lua_newtable(L);
......
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "auxiliar.h"
#include "types.h"
#include "particles.h"
#include "script.h"
#include <math.h>
#include <SDL.h>
#include <SDL_ttf.h>
#define rng(x, y) (x + rand_div(1 + y - x))
static bool getfield(const char *key, float *min, float *max)
{
double result;
lua_pushstring(L, key);
lua_gettable(L, -2);
lua_pushnumber(L, 1);
lua_gettable(L, -2);
*min = (float)lua_tonumber(L, -1);
lua_pop(L, 1);
lua_pushnumber(L, 2);
lua_gettable(L, -2);
*max = (float)lua_tonumber(L, -1);
lua_pop(L, 1);
printf("%s :: %f %f\n", key, (float)*min, (float)*max);
lua_pop(L, 1);
return result;
}
static int particles_new(lua_State *L)
{
int nb = luaL_checknumber(L, 1);
GLuint *t = (GLuint*)auxiliar_checkclass(L, "gl{texture}", 3);
int t_ref = luaL_ref(L, LUA_REGISTRYINDEX);
int p_ref = luaL_ref(L, LUA_REGISTRYINDEX);
particles_type *ps = (particles_type*)lua_newuserdata(L, sizeof(particles_type));
auxiliar_setclass(L, "core{particles}", -1);
ps->nb = nb;
ps->texture = *t;
ps->texture_ref = t_ref;
ps->particles = calloc(nb, sizeof(particle_type));
// Grab all parameters
lua_rawgeti(L, LUA_REGISTRYINDEX, p_ref);
lua_pushstring(L, "base");
lua_gettable(L, -2);
ps->base = (float)lua_tonumber(L, -1);
lua_pop(L, 1);
getfield("life", &(ps->life_min), &(ps->life_max));
getfield("size", &(ps->size_min), &(ps->size_max));
getfield("sizev", &(ps->sizev_min), &(ps->sizev_max));
getfield("sizea", &(ps->sizea_min), &(ps->sizea_max));
getfield("r", &(ps->r_min), &(ps->r_max));
getfield("rv", &(ps->rv_min), &(ps->rv_max));
getfield("ra", &(ps->ra_min), &(ps->ra_max));
getfield("g", &(ps->g_min), &(ps->g_max));
getfield("gv", &(ps->gv_min), &(ps->gv_max));
getfield("ga", &(ps->ga_min), &(ps->ga_max));
getfield("b", &(ps->b_min), &(ps->b_max));
getfield("bv", &(ps->bv_min), &(ps->bv_max));
getfield("ba", &(ps->ba_min), &(ps->ba_max));
getfield("a", &(ps->a_min), &(ps->a_max));
getfield("av", &(ps->av_min), &(ps->av_max));
getfield("aa", &(ps->aa_min), &(ps->aa_max));
lua_pop(L, 1);
luaL_unref(L, LUA_REGISTRYINDEX, p_ref);
return 1;
}
static int particles_free(lua_State *L)
{
particles_type *ps = (particles_type*)auxiliar_checkclass(L, "core{particles}", 1);
free(ps->particles);
luaL_unref(L, LUA_REGISTRYINDEX, ps->texture_ref);
lua_pushnumber(L, 1);
return 1;
}
static int particles_emit(lua_State *L)
{
particles_type *ps = (particles_type*)auxiliar_checkclass(L, "core{particles}", 1);
int nb = luaL_checknumber(L, 2);
int i;
for (i = 0; i < ps->nb; i++)
{
particle_type *p = &ps->particles[i];
if (!p->life)
{
p->life = rng(ps->life_min, ps->life_max);
p->size = rng(ps->size_min, ps->size_max);
p->sizev = rng(ps->sizev_min, ps->sizev_max);
p->sizea = rng(ps->sizea_min, ps->sizea_max);
p->x = p->y = 0;
float angle = rng(0, 360) / (2 * M_PI);
float v = rng(1, 100) / 100.0f;
p->xa = cos(angle) * v;
p->ya = sin(angle) * v;
p->xv = cos(angle) * rng(1, 100) / 100.0f * 3;
p->yv = sin(angle) * rng(1, 100) / 100.0f * 3;
printf("%f %f : %d\n", ps->b_min, ps->b_max, rng((int)ps->r_min, (int)ps->r_max));
p->r = rng((int)ps->r_min, (int)ps->r_max) / 255.0f;
p->g = rng((int)ps->g_min, (int)ps->g_max) / 255.0f;
p->b = rng((int)ps->b_min, (int)ps->b_max) / 255.0f;
p->a = rng((int)ps->a_min, (int)ps->a_max) / 255.0f;
p->rv = 0;
p->gv = 0;
p->bv = 0;
p->av = -0.01 * rng(1, 5);
p->ra = 0;
p->ga = 0;
p->ba = 0;
p->aa = 0;
nb--;
if (!nb) break;
}
}
return 0;
}
static int particles_to_screen(lua_State *L)
{
particles_type *ps = (particles_type*)auxiliar_checkclass(L, "core{particles}", 1);
int x = luaL_checknumber(L, 2);
int y = luaL_checknumber(L, 3);
int i = 0;
glBindTexture(GL_TEXTURE_2D, ps->texture);
for (i = 0; i < ps->nb; i++)
{
particle_type *p = &ps->particles[i];
if (p->life)
{
glColor4f(p->r, p->g, p->b, p->a);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex3f(0 + x + p->x, 0 + y + p->y, -97);
glTexCoord2f(1,0); glVertex3f(p->size + x + p->x, 0 + y + p->y, -97);
glTexCoord2f(1,1); glVertex3f(p->size + x + p->x, p->size + y + p->y, -97);
glTexCoord2f(0,1); glVertex3f(0 + x + p->x, p->size + y + p->y, -97);
glEnd();
p->life--;
p->x += p->xv;
p->y += p->yv;
p->r += p->rv;
p->g += p->gv;
p->b += p->bv;
p->a += p->av;
p->size += p->sizev;
p->xv += p->xa;
p->yv += p->ya;
p->rv += p->ra;
p->gv += p->ga;
p->bv += p->ba;
p->av += p->aa;
p->sizev += p->sizea;
}
}
// Restore normal display
glColor4f(1, 1, 1, 1);
return 0;
}
static const struct luaL_reg particleslib[] =
{
{"newEmitter", particles_new},
{NULL, NULL},
};
static const struct luaL_reg particles_reg[] =
{
{"__gc", particles_free},
{"close", particles_free},
{"emit", particles_emit},
{"toScreen", particles_to_screen},
{NULL, NULL},
};
int luaopen_particles(lua_State *L)
{
auxiliar_newclass(L, "core{particles}", particles_reg);
luaL_openlib(L, "core.particles", particleslib, 0);
return 1;
}
#ifndef _PARTICLES_H_
#define _PARTICLES_H_
#include <gl.h>
typedef struct {
float size, sizev, sizea;
float x, y, xv, yv, xa, ya;
float r, g, b, a, rv, gv, bv, av, ra, ga, ba, aa;
int life;
} particle_type;
typedef struct {
GLuint texture;
particle_type *particles;
int nb;
int texture_ref;
float base;
float size_min, sizev_min, sizea_min;
float x_min, y_min, xv_min, yv_min, xa_min, ya_min;
float r_min, g_min, b_min, a_min, rv_min, gv_min, bv_min, av_min, ra_min, ga_min, ba_min, aa_min;
float size_max, sizev_max, sizea_max;
float x_max, y_max, xv_max, yv_max, xa_max, ya_max;
float r_max, g_max, b_max, a_max, rv_max, gv_max, bv_max, av_max, ra_max, ga_max, ba_max, aa_max;
float life_min, life_max;
} particles_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