Skip to content

Commit

Permalink
Basic rotation!
Browse files Browse the repository at this point in the history
- Switched to WSAD cause that's easier
  • Loading branch information
Tony Bark committed May 6, 2024
1 parent 86aa6ef commit b7d7fdc
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ const GameScreen = enum {
lot,
};

const Rotations = enum {
left,
right,
pub fn changeRotions(self: Rotations) Rotations {
return self;
}

pub fn init(self: Rotations) Rotations {
return self;
}
};

// Still in the proof of concept phase, don't mind the mess
pub fn main() anyerror!void {
const screen_width = 800;
Expand All @@ -25,7 +37,7 @@ pub fn main() anyerror!void {
// var zoom: f32 = 10;

var camera = rl.Camera3D{
.position = rl.Vector3.init(0.0, 20.0, 90.0),
.position = rl.Vector3.init(-90.0, 20.0, 90.0),
.target = rl.Vector3.init(0, 0.0, 0),
.up = rl.Vector3.init(0, 1.0, 0),
.fovy = 10,
Expand All @@ -35,6 +47,8 @@ pub fn main() anyerror!void {
const floorLevel = rl.Vector3.init(0.0, 0.0, 0.0);
const itemStatic = rl.Vector3.init(0.0, 2.0, 0.0);

var get_rotate = Rotations.init(Rotations.right);

// const planePosition = rl.Vector3.init(0.0, 0.0, 0.0);

// var textBox = rl.Rectangle.init(screen_width / 2.0 - 100, 180, 50);
Expand All @@ -48,10 +62,12 @@ pub fn main() anyerror!void {
// defer rl.closeAudioDevice();
const logo = rl.Texture.init("resources/logo.png");
const splash = rl.Texture.init("resources/tsosplash.png");
const table3 = rl.Texture.init("resources/items/dorms/table_3.png");
const table4 = rl.Texture.init("resources/items/dorms/table_4.png");
defer rl.unloadTexture(splash);
defer rl.unloadTexture(logo);
defer rl.unloadTexture(table4);
defer rl.unloadTexture(table3);

while (!rl.windowShouldClose()) {

Expand All @@ -71,18 +87,16 @@ pub fn main() anyerror!void {
.lot => {
const zoom_increment = 5;

if (rl.isKeyPressed(rl.KeyboardKey.key_equal)) {
if (camera.fovy <= 10 or camera.fovy >= 20) {
if (rl.isKeyPressed(rl.KeyboardKey.key_s)) {
if (camera.fovy == 10) {
camera.fovy += zoom_increment;
}

dbg.print("Zoom level: {any}\n", .{
camera.fovy,
});
}

if (rl.isKeyPressed(rl.KeyboardKey.key_minus)) {
if (camera.fovy <= 10 or camera.fovy >= 2.0) {
} else if (rl.isKeyPressed(rl.KeyboardKey.key_w)) {
if (camera.fovy == 15) {
camera.fovy -= zoom_increment;
}

Expand All @@ -91,6 +105,16 @@ pub fn main() anyerror!void {
});
}

if (rl.isKeyPressed(rl.KeyboardKey.key_a)) {
camera.position = rl.Vector3.init(-90.0, 20.0, 90.0);
get_rotate = Rotations.changeRotions(Rotations.left);
dbg.print("Roate right\n", .{});
} else if (rl.isKeyPressed(rl.KeyboardKey.key_d)) {
camera.position = rl.Vector3.init(90.0, 20.0, 90.0);
get_rotate = Rotations.changeRotions(Rotations.right);
dbg.print("Roate left\n", .{});
}

// camera.update(rl.CameraMode.camera_custom);
},
}
Expand Down Expand Up @@ -121,7 +145,11 @@ pub fn main() anyerror!void {
defer camera.end();

rl.drawPlane(floorLevel, rl.Vector2.init(64, 64), rl.Color.dark_green);
rl.drawBillboard(camera, table4, itemStatic, 2.0, rl.Color.white);
switch (get_rotate) {
.right => rl.drawBillboard(camera, table4, itemStatic, 2.0, rl.Color.white),
.left => rl.drawBillboard(camera, table3, itemStatic, 2.0, rl.Color.white),
}

// rl.drawGrid(64, 1.0);
},
}
Expand Down

0 comments on commit b7d7fdc

Please sign in to comment.