blob: c8492df382790ab7636f993e469dfdb37e35d5e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
const std = @import("std");
const spoon = @import("spoon");
const ball = @import("ball.zig");
const brothers = @import("brothers.zig");
const playfield = @import("playfield.zig");
pub const Game = struct {
ball: ball.Ball = undefined,
brothers: [2]brothers.Brother = undefined,
side: brothers.Side = undefined,
pub fn draw(self: Game, rc: *spoon.Term.RenderContext) !void {
try playfield.draw(rc);
try self.brothers[0].draw(rc);
try self.brothers[1].draw(rc);
try self.ball.draw(rc);
}
pub fn moveJump(self: *Game, side: brothers.Side) void {
self.brothers[@enumToInt(side)].moveJump();
}
pub fn moveLeft(self: *Game, side: brothers.Side) void {
self.brothers[@enumToInt(side)].moveLeft();
}
pub fn moveRight(self: *Game, side: brothers.Side) void {
self.brothers[@enumToInt(side)].moveRight();
}
pub fn reset(self: *Game, side: brothers.Side) void {
self.side = side;
self.resetRound();
}
pub fn resetRound(self: *Game) void {
self.ball.reset(.left);
self.brothers[0].reset(.left);
self.brothers[1].reset(.right);
}
pub fn step(self: *Game) void {
self.ball.step();
self.brothers[0].step(&self.ball);
self.brothers[1].step(&self.ball);
}
};
|