Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Zac8668/astratomic
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac8668 committed Dec 30, 2023
2 parents d4bb933 + 7ceff45 commit 982ff75
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 25 deletions.
144 changes: 144 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: 🚀 Release

on:
workflow_dispatch:
push:
tags:
- "v*"

defaults:
run:
shell: bash

jobs:
generate_changelog:
name: 📜 Generate Changelog
runs-on: ubuntu-latest
outputs:
release_body: ${{ steps.git-cliff.outputs.content }}
steps:
- name: ⬇️ Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: 📠 Calculate Git Cliff Args
id: cliff-args
run: |
if [ "${{ github.event_name }}" = "push" ]; then
echo "args=--latest" >> $GITHUB_OUTPUT
else
echo "args=--unreleased" >> $GITHUB_OUTPUT
fi
- name: 📜 Generate Changelog
uses: orhun/git-cliff-action@v2
id: git-cliff
with:
args: -vv --strip all ${{ steps.cliff-args.outputs.args }}

- name: 📝 Set Job Summary
run: |
echo "${{ steps.git-cliff.outputs.content }}" >> $GITHUB_STEP_SUMMARY
build_release:
name: 🔨 Build
runs-on: ${{ matrix.config.os }}
continue-on-error: true
outputs:
release_version: ${{ env.RELEASE_VERSION }}
strategy:
fail-fast: false
matrix:
config:
- { os: ubuntu-latest, target: "x86_64-unknown-linux-gnu" }
- { os: ubuntu-latest, target: "aarch64-unknown-linux-gnu" }
- { os: macos-latest, target: "x86_64-apple-darwin" }
- { os: macos-latest, target: "aarch64-apple-darwin" }
- { os: windows-latest, target: "x86_64-pc-windows-msvc" }

steps:
- name: 📠 Calculate Release Version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" -o "${{ github.event_name }}" = "schedule" ]; then
echo "RELEASE_VERSION=nightly-$(date '+%Y-%m-%d')" >> $GITHUB_ENV
else
echo "RELEASE_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: ⬇️ Checkout
uses: actions/checkout@v3

- name: 🦀 Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
target: ${{ matrix.config.target }}

- name: 🔨 Build
uses: actions-rs/cargo@v1
with:
command: build
args: --release --locked --target ${{ matrix.config.target }}
use-cross: true

- name: ⚙️ Prepare artifacts [Windows]
shell: bash
if: matrix.config.os == 'windows-latest'
run: |
release_dir="astratomic-${{ env.RELEASE_VERSION }}"
artifact_path="astratomic-${{ env.RELEASE_VERSION }}-${{ matrix.config.target }}.zip"
echo "ARTIFACT_PATH=$artifact_path" >> $GITHUB_ENV
mkdir $release_dir
cp target/${{ matrix.config.target }}/release/astratomic.exe $release_dir/
cp -R assets/ $release_dir/
cp LICENSE $release_dir/
7z a -tzip $artifact_path $release_dir/
- name: ⚙️ Prepare artifacts [Unix]
shell: bash
if: matrix.config.os != 'windows-latest'
run: |
release_dir="astratomic-${{ env.RELEASE_VERSION }}"
artifact_path="astratomic-${{ env.RELEASE_VERSION }}-${{ matrix.config.target }}.tar.gz"
echo "ARTIFACT_PATH=$artifact_path" >> $GITHUB_ENV
mkdir $release_dir
cp target/${{ matrix.config.target }}/release/astratomic $release_dir/
cp -R assets $release_dir
cp LICENSE $release_dir
tar -czvf $artifact_path $release_dir/
- name: ⏫️ Upload artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ env.ARTIFACT_PATH }}
path: ${{ env.ARTIFACT_PATH }}
if-no-files-found: error

publish_release:
name: 🚀 Publish
needs:
- generate_changelog
- build_release
runs-on: ubuntu-latest

steps:
- name: ⬇️ Download Artifacts
uses: actions/download-artifact@v2

- name: 🔒 Generate Checksums
run: for file in astratomic-*/astratomic-*; do openssl dgst -sha256 -r "$file" | awk '{print $1}' > "${file}.sha256"; done

