~comcloudway/little_town

69abade8bede3507620ad857a8f82107b2110a4a — Jakob Meier 1 year, 8 months ago 299abcd
Added ability to place blocks behind or below others
3 files changed, 27 insertions(+), 19 deletions(-)

M README.md
M src/game/world.rs
M src/screens/build.rs
M README.md => README.md +10 -14
@@ 9,17 9,6 @@ with this 2D game
## Screenshot
![img](./screenshot.png)

To try out the example world on your device,
copy the `example.world` to the applications data dir.

On Linux, this is `~/.local/share/little_town/`,
if you are not running Linux,
have a look at the [ProjectDir Value Table](https://github.com/xdg-rs/dirs/tree/master/directories#projectdirs).

After copying the file,
launch the game and the world should appear in the world list


## Roadmap
- [x] Placing & Removing blocks
- [x] Basic Welcome Screen


@@ 32,17 21,24 @@ launch the game and the world should appear in the world list
  - [x] World creation screen
- [ ] (MAYBE) campaign mode (build & expand a city with limited ressources)
- [ ] Touch control
  - [ ] Move screen with 2 fingers
  - [ ] zoom camera with pinch gesture
  - [ ] place block with single click
  - [ ] destroy block with long click
- [ ] Settings menu (i.e for Keybindings)
- [ ] Game music?
- [ ] Background music (ambient)
- [ ] Add more assets
  - [x] SketchTown Expansion pack
  - [ ] (MAYBE) [Sketch Desert](https://kenney.nl/assets/sketch-desert)
- [x] Placing blocks on the other side of a block (Shift+Mouse)
  - [x] (requires) rotate block using Ctrl+Mouse

## Keymap
### in-Game
| Action | Key(s) / MouseButton |
|--------|----------------------|
| place Block | Left mouse button |
| place Block on inverted face | `<Shift>` and left mouse button |
| destroy Block | right mouse button |
| Save Game | `S` |
| Save & Quit | `Q` or `<Escape>` |


@@ 54,8 50,8 @@ launch the game and the world should appear in the world list
| South | `J` |
| West | `H` |
| East | `L` |
| rotate CCW | `<Shift>` and left mouse button |
| rotate CW | `<Shift>` and right mouse button |
| rotate CCW | `<Ctrl>` and left mouse button |
| rotate CW | `<Ctrl>` and right mouse button |

#### Camera movement
| Action | Key(s) / MouseButton |

M src/game/world.rs => src/game/world.rs +5 -0
@@ 81,6 81,11 @@ impl World {
    /// can be used to remove items
    /// or place items
    pub fn place_block(&mut self, pos: &Pos3, block: Block, dir: Direction) -> bool {
        // dont place block if there is a block here
        if self.grid.contains_key(pos) {
            return false;
        }

        if let Some(count) = self.inventory.contents.get_mut(&block) {
            // player has block
            if *count > 0 {

M src/screens/build.rs => src/screens/build.rs +12 -5
@@ 293,7 293,6 @@ impl GameComponent for BuildScreen {
    }
    fn ev_loop(&mut self) -> GameEvent {
        if let Some(world) = &mut self.world {

            if self.inventory_widgets.shown {
                // process input
                match self.inventory_widgets.widget_back.ev_loop() {


@@ 414,7 413,7 @@ impl GameComponent for BuildScreen {
                            // for a given pixel
                            let mut pos = Pos3::new(pos.x, pos.y, pos.z);

                            if is_key_down(KeyCode::LeftShift) {
                            if is_key_down(KeyCode::LeftControl) {
                                if let Some(block) = world.grid.get_mut(&pos) {
                                    if is_mouse_button_pressed(MouseButton::Left) {
                                        // rotate block CCW


@@ 448,15 447,23 @@ impl GameComponent for BuildScreen {
                                    let (x,y) = get_screen_coords(&pos, world.cam.scale, world.cam.center);
                                    let face = Face::from_xy(mx-x, my-y, world.cam.scale);

                                    // invert coordinate when left shift is pressed
                                    // allows placing blocks below & behind other block
                                    let factor = if is_key_down(KeyCode::LeftShift) {
                                        -1
                                    } else {
                                        1
                                    };

                                    match face.unwrap() {
                                        Face::Top => {
                                            pos.z+=1;
                                            pos.z+=factor;
                                        },
                                        Face::Left => {
                                            pos.x+=1;
                                            pos.x+=factor;
                                        },
                                        Face::Right => {
                                            pos.y+=1;
                                            pos.y+=factor;
                                        }
                                    }