Skip to content

Commit

Permalink
Add Flame effect behind player's ship
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanlangston committed Jan 5, 2024
1 parent f6657d0 commit 214f375
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
39 changes: 39 additions & 0 deletions src/Models/Flames.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const std = @import("std");
const raylib = @import("raylib");
const Shared = @import("../Shared.zig").Shared;

pub const Flames = struct {
var frame: f32 = 0;

pub inline fn Draw(
position: raylib.Rectangle,
rotation: f32,
) void {
if (frame == std.math.floatMax(f32)) {
frame = 0;
}
frame += raylib.getFrameTime();

const fireTexture = Shared.Texture.Get(.Fire);

const waveShader = Shared.Shader.Get(.Wave);
const waveShaderLoc = raylib.getShaderLocation(waveShader, "seconds");
raylib.setShaderValue(waveShader, waveShaderLoc, &frame, @intFromEnum(raylib.ShaderUniformDataType.shader_uniform_float));
waveShader.activate();
defer waveShader.deactivate();

raylib.drawTexturePro(
fireTexture,
raylib.Rectangle.init(
0,
0,
@as(f32, @floatFromInt(fireTexture.width)),
@as(f32, @floatFromInt(fireTexture.height)),
),
position,
raylib.Vector2.init(position.width / 2, position.height),
rotation,
Shared.Color.White.alpha(0.75),
);
}
};
11 changes: 11 additions & 0 deletions src/Models/Player.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const raylib_math = @import("raylib-math");
const Shared = @import("../Shared.zig").Shared;
const Shoot = @import("./Shoot.zig").Shoot;
const Alien = @import("./Alien.zig").Alien;
const Flames = @import("./Flames.zig").Flames;

pub const Player = struct {
position: raylib.Vector2,
Expand Down Expand Up @@ -208,6 +209,16 @@ pub const Player = struct {
const shipTexture = Shared.Texture.Get(.Ship);
const shipWidthF = @as(f32, @floatFromInt(shipTexture.width));
const shipHeightF = @as(f32, @floatFromInt(shipTexture.height));

if (Shared.Input.Up_Held()) {
Flames.Draw(raylib.Rectangle.init(
self.position.x,
self.position.y,
base_size,
(base_size * 2) * self.acceleration,
), self.rotation - 180);
}

raylib.drawTexturePro(
shipTexture,
raylib.Rectangle.init(0, 0, shipWidthF, shipHeightF),
Expand Down
8 changes: 4 additions & 4 deletions src/Shaders/Wave.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ uniform vec2 size;

float freqX = 25.0;
float freqY = 25.0;
float ampX = 20.0;
float ampY = 20.0;
float speedX = 4.0;
float speedY = 4.0;
float ampX = 40.0;
float ampY = 40.0;
float speedX = 8.0;
float speedY = 8.0;

void main() {
float pixelWidth = 1.0 / size.x;
Expand Down
Binary file added src/Textures/Fire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 214f375

Please sign in to comment.