Demos update (SpaceInvaders demo)

-added new sprites
-added new functions to vectors
-fixed rendering rotated sprites
-small performance improvement and some bug fixes
-added animations support
-bullets get initial velocity from parent
-added partiles for fire from gun and explosion of enemies
This commit is contained in:
Mergul 2020-05-19 20:27:18 +02:00
parent 6c3c803d1e
commit 0b924ae77c
7 changed files with 411 additions and 34 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Before After
Before After

View file

@ -18,6 +18,9 @@
"libs-windows-x86_64": ["libs/windows/x64/SDL2","libs/windows/x64/SDL2_Image","libs/windows/x64/cimgui"],
"libs-linux-x86_64": ["cimgui","SDL2","SDL2_image"],
"lflags-linux-x86_64": ["-rpath=libs/linux/x64/","-Llibs/linux/x64/"],
"dflags-ldc" : [
"--ffast-math"
],
"configurations" : [
{
"name" : "default",

View file

@ -262,7 +262,7 @@ void mainLoop(void* arg)
if(launcher.tool && launcher.tool_repeat != 0 && launcher.mouse.left && !igIsWindowHovered(ImGuiHoveredFlags_AnyWindow) && !igIsWindowFocused(ImGuiFocusedFlags_AnyWindow))
{
float range = 500.0 / cast(float)launcher.tool_repeat;
launcher.repeat_time += launcher.delta_time;
launcher.repeat_time += launcher.delta_time * 100;
while(launcher.repeat_time > range)
{
launcher.repeat_time -= range;
@ -716,7 +716,7 @@ int main(int argc, char** argv)
launcher.job_updater = Mallocator.make!ECSJobUpdater(1);
//launcher.job_updater.onCreate();
EntityManager.initialize(32);
EntityManager.initialize(32, 1<<16);
launcher.manager = EntityManager.instance;
//launcher.manager.m_thread_id_func = &launcher.job_updater.getThreadID;

View file

@ -285,7 +285,7 @@ struct ParticleSystem
{
uint length;
@readonly Entity[] entities;
@readonly CParticle[] particle;
CParticle[] particle;
}
void onUpdate(EntitiesData data)

View file

@ -16,6 +16,8 @@ import ecs_utils.gfx.texture;
import ecs_utils.math.vector;
import ecs_utils.utils;
import std.math : PI;
//import std.array : staticArray;
enum float px = 1.0/512.0;
@ -121,6 +123,16 @@ struct CScale
vec2 value = vec2(16,16);
}
struct CRotation
{
mixin ECS.Component;
///use component as it value
alias value this;
float value = 0;
}
struct CTexture
{
mixin ECS.Component;
@ -176,6 +188,17 @@ struct CLaserWeapon
{
mixin ECS.Component;
static struct Level
{
float reload_time;
float dispersion;
}
__gshared Level[12] levels = [Level(4000,0),Level(4000,0.1),
Level(500,0),Level(350,0),Level(250,0.02),Level(175,0.03),Level(110,0.04),
Level(80,0.05),Level(50,0.08),Level(20,0.1),Level(10,0.12),Level(2,0.14)];
ubyte level = 1;
float shoot_time = 0;
}
@ -208,13 +231,30 @@ struct CShootGrid
mixin ECS.Component;
}
struct CTargetPartent
{
mixin ECS.Component;
EntityID parent;
vec2 rel_pos;
}
struct CHitPoints
{
mixin ECS.Component;
alias value this;
int value = 10;
int value = 3;
}
struct CMaxHitPoints
{
mixin ECS.Component;
alias value this;
int value = 3;
}
struct CHitMark
@ -229,6 +269,47 @@ struct CHitMark
struct CUpgrade
{
mixin ECS.Component;
alias value this;
enum Upgrade : ubyte
{
hit_points,
regeneration,
laser
}
Upgrade value;
}
struct CAnimation
{
mixin ECS.Component;
vec4[] frames;
float time = 0;
float speed = 1;
}
struct CAnimationLooped
{
mixin ECS.Component;
}
struct CDamping
{
mixin ECS.Component;
alias value this;
byte value = 0;
}
struct CParticle
{
mixin ECS.Component;
float life = 0;
}
/*#######################################################################################################################
@ -436,6 +517,7 @@ struct DrawSystem
@readonly CTexture[] textures;
@readonly CLocation[] locations;
@readonly CScale[] scale;
@readonly @optional CRotation[] rotation;
@readonly @optional CDepth[] depth;
@readonly @optional CHitMark[] hit_mark;
}
@ -452,6 +534,13 @@ struct DrawSystem
launcher.renderer.draw(data.textures[i].tex, data.locations[i].value, data.scale[i], data.textures[i].coords, cast(short)data.locations[i].y, color, 0, 0, 0, data.thread_id);
}
}
else if(data.rotation)
{
foreach(i; 0..data.length)
{
launcher.renderer.draw(data.textures[i].tex, data.locations[i].value, data.scale[i], data.textures[i].coords, cast(short)data.locations[i].y, 0x80808080, data.rotation[i], 0, 0, data.thread_id);
}
}
else
{
foreach(i; 0..data.length)
@ -463,18 +552,36 @@ struct DrawSystem
else
{
if(data.hit_mark)
{
if(data.rotation)
{
foreach(i; 0..data.length)
{
uint color = 0x80808080 + 0x01010101 * data.hit_mark[i];
launcher.renderer.draw(data.textures[i].tex, data.locations[i].value, data.scale[i], data.textures[i].coords, cast(short)(data.depth[i] * 64 + data.locations[i].y), color, 0, 0, 0, data.thread_id);
launcher.renderer.draw(data.textures[i].tex, data.locations[i].value, data.scale[i], data.textures[i].coords, cast(short)(data.depth[i] * 4 + data.locations[i].y), color, data.rotation[i], 0, 0, data.thread_id);
}
}
else
{
foreach(i; 0..data.length)
{
launcher.renderer.draw(data.textures[i].tex, data.locations[i].value, data.scale[i], data.textures[i].coords, cast(short)(data.depth[i] * 64 + data.locations[i].y), 0x80808080, 0, 0, 0, data.thread_id);
uint color = 0x80808080 + 0x01010101 * data.hit_mark[i];
launcher.renderer.draw(data.textures[i].tex, data.locations[i].value, data.scale[i], data.textures[i].coords, cast(short)(data.depth[i] * 4 + data.locations[i].y), color, 0, 0, 0, data.thread_id);
}
}
}
else if(data.rotation)
{
foreach(i; 0..data.length)
{
launcher.renderer.draw(data.textures[i].tex, data.locations[i].value, data.scale[i], data.textures[i].coords, cast(short)(data.depth[i] * 4 + data.locations[i].y), 0x80808080, data.rotation[i], 0, 0, data.thread_id);
}
}
else
{
foreach(i; 0..data.length)
{
launcher.renderer.draw(data.textures[i].tex, data.locations[i].value, data.scale[i], data.textures[i].coords, cast(short)(data.depth[i] * 4 + data.locations[i].y), 0x80808080, 0, 0, 0, data.thread_id);
}
}
}
@ -502,7 +609,14 @@ struct LaserShootingSystem
mixin ECS.System!32;
bool shoot = false;
static float[18] laser_shoot_times = [500,400,300,200,100,50,25,10,5,2,1,0.8,0.6,0.5,0.4,0.3,0.2,0.1];
//static float[18] laser_shoot_times = [500,400,300,200,100,50,25,10,5,2,1,0.8,0.6,0.5,0.4,0.3,0.2,0.1];
//static float[18] laser_shoot_disp = [0,0,0,0,0.05,0.06,0.08,0.1,0.14,0.18,0.2,0.25,0.26,0.27,0.28,0.29,0.3,0.4];
__gshared vec4[] fire_frames = [vec4(96,64,8,16)*px,vec4(104,64,8,16)*px,vec4(112,64,8,16)*px,vec4(120,64,8,16)*px,vec4(128,64,8,16)*px,
vec4(136,64,8,16)*px,vec4(144,64,8,16)*px,vec4(152,64,8,16)*px,vec4(160,64,8,16)*px];
// __gshared vec4[] fire_frames = [vec4(0,160,8,16)*px,vec4(16,160,16,16)*px,vec4(32,160,16,16)*px,vec4(48,160,16,16)*px,vec4(64,160,16,16)*px,
// vec4(80,160,16,16)*px,vec4(96,160,16,16)*px,vec4(112,160,16,16)*px];
/*CLocation* laser_location;
CVelocity* laser_velocity;
@ -518,6 +632,7 @@ struct LaserShootingSystem
@readonly @optional CAutoShoot[] auto_shoot;
@readonly CLocation[] location;
@readonly CGuild[] guild;
@optional @readonly CVelocity[] velocity;
CLaserWeapon[] laser;
}
@ -527,6 +642,11 @@ struct LaserShootingSystem
CLocation* laser_location;
CVelocity* laser_velocity;
CGuild* laser_guild;
EntityTemplate* fire_tmpl;
CLocation* fire_location;
CVelocity* fire_velocity;
CRotation* fire_rotation;
}
ThreadData[] threads;
@ -535,7 +655,10 @@ struct LaserShootingSystem
void onCreate()
{
threads = Mallocator.makeArray!ThreadData(32);
threads[0].laser_tmpl = launcher.manager.allocateTemplate([CLocation.component_id, CTexture.component_id, CVelocity.component_id, CScale.component_id, CLaser.component_id, CGuild.component_id].staticArray);
threads[0].laser_tmpl = launcher.manager.allocateTemplate(
[CLocation.component_id, CTexture.component_id, CVelocity.component_id,
CScale.component_id, CLaser.component_id, CGuild.component_id].staticArray
);
CTexture* tex_comp = threads[0].laser_tmpl.getComponent!CTexture;
tex_comp.tex = space_invaders.texture;//laser_tex;
@ -546,12 +669,33 @@ struct LaserShootingSystem
threads[0].laser_velocity = threads[0].laser_tmpl.getComponent!CVelocity;
threads[0].laser_guild = threads[0].laser_tmpl.getComponent!CGuild;
threads[0].fire_tmpl = launcher.manager.allocateTemplate(
[CLocation.component_id, CTexture.component_id, CScale.component_id,
CAnimation.component_id, CParticle.component_id, CRotation.component_id,
CVelocity.component_id, CDamping.component_id].staticArray
);
tex_comp = threads[0].fire_tmpl.getComponent!CTexture;
tex_comp.tex = space_invaders.texture;//laser_tex;
tex_comp.coords = vec4(96*px,64*px,8*px,16*px);
scale_comp = threads[0].fire_tmpl.getComponent!CScale;
scale_comp.value = vec2(8,16);
threads[0].fire_location = threads[0].fire_tmpl.getComponent!CLocation;
threads[0].fire_rotation = threads[0].fire_tmpl.getComponent!CRotation;
threads[0].fire_velocity = threads[0].fire_tmpl.getComponent!CVelocity;
threads[0].fire_tmpl.getComponent!(CParticle).life = 300;
*threads[0].fire_tmpl.getComponent!(CAnimation) = CAnimation(fire_frames, 0, 3);
foreach(ref ThreadData thread;threads[1..$])
{
thread.laser_tmpl = launcher.manager.allocateTemplate(threads[0].laser_tmpl);
thread.laser_location = thread.laser_tmpl.getComponent!CLocation;
thread.laser_velocity = thread.laser_tmpl.getComponent!CVelocity;
thread.laser_guild = thread.laser_tmpl.getComponent!CGuild;
thread.fire_tmpl = launcher.manager.allocateTemplate(threads[0].fire_tmpl);
thread.fire_location = thread.fire_tmpl.getComponent!CLocation;
thread.fire_rotation = thread.fire_tmpl.getComponent!CRotation;
thread.fire_velocity = thread.fire_tmpl.getComponent!CVelocity;
}
//laser_location = space_invaders.laser_tmpl.getComponent!CLocation;
}
@ -588,13 +732,34 @@ struct LaserShootingSystem
{
CLaserWeapon* laser = &data.laser[i];
laser.shoot_time += launcher.delta_time;
while(laser.shoot_time > laser_shoot_times[laser.level - 1])
while(laser.shoot_time > CLaserWeapon.levels[laser.level - 1].reload_time)
{
laser.shoot_time -= laser_shoot_times[laser.level - 1];
laser.shoot_time -= CLaserWeapon.levels[laser.level - 1].reload_time;
thread.laser_location.value = data.location[i];
thread.laser_velocity.value = vec2(randomf()*0.5-0.25,data.shoot_direction[i].direction == Direction.up ? 1.0 : -1.0);
thread.laser_velocity.value = vec2((randomf()*2-1) * CLaserWeapon.levels[laser.level - 1].dispersion,data.shoot_direction[i].direction == Direction.up ? 1.0 : -1.0);
thread.laser_guild.guild = data.guild[i].guild;
if(data.velocity)
{
thread.fire_velocity.value = data.velocity[i];
//thread.laser_velocity.value += data.velocity[i] * 0.5;
}
else thread.fire_velocity.value = vec2(0,0);
launcher.manager.addEntity(thread.laser_tmpl);
thread.fire_location.value = data.location[i];
if(data.shoot_direction[i].direction == Direction.down)
{
thread.fire_rotation.value = PI;
thread.fire_location.value.y -= 16;
}
else
{
thread.fire_rotation.value = 0;
thread.fire_location.value.y += 24;
}
launcher.manager.addEntity(thread.fire_tmpl);
}
}
}
@ -604,13 +769,47 @@ struct LaserShootingSystem
{
CLaserWeapon* laser = &data.laser[i];
laser.shoot_time += launcher.delta_time;
if(laser.shoot_time > laser_shoot_times[laser.level - 1])laser.shoot_time = laser_shoot_times[laser.level - 1];
if(laser.shoot_time > CLaserWeapon.levels[laser.level - 1].reload_time)laser.shoot_time = CLaserWeapon.levels[laser.level - 1].reload_time;
}
}
}
}
struct DampingSystem
{
mixin ECS.System!32;
struct EntitiesData
{
uint length;
const (Entity)[] entity;
@readonly CDamping[] damping;
CVelocity[] velocity;
}
float[10] damp = 0;
bool onBegin()
{
import core.stdc.math : powf;
foreach(i;0..10)
{
damp[i] = powf((0.98 - cast(float)i * 0.02),launcher.delta_time*0.1);
}
return true;
}
void onUpdate(EntitiesData data)
{
foreach(i; 0..data.length)
{
data.velocity[i] = data.velocity[i] * damp[data.damping[i]];
}
}
}
struct LaserCollisionSystem
{
mixin ECS.System!32;
@ -689,7 +888,7 @@ struct UpgradeSystem
CLaserWeapon* laser = entity.getComponent!CLaserWeapon;
if(laser)
{
if(laser.level < LaserShootingSystem.laser_shoot_times.length)laser.level++;
if(laser.level < CLaserWeapon.levels.length)laser.level++;
}
}
}
@ -884,9 +1083,15 @@ struct HitPointsSystem
{
mixin ECS.System;
__gshared vec4[] upgrade_laser_frames = [vec4(96,80,16,16)*px,vec4(112,80,16,16)*px,vec4(128,80,16,16)*px,vec4(144,80,16,16)*px,vec4(128,80,16,16)*px,vec4(112,80,16,16)*px];
__gshared vec4[] explosion_laser_frames = [vec4(80,128,16,16)*px,vec4(96,128,16,16)*px,vec4(112,128,16,16)*px,vec4(128,128,16,16)*px,vec4(144,128,16,16)*px,vec4(160,128,16,16)*px,vec4(176,128,16,16)*px,vec4(192,128,16,16)*px,vec4(208,128,16,16)*px];
EntityTemplate* upgrade_tmpl;
CLocation* upgrade_location;
EntityTemplate* explosion_tmpl;
CLocation* explosion_location;
struct EntitiesData
{
CHitPoints[] hp;
@ -894,13 +1099,21 @@ struct HitPointsSystem
void onCreate()
{
upgrade_tmpl = launcher.manager.allocateTemplate([CVelocity.component_id, CLocation.component_id, CTexture.component_id, CScale.component_id, CUpgrade.component_id].staticArray);
upgrade_tmpl = launcher.manager.allocateTemplate([CVelocity.component_id, CLocation.component_id, CTexture.component_id, CScale.component_id, CUpgrade.component_id, CAnimation.component_id, CAnimationLooped.component_id].staticArray);
CTexture* tex_comp = upgrade_tmpl.getComponent!CTexture;
tex_comp.tex = space_invaders.texture;//ship_tex;
tex_comp.coords = vec4(0*px,32*px,16*px,16*px);
*upgrade_tmpl.getComponent!CAnimation = CAnimation(upgrade_laser_frames, 0, 1);
CVelocity* vel_comp = upgrade_tmpl.getComponent!CVelocity;
vel_comp.value = vec2(0,-0.1);
upgrade_location = upgrade_tmpl.getComponent!CLocation;
explosion_tmpl = launcher.manager.allocateTemplate([CDepth.component_id, CParticle.component_id, CLocation.component_id, CTexture.component_id, CScale.component_id, CAnimation.component_id].staticArray);
explosion_tmpl.getComponent!(CTexture).tex = space_invaders.texture;
*explosion_tmpl.getComponent!CAnimation = CAnimation(explosion_laser_frames, 0, 1.333);
explosion_tmpl.getComponent!(CParticle).life = 600;
*explosion_tmpl.getComponent!CDepth = -1;
explosion_location = explosion_tmpl.getComponent!CLocation;
}
void onDestroy()
@ -911,9 +1124,9 @@ struct HitPointsSystem
void handleEvent(Entity* entity, EDamage event)
{
CHitPoints* hp = entity.getComponent!CHitPoints;
if(*hp < 0)return;
if(*hp <= 0)return;
*hp -= event.damage;
if(*hp < 0)
if(*hp <= 0)
{
launcher.manager.sendEvent(entity.id, EDeath());
//launcher.manager.removeEntity(entity.id);
@ -926,15 +1139,17 @@ struct HitPointsSystem
{
CEnemy* enemy = entity.getComponent!CEnemy;
if(enemy)
{
if(randomRange(0, 1000) < 5)
{
CLocation* location = entity.getComponent!CLocation;
if(location)
{
if(randomRange(0, 1000) < 5)
{
*upgrade_location = *location;
launcher.manager.addEntity(upgrade_tmpl);
}
*explosion_location = *location;
launcher.manager.addEntity(explosion_tmpl);
}
}
launcher.manager.removeEntity(entity.id);
@ -1031,7 +1246,7 @@ struct MovementSystem
//@optional const (CLaser)[] laser;
const (Entity)[] entities;
@optional CSideMove[] side_move;
//@optional CSideMove[] side_move;
}
void onUpdate(EntitiesData data)
@ -1044,6 +1259,63 @@ struct MovementSystem
}
}
struct AnimationSystem
{
mixin ECS.System!32;
struct EntitiesData
{
uint length;
CAnimation[] animation;
CTexture[] texture;
@optional @readonly CAnimationLooped[] looped;
}
void onUpdate(EntitiesData data)
{
float dt = launcher.delta_time * 0.01;
if(data.looped)
{
foreach(i;0..data.length)
{
data.animation[i].time += dt * data.animation[i].speed;
while(data.animation[i].time >= data.animation[i].frames.length)data.animation[i].time -= cast(float)data.animation[i].frames.length;
data.texture[i].coords = data.animation[i].frames[cast(int)(data.animation[i].time)];
}
}
else
{
foreach(i;0..data.length)
{
data.animation[i].time += dt * data.animation[i].speed;
if(data.animation[i].time >= data.animation[i].frames.length)data.animation[i].time = data.animation[i].frames.length - 0.1;
data.texture[i].coords = data.animation[i].frames[cast(int)(data.animation[i].time)];
}
}
}
}
struct ParticleSystem
{
mixin ECS.System!32;
struct EntitiesData
{
uint length;
@readonly Entity[] entitiy;
CParticle[] particle;
}
void onUpdate(EntitiesData data)
{
foreach(i;0..data.length)
{
data.particle[i].life -= launcher.delta_time;
if(data.particle[i].life < 0)launcher.manager.removeEntity(data.entitiy[i].id);
}
}
}
extern(C) float sqrtf(float x) @nogc nothrow @system;
@ -1063,7 +1335,8 @@ struct InputMovementSystem
//read only components can be marked with @readonly attribute or with const expression instead
const (CInput)[] input;
//components are treated as required by default
CLocation[] locations;
//CLocation[] locations;
CVelocity[] velocity;
CTexture[] textures;
}
@ -1108,22 +1381,33 @@ struct InputMovementSystem
*/
void onUpdate(EntitiesData data)
{
if(move_vector.x == 0)
/*if(move_vector.x == 0)
{
foreach(i; 0..data.length)
{
data.textures[i].coords = vec4(0*px,80*px,48*px,32*px);
}
//return;
}
}*/
//move every entity using movement vector
//if(move_vector.x != 0 || move_vector.y != 0)
foreach(i; 0..data.length)
{
data.locations[i].x += move_vector.x * launcher.delta_time * 0.25;
data.locations[i].y += move_vector.y * launcher.delta_time * 0.25;
if(move_vector.x > 0)data.textures[i].coords = vec4(48*px,80*px,48*px,32*px);
else data.textures[i].coords = vec4(0*px,80*px,48*px,32*px);
data.velocity[i] += move_vector * launcher.delta_time * 0.005;
if(data.velocity[i].x > 0.5)data.velocity[i].x = 0.5;
else if(data.velocity[i].x < -0.5)data.velocity[i].x = -0.5;
if(data.velocity[i].y > 0.5)data.velocity[i].y = 0.5;
else if(data.velocity[i].y < -0.5)data.velocity[i].y = -0.5;
//data.locations[i].x += move_vector.x * launcher.delta_time * 0.25;
//data.locations[i].y += move_vector.y * launcher.delta_time * 0.25;
//if(move_vector.x > 0)data.textures[i].coords = vec4(48*px,80*px,48*px,32*px);
//else data.textures[i].coords = vec4(0*px,80*px,48*px,32*px);
}
/*else
foreach(i; 0..data.length)
{
data.velocity[i] = vec2(0,0);
}*/
}
}
@ -1165,6 +1449,12 @@ void spaceInvadersStart()
launcher.manager.registerComponent!CHitPoints;
launcher.manager.registerComponent!CHitMark;
launcher.manager.registerComponent!CUpgrade;
launcher.manager.registerComponent!CParticle;
launcher.manager.registerComponent!CMaxHitPoints;
launcher.manager.registerComponent!CAnimation;
launcher.manager.registerComponent!CRotation;
launcher.manager.registerComponent!CAnimationLooped;
launcher.manager.registerComponent!CDamping;
launcher.manager.registerEvent!EChangeDirection;
launcher.manager.registerEvent!EDamage;
@ -1185,6 +1475,9 @@ void spaceInvadersStart()
launcher.manager.registerSystem!HitMarkingSystem(-100);
launcher.manager.registerSystem!UpgradeCollisionSystem(-70);
launcher.manager.registerSystem!UpgradeSystem(-100);
launcher.manager.registerSystem!ParticleSystem(-100);
launcher.manager.registerSystem!AnimationSystem(-100);
launcher.manager.registerSystem!DampingSystem(-101);
launcher.manager.endRegister();
@ -1197,8 +1490,13 @@ void spaceInvadersStart()
//launcher.manager.getSystem(CleanSystem.system_id).disable();
{
ushort[11] components = [CHitMark.component_id, CHitPoints.component_id, CLocation.component_id, CTexture.component_id, CInput.component_id, CShip.component_id, CScale.component_id, CLaserWeapon.component_id, CShootDirection.component_id, CShootGrid.component_id, CGuild.component_id];
space_invaders.ship_tmpl = launcher.manager.allocateTemplate(components);
space_invaders.ship_tmpl = launcher.manager.allocateTemplate(
[CVelocity.component_id, CHitMark.component_id, CHitPoints.component_id,
CLocation.component_id, CTexture.component_id, CInput.component_id,
CShip.component_id, CScale.component_id, CLaserWeapon.component_id,
CShootDirection.component_id, CShootGrid.component_id, CGuild.component_id,
CDamping.component_id].staticArray
);
CScale* scale_comp = space_invaders.ship_tmpl.getComponent!CScale;
scale_comp.value = vec2(48,32);
@ -1208,8 +1506,9 @@ void spaceInvadersStart()
CLocation* loc_comp = space_invaders.ship_tmpl.getComponent!CLocation;
loc_comp.value = vec2(64,64);
CLaserWeapon* weapon = space_invaders.ship_tmpl.getComponent!CLaserWeapon;
weapon.level = 1;
weapon.level = 3;
space_invaders.ship_tmpl.getComponent!CHitPoints().value = 1000;
space_invaders.ship_tmpl.getComponent!CDamping().value = 7;
launcher.manager.addEntity(space_invaders.ship_tmpl);
}
@ -1273,12 +1572,13 @@ void spaceInvadersStart()
EntityTemplate* upgrade_tmpl;
{
upgrade_tmpl = launcher.manager.allocateTemplate([CVelocity.component_id, CLocation.component_id, CTexture.component_id, CScale.component_id, CUpgrade.component_id].staticArray);
upgrade_tmpl = launcher.manager.allocateTemplate([CVelocity.component_id, CLocation.component_id, CTexture.component_id, CScale.component_id, CUpgrade.component_id, CAnimationLooped.component_id, CAnimation.component_id].staticArray);
CTexture* tex_comp = upgrade_tmpl.getComponent!CTexture;
tex_comp.tex = space_invaders.texture;//ship_tex;
tex_comp.coords = vec4(0*px,32*px,16*px,16*px);
CVelocity* vel_comp = upgrade_tmpl.getComponent!CVelocity;
vel_comp.value = vec2(0,-0.1);
*upgrade_tmpl.getComponent!CAnimation = CAnimation(HitPointsSystem.upgrade_laser_frames, 0, 0.75);
}
launcher.manager.commit();
@ -1326,7 +1626,7 @@ void spaceInvadersTool(vec2 position, Tool tool, int size)
CLaserWeapon* laser_weapon = tmpl.getComponent!CLaserWeapon;
if(laser_weapon)
{
laser_weapon.shoot_time = randomf * LaserShootingSystem.laser_shoot_times[laser_weapon.level - 1];
laser_weapon.shoot_time = randomf * CLaserWeapon.levels[laser_weapon.level - 1].reload_time;
}
launcher.manager.addEntity(tmpl);
}

View file

@ -535,12 +535,30 @@ struct Renderer
verts[item_id*28] = cast(short)(((GfxConfig.meshes[mesh_id].vertices[0] * coss + GfxConfig.meshes[mesh_id].vertices[1] * sinn) * size.x + pos.x) * 8191);
verts[item_id*28+1] = cast(short)(((GfxConfig.meshes[mesh_id].vertices[1] * coss - GfxConfig.meshes[mesh_id].vertices[0] * sinn) * size.y + pos.y) * 8191);
verts[item_id*28+2] = cast(short)((GfxConfig.meshes[mesh_id].vertices[2] * coords.z + coords.x)*32767);
verts[item_id*28+3] = cast(short)((GfxConfig.meshes[mesh_id].vertices[3] * coords.w + coords.y)*32767);
memcpy(verts.ptr+item_id*28+4,mem.ptr,6);
verts[item_id*28+7] = cast(short)(((GfxConfig.meshes[mesh_id].vertices[4] * coss + GfxConfig.meshes[mesh_id].vertices[5] * sinn) * size.x + pos.x) * 8191);
verts[item_id*28+8] = cast(short)(((GfxConfig.meshes[mesh_id].vertices[5] * coss - GfxConfig.meshes[mesh_id].vertices[4] * sinn) * size.y + pos.y) * 8191);
verts[item_id*28+9] = cast(short)((GfxConfig.meshes[mesh_id].vertices[6] * coords.z + coords.x)*32767);
verts[item_id*28+10] = cast(short)((GfxConfig.meshes[mesh_id].vertices[7] * coords.w + coords.y)*32767);
memcpy(verts.ptr+item_id*28+11,mem.ptr,6);
verts[item_id*28+14] = cast(short)(((GfxConfig.meshes[mesh_id].vertices[8] * coss + GfxConfig.meshes[mesh_id].vertices[9] * sinn) * size.x + pos.x) * 8191);
verts[item_id*28+15] = cast(short)(((GfxConfig.meshes[mesh_id].vertices[9] * coss - GfxConfig.meshes[mesh_id].vertices[8] * sinn) * size.y + pos.y) * 8191);
verts[item_id*28+16] = cast(short)((GfxConfig.meshes[mesh_id].vertices[10] * coords.z + coords.x)*32767);
verts[item_id*28+17] = cast(short)((GfxConfig.meshes[mesh_id].vertices[11] * coords.w + coords.y)*32767);
memcpy(verts.ptr+item_id*28+18,mem.ptr,6);
verts[item_id*28+21] = cast(short)(((GfxConfig.meshes[mesh_id].vertices[12] * coss + GfxConfig.meshes[mesh_id].vertices[13] * sinn) * size.x + pos.x) * 8191);
verts[item_id*28+22] = cast(short)(((GfxConfig.meshes[mesh_id].vertices[13] * coss - GfxConfig.meshes[mesh_id].vertices[12] * sinn) * size.y + pos.y) * 8191);
verts[item_id*28+23] = cast(short)((GfxConfig.meshes[mesh_id].vertices[14] * coords.z + coords.x)*32767);
verts[item_id*28+24] = cast(short)((GfxConfig.meshes[mesh_id].vertices[15] * coords.w + coords.y)*32767);
memcpy(verts.ptr+item_id*28+25,mem.ptr,6);
}
/*verts[item_id*28+2] = cast(short)((GfxConfig.meshes[mesh_id].vertices[2] * coords.z + coords.x)*32767);

View file

@ -2,6 +2,18 @@ module ecs_utils.math.vector;
struct vec2
{
this(float v) @nogc nothrow
{
x = v;
y = v;
}
this(float x, float y) @nogc nothrow
{
this.x = x;
this.y = y;
}
union
{
struct
@ -75,6 +87,22 @@ struct vec4
float[4] data;
}
this(float v) @nogc nothrow
{
x = v;
y = v;
z = v;
w = v;
}
this(float x, float y, float z, float w) @nogc nothrow
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
vec4 opBinary(string op)(float v)
{
static if (op == "+") return vec4(x + v, y + v, z + v, w + v);
@ -97,6 +125,18 @@ struct ivec2
int[2] data;
}
this(int v) @nogc nothrow
{
x = v;
y = v;
}
this(int x, int y) @nogc nothrow
{
this.x = x;
this.y = y;
}
ivec2 opBinary(string op, T)(T v)
{
static if (op == "+") return ivec2(x + v, y + v);
@ -125,4 +165,20 @@ struct ivec4
}
int[4] data;
}
this(int v) @nogc nothrow
{
x = v;
y = v;
z = v;
w = v;
}
this(int x, int y, int z, int w) @nogc nothrow
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
}