Skip to content

Commit

Permalink
Add aliens and meteors to Menu Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanlangston committed Jan 3, 2024
1 parent 05778d0 commit b7dc8ac
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Models/Player.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub const Player = struct {
default: bool,
};

pub inline fn init(screenSize: raylib.Vector2, shipHeight: f32) Player {
pub inline fn init(screenSize: raylib.Vector2, shipHeight: f32, colliderSize: f32) Player {
const position = raylib.Vector2.init(
screenSize.x / 2,
(screenSize.y - shipHeight) / 2,
Expand All @@ -47,7 +47,7 @@ pub const Player = struct {
.collider = raylib.Vector3.init(
position.x,
position.y,
12,
colliderSize,
),
.color = Shared.Color.Gray.Light,
};
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/AsteroidsViewModel.zig
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create(
shieldLevel = MAX_SHIELD;
nextShieldLevel = MAX_SHIELD;

player = Player.init(screenSize, shipHeight);
player = Player.init(screenSize, shipHeight, 12);

score = 0;

Expand Down
39 changes: 39 additions & 0 deletions src/ViewModels/MenuViewModel.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const Logger = @import("../Logger.zig").Logger;
const raylib = @import("raylib");
const Starscape = @import("../Models/Starscape.zig").Starscape;
const AsteroidsViewModel = @import("../ViewModels/AsteroidsViewModel.zig").AsteroidsViewModel;
const Meteor = @import("../Models/Meteor.zig").Meteor;
const Alien = @import("../Models/Alien.zig").Alien;
const Player = @import("../Models/Player.zig").Player;
const Shoot = @import("../Models/Shoot.zig").Shoot;

pub const Selection = enum {
Start,
Expand All @@ -22,12 +26,47 @@ pub const MenuViewModel = Shared.View.ViewModel.Create(
pub var frameCount: f32 = 0;

var starScape: Starscape = undefined;
pub var meteors: [30]Meteor = undefined;
pub var aliens: [10]Alien = undefined;
pub const player = Player.init(AsteroidsVM.screenSize, AsteroidsVM.shipHeight, 0);
var shoots: [0]Shoot = undefined;

pub inline fn init() void {
frameCount = 0;

starScape = Starscape.init(AsteroidsVM.screenSize);
AsteroidsVM.starScape = starScape;

inline for (0..meteors.len) |i| {
meteors[i] = Meteor.init(Shared.Random.Get().float(f32) * 40 + 10);
meteors[i].RandomizePositionAndSpeed(player, AsteroidsVM.screenSize, false);
meteors[i].active = true;
}
inline for (0..aliens.len) |i| {
aliens[i] = Alien.init();
aliens[i].RandomizePosition(player, AsteroidsVM.screenSize, false);
aliens[i].active = true;
}
}

pub inline fn Update() void {
inline for (0..meteors.len) |i| {
// Check Large
switch (meteors[i].Update(player, &shoots, &aliens, &shoots, AsteroidsVM.screenSize, AsteroidsVM.shipHeight, AsteroidsVM.PLAYER_BASE_SIZE)) {
.default => {},
.shot => |shot| {
_ = shot;
},
.collide => {},
}
}

inline for (0..aliens.len) |i| {
switch (aliens[i].Update(player, &shoots, &shoots, AsteroidsVM.screenSize)) {
.shot => {},
.default => {},
}
}
}

pub inline fn GetSelectionText(select: Selection) [:0]const u8 {
Expand Down
18 changes: 11 additions & 7 deletions src/Views/MenuView.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,29 @@ const Shared = @import("../Shared.zig").Shared;
const vm: type = MenuViewModel.GetVM();
const AsteroidsVM = AsteroidsViewModel.GetVM();

pub fn Background(target: raylib.Vector2) void {
raylib.drawRectangleLinesEx(
raylib.Rectangle.init(0, 0, AsteroidsVM.screenSize.x, AsteroidsVM.screenSize.y),
5,
Shared.Color.Green.Light,
);

fn Background(target: raylib.Vector2) void {
AsteroidsVM.starScape.Draw(
AsteroidsVM.screenSize.x,
AsteroidsVM.screenSize.y,
target,
);

inline for (0..vm.aliens.len) |i| {
vm.aliens[i].Draw();
}

inline for (0..vm.meteors.len) |i| {
vm.meteors[i].Draw(vm.player.position);
}
}

pub fn DrawFunction() Shared.View.Views {
raylib.clearBackground(Shared.Color.Tone.Dark);

Shared.Music.Play(.TitleScreenMusic);

vm.Update();

const locale = Shared.Locale.GetLocale().?;
const font = Shared.Font.Get(.Unknown);

Expand Down

0 comments on commit b7dc8ac

Please sign in to comment.