Browse Source

Added clippy

belt_ext
Weird Constructor 2 months ago
parent
commit
20b8c54158
  1. BIN
      assets/textures/clippy.png
  2. BIN
      assets/textures/clippy/Female Sprite by Sutemo.xcf
  3. BIN
      assets/textures/clippy/adjusted_sutemo_for_expot.xcf
  4. BIN
      assets/textures/clippy/sutemo_sheet.xcf
  5. 89
      src/main.rs
  6. 1
      src/renderer.rs
  7. 27
      src/sprites.rs

BIN
assets/textures/clippy.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
assets/textures/clippy/Female Sprite by Sutemo.xcf

Binary file not shown.

BIN
assets/textures/clippy/adjusted_sutemo_for_expot.xcf

Binary file not shown.

BIN
assets/textures/clippy/sutemo_sheet.xcf

Binary file not shown.

89
src/main.rs

@ -22,7 +22,7 @@ use chemtorio::{Chem, Chemtorio, EntityTypeTag};
use hecs::Entity;
use inventory::WeightFilter;
use renderer::{ChemtorioRenderer, Overlay};
use sprites::{EntitySprite, SpriteAssets, SC_OVERLAYS_IDX, SC_TILES_IDX};
use sprites::{EntitySprite, SpriteAssets, SC_OVERLAYS_IDX, SC_TILES_IDX, SC_CLIPPY_IDX};
#[derive(Clone, Copy)]
enum PlacementMode {
@ -64,6 +64,17 @@ impl ChemtorioRenderer for QuadRenderer {
self.sprites.draw(&ground_id, pos.0 as f32, pos.1 as f32);
}
fn render_clippy(&mut self, pos: (i32, i32), eyes_open: bool, frame: usize) {
let base_idx = if eyes_open {
0
} else {
2
};
self.sprites
.draw_anim_frame(&(SC_CLIPPY_IDX, base_idx), frame, pos.0 as f32, pos.1 as f32);
}
fn render_overlay(&mut self, pos: (i32, i32), overlay: Overlay) {
let id = match overlay {
Overlay::EQ => Some(6),
@ -178,6 +189,49 @@ impl QuadRenderer {
}
}
struct Notification {
delay_frames: u32,
cur_frame: u32,
message: String,
}
impl Notification {
pub fn new() -> Self {
Self {
delay_frames: 60,
cur_frame: 0,
message: String::from(""),
}
}
pub fn notify(&mut self, msg: &str) {
self.cur_frame = self.delay_frames;
self.message = msg.to_string();
}
pub fn notify_frame(&self) -> usize {
if self.cur_frame > (self.delay_frames / 2) {
1
} else {
0
}
}
pub fn tick(&mut self) {
if self.cur_frame > 0 {
self.cur_frame -= 1;
}
}
pub fn cur_message(&self) -> Option<&str> {
if self.cur_frame > 0 {
Some(&self.message[..])
} else {
None
}
}
}
use egui::ColorImage;
use egui_extras::RetainedImage;
@ -375,6 +429,9 @@ async fn main() {
let zoom_level_max = 3;
let zoom_level_min = -2;
let mut zoom_level: i32 = 0;
let mut notify = Notification::new();
loop {
// belts.tick();
@ -384,6 +441,8 @@ async fn main() {
}
sub += 1;
notify.tick();
// (m_pos.x / 32.0).round() * 32.0 + 16.0,
// (m_pos.y / 32.0).round() * 32.0 + 16.0,
// );
@ -610,6 +669,7 @@ async fn main() {
cur = dir.offs_pos_by(cur, 1);
if cur.0 >= min && cur.0 <= max {
chemtorio.build_belt_at_tile(cur, *dir);
notify.notify("Placed a fine belt there!");
}
}
last.0 = m_tile_pos.0;
@ -622,6 +682,7 @@ async fn main() {
cur = dir.offs_pos_by(cur, 1);
if cur.1 >= min && cur.1 <= max {
chemtorio.build_belt_at_tile(cur, *dir);
notify.notify("Placed a fine belt there!");
}
}
last.1 = m_tile_pos.1;
@ -632,6 +693,7 @@ async fn main() {
*dir = Some(Dir::from_poses(*last, m_tile_pos));
chemtorio.build_belt_at_tile(*last, dir.unwrap());
chemtorio.build_belt_at_tile(m_tile_pos, dir.unwrap());
notify.notify("Placed a fine belt there!");
*last = m_tile_pos;
placement_mode = PlacementMode::Belt(dir.unwrap());
}
@ -655,13 +717,16 @@ async fn main() {
}
PlacementMode::Source => {
chemtorio.place_source_at(m_tile_pos, cur_chem);
notify.notify("Placed a fine source there!");
}
PlacementMode::Picker(dir) => {
chemtorio.build_picker_at(m_tile_pos, dir);
notify.notify("Oh my, you placed a picker, sweet!");
}
PlacementMode::Belt(dir) => {
if belt_draw.is_none() || belt_draw.unwrap().1.is_none() {
chemtorio.build_belt_at_tile(m_tile_pos, dir);
notify.notify("A very fine belt there!");
}
belt_draw = None;
}
@ -773,6 +838,28 @@ async fn main() {
egui_macroquad::draw();
if let Some(msg) = notify.cur_message() {
let y_top = screen_height() - 100.0;
draw_rectangle(
0.0,
y_top,
1024.0,
60.0,
Color::from_rgba(0xfb, 0x79, 0x91, 0x80),
);
draw_text(msg, 248.0 + 2.0, y_top + 40.0 + 2.0, 30.0, Color::new(0.0, 0.0, 0.0, 1.0));
draw_text(msg, 248.0, y_top + 40.0, 30.0, Color::new(1.0, 1.0, 1.0, 1.0));
// let clip = EntitySprite::clippy_happy_eyes_closed();
qrend.render_clippy((128, screen_height() as i32 - 128), false, notify.notify_frame());
} else {
// let clip = EntitySprite::clippy_happy();
// qrend.render_entity((128, screen_height() as i32 - 128), &clip);
qrend.render_clippy((128, screen_height() as i32 - 128), true, 0);
}
next_frame().await
}
}

1
src/renderer.rs

@ -15,6 +15,7 @@ pub trait ChemtorioRenderer {
fn render_ground(&mut self, pos: (i32, i32), ground_id: usize);
fn render_overlay(&mut self, pos: (i32, i32), overlay: Overlay);
fn render_belt(&mut self, pos: (i32, i32), frame: usize, dir: Dir);
fn render_clippy(&mut self, pos: (i32, i32), eyes_open: bool, frame: usize);
fn render_belt_shadow(&mut self, pos: (i32, i32), frame: usize, dir: Dir);
fn render_underground(&mut self, pos: (i32, i32), frame: usize, begin: bool, dir: Dir);
fn render_underground_shadow(&mut self, pos: (i32, i32), frame: usize, begin: bool, dir: Dir);

27
src/sprites.rs

@ -12,6 +12,7 @@ pub const SC_PICKER_IDX: usize = 3;
pub const SC_BASE_IDX: usize = 4;
pub const SC_OVERLAYS_IDX: usize = 5;
pub const SC_UNDERG_IDX: usize = 6;
pub const SC_CLIPPY_IDX: usize = 7;
pub trait Sprite {
fn collection_index(&self) -> usize;
@ -85,6 +86,22 @@ impl Sprite for EntitySprite {
}
impl EntitySprite {
pub fn clippy_happy() -> EntitySprite {
Self {
collection_index: SC_CLIPPY_IDX,
texture_index: 0,
shadow_offs: 0,
}
}
pub fn clippy_happy_eyes_closed() -> EntitySprite {
Self {
collection_index: SC_CLIPPY_IDX,
texture_index: 2,
shadow_offs: 0,
}
}
pub fn picker_dir(dir: Dir) -> EntitySprite {
let idx = match dir {
Dir::U => 0,
@ -376,6 +393,13 @@ impl SpriteAssets {
None,
);
let clippy_tx = Image::from_file_with_format(
&load_file("assets/textures/clippy.png")
.await
.expect("load file"),
None,
);
// SC_TILES_IDX 0
self.collections
.push(SpriteCollection::from_image(tiles, 32, 16, 16));
@ -397,6 +421,9 @@ impl SpriteAssets {
// SC_UNDERG_IDX 6
self.collections
.push(SpriteCollection::from_image(underg_tx, 64, 4, 2));
// SC_CLIPPY_IDX 7
self.collections
.push(SpriteCollection::from_image(clippy_tx, 256, 4, 4));
}
pub fn draw_shadow<S: Sprite>(&self, sprite: &S, x: f32, y: f32) {

Loading…
Cancel
Save