add finale section
This commit is contained in:
parent
1382b14313
commit
310a4aff55
108
src/game.zig
108
src/game.zig
@ -55,6 +55,8 @@ pub const Level = struct {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const key = "XXXXX-XXXXX-XXXXX";
|
||||||
|
|
||||||
gpa: Allocator,
|
gpa: Allocator,
|
||||||
|
|
||||||
canvas_size: Vec2,
|
canvas_size: Vec2,
|
||||||
@ -74,6 +76,10 @@ timers: Timer.List = .empty,
|
|||||||
level_exit_transition: ?Timer.Id = null,
|
level_exit_transition: ?Timer.Id = null,
|
||||||
level_enter_transition: ?Timer.Id = null,
|
level_enter_transition: ?Timer.Id = null,
|
||||||
|
|
||||||
|
finale: bool = false,
|
||||||
|
finale_timer: ?Timer.Id = null,
|
||||||
|
finale_counter: u32 = 0,
|
||||||
|
|
||||||
pub fn init(gpa: Allocator) !Game {
|
pub fn init(gpa: Allocator) !Game {
|
||||||
var self = Game{
|
var self = Game{
|
||||||
.gpa = gpa,
|
.gpa = gpa,
|
||||||
@ -334,20 +340,14 @@ fn hasStaricaseAt(self: *Game, position: Vec2) bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tick(self: *Game, input: Input) !void {
|
pub fn tickLevel(self: *Game, input: Input) !void {
|
||||||
const bg_color = rgb_hex("#222323").?;
|
const bg_color = rgb_hex("#222323").?;
|
||||||
|
|
||||||
Gfx.drawRectangle(.init(0, 0), .init(self.canvas_size.x, self.canvas_size.y), bg_color);
|
|
||||||
if (self.show_grid) {
|
|
||||||
self.drawGrid(.init(1, 1), rgb(20, 20, 20), 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.restart) {
|
if (input.restart) {
|
||||||
try self.restartLevel();
|
try self.restartLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.level.timers.now += input.dt;
|
self.level.timers.now += input.dt;
|
||||||
self.timers.now += input.dt;
|
|
||||||
|
|
||||||
var cover_opacity: f32 = 0;
|
var cover_opacity: f32 = 0;
|
||||||
var can_move = true;
|
var can_move = true;
|
||||||
@ -359,6 +359,10 @@ pub fn tick(self: *Game, input: Input) !void {
|
|||||||
|
|
||||||
if (self.timers.finished(timer)) {
|
if (self.timers.finished(timer)) {
|
||||||
self.current_level += 1;
|
self.current_level += 1;
|
||||||
|
if (self.current_level == self.levels.items.len) {
|
||||||
|
self.finale = true;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
try self.restartLevel();
|
try self.restartLevel();
|
||||||
self.level_exit_transition = null;
|
self.level_exit_transition = null;
|
||||||
|
|
||||||
@ -367,6 +371,7 @@ pub fn tick(self: *Game, input: Input) !void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (self.level_enter_transition) |timer| {
|
if (self.level_enter_transition) |timer| {
|
||||||
cover_opacity = 1 - self.timers.percent_passed(timer);
|
cover_opacity = 1 - self.timers.percent_passed(timer);
|
||||||
@ -440,6 +445,91 @@ pub fn tick(self: *Game, input: Input) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn tickFinale(self: *Game) !void {
|
||||||
|
const color = rgb(200, 200, 200);
|
||||||
|
|
||||||
|
const Line = struct {
|
||||||
|
pos: Vec2,
|
||||||
|
font: Gfx.Font,
|
||||||
|
text: []const u8,
|
||||||
|
};
|
||||||
|
|
||||||
|
const lines = [5]Line{
|
||||||
|
.{
|
||||||
|
.pos = Vec2.init(1, 1),
|
||||||
|
.font = Gfx.Font.default,
|
||||||
|
.text = "Congratulations scientist"
|
||||||
|
},
|
||||||
|
.{
|
||||||
|
.pos = Vec2.init(1, 2),
|
||||||
|
.font = Gfx.Font.default,
|
||||||
|
.text = "You have passed the entrance exam"
|
||||||
|
},
|
||||||
|
.{
|
||||||
|
.pos = Vec2.init(1, 3),
|
||||||
|
.font = Gfx.Font.default,
|
||||||
|
.text = "Here is your entry code"
|
||||||
|
},
|
||||||
|
.{
|
||||||
|
.pos = Vec2.init(1, 5),
|
||||||
|
.font = Gfx.Font.bold,
|
||||||
|
.text = key
|
||||||
|
},
|
||||||
|
.{
|
||||||
|
.pos = Vec2.init(1, 7),
|
||||||
|
.font = Gfx.Font.default,
|
||||||
|
.text = "I'll meet you at the lab"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (self.finale_timer == null) {
|
||||||
|
if (self.finale_counter < lines.len) {
|
||||||
|
self.finale_timer = try self.timers.start(self.gpa, .{
|
||||||
|
.duration = 2,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.finale_timer) |timer| {
|
||||||
|
if (self.timers.finished(timer)) {
|
||||||
|
self.finale_timer = null;
|
||||||
|
self.finale_counter += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (0..self.finale_counter) |i| {
|
||||||
|
const line = lines[i];
|
||||||
|
try Gfx.drawText(self.gpa, line.pos, line.font, color, line.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.finale_counter < lines.len) {
|
||||||
|
var opacity: f32 = 0;
|
||||||
|
if (self.finale_timer) |timer| {
|
||||||
|
opacity = self.timers.percent_passed(timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
const line = lines[self.finale_counter];
|
||||||
|
try Gfx.drawText(self.gpa, line.pos, line.font, color.multiply(Vec4.init(1, 1, 1, opacity)), line.text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn tick(self: *Game, input: Input) !void {
|
||||||
|
const bg_color = rgb_hex("#222323").?;
|
||||||
|
|
||||||
|
Gfx.drawRectangle(.init(0, 0), .init(self.canvas_size.x, self.canvas_size.y), bg_color);
|
||||||
|
if (self.show_grid) {
|
||||||
|
self.drawGrid(.init(1, 1), rgb(20, 20, 20), 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.timers.now += input.dt;
|
||||||
|
|
||||||
|
if (self.finale) {
|
||||||
|
try self.tickFinale();
|
||||||
|
} else {
|
||||||
|
try self.tickLevel(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn debug(self: *Game) !void {
|
pub fn debug(self: *Game) !void {
|
||||||
if (!imgui.beginWindow(.{
|
if (!imgui.beginWindow(.{
|
||||||
.name = "Debug",
|
.name = "Debug",
|
||||||
@ -457,4 +547,8 @@ pub fn debug(self: *Game) !void {
|
|||||||
if (imgui.button("Skip level")) {
|
if (imgui.button("Skip level")) {
|
||||||
try self.nextLevel();
|
try self.nextLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (imgui.button("Finale")) {
|
||||||
|
self.finale = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -294,7 +294,12 @@ pub const Font = struct {
|
|||||||
|
|
||||||
pub const default = Font{
|
pub const default = Font{
|
||||||
.variant = .regular,
|
.variant = .regular,
|
||||||
.size = 16,
|
.size = 64,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const bold = Font{
|
||||||
|
.variant = .bold,
|
||||||
|
.size = 64,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn setAsCurrent(self: Font) void {
|
pub fn setAsCurrent(self: Font) void {
|
||||||
@ -320,10 +325,13 @@ pub const Font = struct {
|
|||||||
);
|
);
|
||||||
c.fonsSetColor(fs, fons_color);
|
c.fonsSetColor(fs, fons_color);
|
||||||
|
|
||||||
|
pushTransform(.init(0, 0), 1.0/64.0);
|
||||||
|
defer popTransform();
|
||||||
|
|
||||||
_ = c.fonsDrawText(
|
_ = c.fonsDrawText(
|
||||||
fs,
|
fs,
|
||||||
pos.x,
|
pos.x*64,
|
||||||
pos.y,
|
pos.y*64,
|
||||||
text.ptr,
|
text.ptr,
|
||||||
text.ptr + text.len
|
text.ptr + text.len
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user