- name: 🚀 Publish Release
uses: svenstaro/upload-release-action@v2
with:
release_name: ${{ needs.build_release.outputs.release_version }}
file: astratomic-*/astratomic-*
file_glob: true
overwrite: true
prerelease: ${{ github.event_name != 'push' }}
body: ${{ needs.generate_changelog.outputs.release_body }}
tag: ${{ needs.build_release.outputs.release_version }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion src/actors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::atom::State;
use crate::prelude::*;

#[derive(Component, Clone, Copy)]
Expand Down
3 changes: 2 additions & 1 deletion src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Chunk {
Ordering::Less => {}
_ => {
for atom in &mut atoms {
atom.state = crate::prelude::State::Powder;
atom.state = State::Powder;
atom.color = [
(230 + rand::thread_rng().gen_range(-20_i16..20_i16)) as u8,
(197 + rand::thread_rng().gen_range(-20_i16..20_i16)) as u8,
Expand Down Expand Up @@ -50,6 +50,7 @@ impl Chunk {
)
}

//This uses the CPU and is not used in-game anymore
pub fn update_image_positions(&self, image: &mut Image, positions: &HashSet<IVec2>) {
for pos in positions {
let pixel_index = (pos.y as usize * CHUNK_LENGHT + pos.x as usize) * 4;
Expand Down
2 changes: 1 addition & 1 deletion src/chunk_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct ChunkGroup<'a> {
pub center: &'a mut [Atom; CHUNK_LEN],
pub corners: ChunkCorners<'a>,
pub sides: ChunkSides<'a>,
// The pos of the center chunk on the chunk manager vec
/// Position of the center chunk.
pub center_pos: IVec2,
}

Expand Down
21 changes: 20 additions & 1 deletion src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Chunk Lenght consts
// Chunk lenght MUST be divisible by 4
pub const CHUNK_LENGHT: usize = 64;
pub const HALF_CHUNK_LENGHT: usize = CHUNK_LENGHT / 2;
Expand All @@ -6,12 +7,30 @@ pub const CHUNK_LEN: usize = CHUNK_LENGHT * CHUNK_LENGHT;
pub const HALF_CHUNK_LEN: usize = CHUNK_LEN / 2;
pub const QUARTER_CHUNK_LEN: usize = CHUNK_LEN / 4;

// Actor consts

pub const UP_WALK_HEIGHT: usize = 3;
pub const DOWN_WALK_HEIGHT: usize = 6;

// Player consts
pub const FUEL_MAX: f32 = 50.;
pub const FUEL_REGEN: f32 = 1.;
pub const FUEL_COMSUMPTON: f32 = 0.48;
pub const JETPACK_FORCE: f32 = 1.5;
pub const JETPACK_MAX: f32 = 3.;

pub const JUMP_MAG: f32 = 13.;
pub const RUN_SPEED: f32 = 5.;

pub const TOOL_DISTANCE: f32 = 32.;
pub const TOOL_RANGE: f32 = 12.;

// Engine consts
pub const ATOM_SIZE: usize = 3;
pub const _CAMERA_SPEED: f32 = 10.;
pub const GRAVITY: u8 = 1;
pub const TERM_VEL: u8 = 10;
pub const FRAMES_SLEEP: u8 = 4;
pub const CHUNKS_WIDTH: usize = 8;
pub const CHUNKS_HEIGHT: usize = 6;

pub const _CAMERA_SPEED: f32 = 10.;
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ mod geom_tools;
mod manager_api;
mod player;
mod prelude {
pub use crate::atom::State;
pub use crate::{
actors::*, animation::*, atom::State, atom::*, chunk::*, chunk_group::*, chunk_manager::*,
consts::*, debug::*, geom_tools::*, manager_api::*, player::*,
actors::*, animation::*, atom::*, chunk::*, chunk_group::*, chunk_manager::*, consts::*,
debug::*, geom_tools::*, manager_api::*, player::*,
};
pub use bevy::math::{ivec2, ivec3, uvec2, uvec3, vec2, vec3};
pub use bevy::prelude::*;
Expand Down
24 changes: 5 additions & 19 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,14 @@ pub struct Tool {
atoms: Vec<Atom>,
}

// Player consts
const FUEL_MAX: f32 = 50.;
const FUEL_REGEN: f32 = 1.;
const FUEL_COMSUMPTON: f32 = 0.48;
const JUMP_MAG: f32 = 13.;
const JETPACK_FORCE: f32 = 1.5;
const JETPACK_MAX: f32 = 3.;
const RUN_SPEED: f32 = 5.;

pub fn player_setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
mut chunk_manager: Query<&mut ChunkManager>,
) {
let mut chunk_manager = chunk_manager.single_mut();

let player_actor = Actor {
height: 17,
width: 10,
Expand Down Expand Up @@ -101,12 +93,8 @@ pub fn update_player(
let (mut actor, mut player, mut textatlas_sprite, mut anim_idxs) = player.single_mut();
let (mut tool_transform, tool_gtransform, mut tool_sprite, mut tool) = tool.single_mut();
let (mouse, keys) = input;

let mut chunk_manager = chunk_manager.single_mut();

let on_ground = on_ground(&chunk_manager, &actor);
let mut just_jumped = false;

// Gravity
if actor.vel.y < TERM_VEL as f32 {
actor.vel.y += 1.;
Expand All @@ -117,11 +105,13 @@ pub fn update_player(
actor.vel.x = x * RUN_SPEED;

// Refuel
let on_ground = on_ground(&chunk_manager, &actor);
if on_ground {
player.fuel = (player.fuel + FUEL_REGEN).clamp(0., Player::default().fuel);
}

// Jump and Jetpack
let mut just_jumped = false;
if keys.just_pressed(KeyCode::Space) {
if on_ground {
actor.vel.y -= JUMP_MAG;
Expand Down Expand Up @@ -179,20 +169,16 @@ pub fn update_player(
tool_transform.translation.x =
tool_transform.translation.x.abs() * (flip_bool as i8 * 2 - 1) as f32;

const TOOL_DISTANCE: f32 = 32.;
const TOOL_RANGE: f32 = 12.;

//Tool shooting and sucking atoms
let mut center_vec_y_flipped = center_vec;
center_vec_y_flipped.y *= -1.;
center_vec_y_flipped /= ATOM_SIZE as f32;

let tool_slope = Vec2::new(angle.cos(), -angle.sin());
let tool_front = center_vec_y_flipped + tool_slope * 8.;

let bound_slope = Vec2::new((angle + std::f32::consts::FRAC_PI_2).cos(), -(angle).cos());
let tool_front = center_vec_y_flipped + tool_slope * 8.;

let mut pos_to_update = vec![];

if mouse.pressed(MouseButton::Right) {
let new_tool_front = tool_front + tool_slope * 6.;
for i in 0..3 {
Expand Down

0 comments on commit 982ff75

Please sign in to comment.