entity.zig (1092B)
1 const raylib = @import("raylib"); 2 3 const Grunt = @import("./enemy_types/grunt.zig"); 4 const Blorb = @import("./enemy_types/blorb.zig"); 5 6 pub const EntityType = enum { grunt, blorb }; 7 8 pub const Entity = union(EntityType) { 9 grunt: Grunt, 10 blorb: Blorb, 11 12 pub fn render(entity: *Entity) void { 13 switch (entity.*) { 14 .grunt => |*grunt| grunt.render(), 15 .blorb => |*blorb| blorb.render(), 16 } 17 } 18 19 pub fn handleDamage(entity: *Entity, damage: f32) bool { 20 return switch (entity.*) { 21 .grunt => |*grunt| grunt.handleDamage(damage), 22 .blorb => |*blorb| blorb.handleDamage(damage), 23 }; 24 } 25 26 pub fn move(entity: *Entity, target_position: raylib.Vector2) void { 27 switch (entity.*) { 28 .grunt => |*grunt| grunt.handleMovement(target_position), 29 .blorb => |*blorb| blorb.handleMovement(), 30 } 31 } 32 33 pub fn tick(entity: *Entity) void { 34 switch (entity.*) { 35 .grunt => |*grunt| grunt.tick(), 36 .blorb => |*blorb| blorb.tick(), 37 } 38 } 39 };