6 n__particles_8h
gullradriel edited this page 2026-10-09 00:55:18 +02:00

include/nilorea/n_particles.h

Particles management. More...

Structures

Name
struct PARTICLE_SYSTEM
Structure of a particle system.
struct PARTICLE_EMITTER
Structure of a particle emitter.
struct PARTICLE
Structure of a single particle.

Detailed Description

Particles management.

Author: Castagnier Mickael aka Gull Ra Driel

Version: 1.0

Date: 20/12/2012

Source code

/*
 * Nilorea Library
 * Copyright (C) 2005-2026 Castagnier Mickael
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */


#ifndef __N_PARTICLE_HEADER
#define __N_PARTICLE_HEADER

#ifdef __cplusplus
extern "C" {
#endif


#include <allegro5/allegro.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_primitives.h>

#include "n_common.h"
#include "n_log.h"
#include "n_list.h"
#include "n_3d.h"
#include "n_time.h"

#define NORMAL_PART 0
#define SINUS_PART 1
#define TRANS_PART 2
#define SNOW_PART 3
#define FIRE_PART 4
#define STAR_PART 5
#define CIRCLE_PART 6
#define PIXEL_PART 7
#define BITMAP_PART 8
#define TEXT_PART 9

typedef struct PARTICLE {
    int mode,
        lifetime,
        spr_id,
        size;

    ALLEGRO_COLOR color;

    PHYSICS object;

    ALLEGRO_COLOR color_start;
    ALLEGRO_COLOR color_end;
    int age;
    int lifetime_max;
    int size_start;
    int size_end;
    int additive;
    int depth_sort;
    struct PARTICLE_EMITTER* emitter;

} PARTICLE;

typedef struct PARTICLE_EMITTER {
    VECTOR3D position;
    VECTOR3D offset;
    VECTOR3D velocity_min;
    VECTOR3D velocity_max;
    VECTOR3D acceleration;
    ALLEGRO_COLOR color_start;
    ALLEGRO_COLOR color_end;
    double emit_rate;
    double emit_accumulator;
    int lifetime_min;
    int lifetime_max;
    int size_start;
    int size_end;
    int particle_mode;
    int burst_count;
    int active;
    int attached_entity_id;
    int spr_id;
    int shape;
    double shape_w;
    double shape_h;
    double shape_rotation;
    int max_particles;
    int additive_blend;
    int depth_sort;
    int live_count;
} PARTICLE_EMITTER;

typedef struct PARTICLE_SYSTEM {
    LIST* list;

    VECTOR3D source;

    N_TIME timer;

    ALLEGRO_BITMAP** sprites;
    int max_sprites;

    LIST* emitters;
} PARTICLE_SYSTEM;

int init_particle_system(PARTICLE_SYSTEM** psys, int max, double x, double y, double z, int max_sprites);

int add_particle(PARTICLE_SYSTEM* psys, int spr, int mode, int lifetime, int size, ALLEGRO_COLOR color, PHYSICS object);
int add_particle_ex(PARTICLE_SYSTEM* psys, int spr, int mode, int off_x, int off_y, int lifetime, int size, ALLEGRO_COLOR color, double vx, double vy, double vz, double ax, double ay, double az);

int manage_particle_ex(PARTICLE_SYSTEM* psys, double delta_t);

int manage_particle(PARTICLE_SYSTEM* psys);

int draw_particle(PARTICLE_SYSTEM* psys, double xpos, double ypos, int w, int h, double range);

int free_particle_system(PARTICLE_SYSTEM** psys);

int move_particles(PARTICLE_SYSTEM* psys, double vx, double vy, double vz);

PARTICLE_EMITTER* add_emitter(PARTICLE_SYSTEM* psys);
int remove_emitter(PARTICLE_SYSTEM* psys, const PARTICLE_EMITTER* em);
int free_emitters(PARTICLE_SYSTEM* psys);

int add_particle_at(PARTICLE_SYSTEM* psys, int spr, int mode, double px, double py, double pz, int lifetime, int size_start, int size_end, ALLEGRO_COLOR color_start, ALLEGRO_COLOR color_end, double vx, double vy, double vz, double ax, double ay, double az);


#ifdef __cplusplus
}
#endif

#endif /* __N_PARTICLE_HEADER */