mirror of
https://github.com/IgLemp/platformer.git
synced 2024-11-25 03:32:16 +01:00
Reduced readability of code
This commit is contained in:
parent
69eb723614
commit
deb26d5d49
@ -1,4 +1,6 @@
|
||||
zig version: 0.10.1
|
||||
|
||||
*TODO*
|
||||
Swap raylib bindings to raylib.zig from raylib-zig
|
||||
- Swap raylib bindings to raylib.zig from raylib-zig
|
||||
- Setup level loading
|
||||
- Setup texture loading
|
||||
|
23
src/main.zig
23
src/main.zig
@ -4,24 +4,11 @@ const std = @import("std");
|
||||
const obj = @import("types.zig");
|
||||
const phs = @import("physics.zig");
|
||||
|
||||
// fn load_level(comptime file_path: []const u8) void {
|
||||
// // TODO
|
||||
// }
|
||||
const DEBUG = true;
|
||||
|
||||
// NOTE
|
||||
// Coordinate system starts at top left corner, whitch means THE Y AXIS IS FLIPPED!!!
|
||||
|
||||
// TODO
|
||||
// Setup level loading
|
||||
// Setup texture loading
|
||||
|
||||
// DEBUG
|
||||
// pub fn main() anyerror!void {
|
||||
// load_level("./resources/scene.dat");
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// MAIN
|
||||
pub fn main() anyerror!void
|
||||
{
|
||||
@ -52,6 +39,7 @@ pub fn main() anyerror!void
|
||||
|
||||
var player: obj.Player = .{
|
||||
.box = .{ .x = 20, .y = 300, .width = 20, .height = 20 },
|
||||
.detection_box = .{ .width = 21, .height = 21 },
|
||||
.velocity = .{ .x = 0, .y = 0 },
|
||||
};
|
||||
|
||||
@ -79,7 +67,7 @@ pub fn main() anyerror!void
|
||||
if (fly) {
|
||||
if (rl.IsKeyDown(rl.KeyboardKey.KEY_UP)) { player.velocity.y += 1.5; }
|
||||
if (rl.IsKeyDown(rl.KeyboardKey.KEY_DOWN)) { player.velocity.y -= 1.5; }
|
||||
phs.free_fly(&player);
|
||||
phs.movement.free_fly(&player);
|
||||
} else {
|
||||
if (rl.IsKeyPressed(rl.KeyboardKey.KEY_UP)) { player.velocity.y = 15; } // jump
|
||||
phs.apply_forces(&player);
|
||||
@ -117,6 +105,9 @@ pub fn main() anyerror!void
|
||||
|
||||
for (map.tiles) |tile| {
|
||||
rl.DrawRectangleRec(tile.box, rl.GRAY);
|
||||
|
||||
// DEBUG
|
||||
if (DEBUG) {
|
||||
var midpoint: rl.Vector2 = .{ .x = tile.box.x + (tile.box.width / 2), .y = tile.box.y + (tile.box.height / 2) };
|
||||
rl.DrawCircleV( midpoint, 4, rl.GREEN);
|
||||
|
||||
@ -126,6 +117,8 @@ pub fn main() anyerror!void
|
||||
rl.DrawCircleV( .{ .x = tile.box.x, .y = tile.box.y }, 4, rl.ORANGE );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
camera.End();
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ pub fn apply_forces(player: *obj.Player) void {
|
||||
player.velocity.y = rlm.Clamp(player.velocity.y, -8, 8);
|
||||
}
|
||||
|
||||
|
||||
pub const movement = struct {
|
||||
pub fn free_fly(player: *obj.Player) void {
|
||||
// apply friction for X
|
||||
if (player.velocity.x > 0) { player.velocity.x -= FRICTION * rl.GetFrameTime(); }
|
||||
@ -42,6 +42,8 @@ pub fn free_fly(player: *obj.Player) void {
|
||||
player.velocity.x = rlm.Clamp(player.velocity.x, -4, 4);
|
||||
player.velocity.y = rlm.Clamp(player.velocity.y, -4, 4);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
pub fn apply_player_collisions(player: *obj.Player, map: obj.Map) void {
|
||||
|
@ -7,10 +7,16 @@ pub const Object = struct {
|
||||
|
||||
pub const Player = struct {
|
||||
box: rl.Rectangle,
|
||||
detection_box: NullOriginBox,
|
||||
velocity: rl.Vector2,
|
||||
// max_velocity: f32,
|
||||
};
|
||||
|
||||
const NullOriginBox = struct {
|
||||
height: f32,
|
||||
width: f32
|
||||
};
|
||||
|
||||
pub const Map = struct {
|
||||
tiles: []Object,
|
||||
};
|
Loading…
Reference in New Issue
Block a user