Skip to content

Commit

Permalink
Big batch of additions.
Browse files Browse the repository at this point in the history
Includes:

- Scoreboard
- Basic AI
- Resetting position after goals
- Several small improvements everywhere
  • Loading branch information
IanTayler committed Nov 17, 2020
1 parent 7225ad8 commit 86b2e02
Show file tree
Hide file tree
Showing 24 changed files with 502 additions and 173 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
.*.swp
assets/sprites/orig
25 changes: 25 additions & 0 deletions assets/fonts/Kottke Silkscreen License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Thank you for downloading Silkscreen, a type family for your Web graphics
by Jason Kottke (jason@kottke.org).

To install the Silkscreen type family, unzip this file and drag the files
into the Fonts folder in the Control Panel.

If you encounter any problems in using this font, please email me and I'll
see if I can try and fix it. Please note that I can't help you with any
installation issues. Please consult your system's help files for assistance.

This font is free for personal and corporate use and may be redistributed in
this unmodified form on your Web site. I would ask that you not modify and
then redistribute this font...although you may modify it for your own
personal use. If you really like this font and use it often, feel free to
mail me (e- or snail mail) some small token of your appreciation. A URL
of your work using Silkscreen would be appreciated as well.

All future bug fixes, updates, and additions to the Silkscreen type family
will be available on my Web site at the following URL:

http://www.kottke.org/plus/type/silkscreen/index.html

Again, thanks for downloading Silkscreen. Enjoy!

-jason
Binary file added assets/fonts/slkscr.ttf
Binary file not shown.
Binary file added assets/fonts/slkscrb.ttf
Binary file not shown.
Binary file added assets/fonts/slkscre.ttf
Binary file not shown.
Binary file added assets/fonts/slkscreb.ttf
Binary file not shown.
100 changes: 57 additions & 43 deletions assets/sprites/field_ichi_1.ron
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Prefab(
// Transform
// TODO: Can I live without this? I want to set it dynamically.
transform: (
translation: (128.0, 128.0, 0.0),
translation: (128.0, 216.0, 0.0),
),
),
// AnimationSetPrefab
Expand Down Expand Up @@ -132,8 +132,8 @@ Prefab(
),
// Collide a square around.
collision_box: (
upper_left_distance: [-8.0, 8.0],
lower_right_distance: [8.0, -8.0],
upper_left_distance: [-6.0, 6.0],
lower_right_distance: [6.0, -6.0],
),
movement_state: (
velocity: [0.0, 0.0],
Expand All @@ -146,6 +146,7 @@ Prefab(
speed: 48.0,
kick_strength: 256.0,
push_strength: 96.0,
side: UpperSide,
),
human: Human,
),
Expand All @@ -160,8 +161,8 @@ Prefab(
),
),
collision_box: (
upper_left_distance: [-25.0, 4.0],
lower_right_distance: [-21.0, -4.0],
upper_left_distance: [-31.0, 4.0],
lower_right_distance: [-27.0, -4.0],
),
animation_set: (
animations: [],
Expand All @@ -178,8 +179,8 @@ Prefab(
),
),
collision_box: (
upper_left_distance: [-25.0, 4.0],
lower_right_distance: [-21.0, -4.0],
upper_left_distance: [-31.0, 4.0],
lower_right_distance: [-27.0, -4.0],
),
animation_set: (
animations: [],
Expand All @@ -196,8 +197,8 @@ Prefab(
),
),
collision_box: (
upper_left_distance: [21.0, 4.0],
lower_right_distance: [25.0, -4.0],
upper_left_distance: [27.0, 4.0],
lower_right_distance: [31.0, -4.0],
),
animation_set: (
animations: [],
Expand All @@ -214,8 +215,8 @@ Prefab(
),
),
collision_box: (
upper_left_distance: [21.0, 4.0],
lower_right_distance: [25.0, -4.0],
upper_left_distance: [27.0, 4.0],
lower_right_distance: [31.0, -4.0],
),
animation_set: (
animations: [],
Expand All @@ -238,7 +239,13 @@ Prefab(
animation_set: (
animations: [],
),
extras: StaticData,
collision_box: (
upper_left_distance: [-26.0, 2.0],
lower_right_distance: [26.0, -6.0],
),
extras: NetData(
net: Net(side: LowerSide),
),
),
),
// UpperNet
Expand All @@ -256,7 +263,42 @@ Prefab(
animation_set: (
animations: [],
),
extras: StaticData,
collision_box: (
upper_left_distance: [-26.0, 6.0],
lower_right_distance: [26.0, -2.0],
),
extras: NetData(
net: Net(side: UpperSide),
),
),
),
// Ball
PrefabEntity(
data: (
sprite_scene: (
render: (
sheet: "field",
sprite_number: 14,
),
transform: (
translation: (128.0, 128.0, -0.1),
),
),
animation_set: (
animations: [],
),
collision_box: (
upper_left_distance: [-2.0, 2.0],
lower_right_distance: [2.0, -2.0],
),
movement_state: (
velocity: [0.0, 0.0],
deaccel: 192.0,
reset: false,
),
extras: BallData(
ball: Ball,
),
),
),
// Enemy
Expand Down Expand Up @@ -335,37 +377,9 @@ Prefab(
speed: 48.0,
kick_strength: 256.0,
push_strength: 96.0,
side: LowerSide,
),
robot: Robot,
),
),
),
// Ball
PrefabEntity(
data: (
sprite_scene: (
render: (
sheet: "field",
sprite_number: 14,
),
transform: (
translation: (128.0, 118.0, -0.1),
),
),
animation_set: (
animations: [],
),
collision_box: (
upper_left_distance: [-2.0, 2.0],
lower_right_distance: [2.0, -2.0],
),
movement_state: (
velocity: [0.0, 0.0],
deaccel: 192.0,
reset: false,
),
extras: BallData(
ball: Ball,
robot: Robot(logic_module: SillyRun),
),
),
),
Expand Down
18 changes: 13 additions & 5 deletions src/components/net.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
extern crate amethyst;
use crate::utils::Side;
use amethyst::{
assets::PrefabData,
derive::PrefabData,
ecs::{Component, DenseVecStorage, Entity, WriteStorage},
Error,
};
use serde::{Deserialize, Serialize};

use amethyst::ecs::{Component, DenseVecStorage};

#[derive(Debug)]
pub struct Net;
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PrefabData)]
#[prefab(Component)]
pub struct Net {
pub side: Side,
}

impl Component for Net {
type Storage = DenseVecStorage<Self>;
Expand Down
4 changes: 3 additions & 1 deletion src/components/player.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::utils;
use amethyst::{
assets::PrefabData,
derive::PrefabData,
Expand All @@ -11,13 +12,14 @@ pub enum ActionType {
Kick,
}

#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PrefabData)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PrefabData)]
#[prefab(Component)]
pub struct Player {
pub speed: f32,
pub action: Option<ActionType>,
pub kick_strength: f32,
pub push_strength: f32,
pub side: utils::Side,
}

impl Player {
Expand Down
18 changes: 16 additions & 2 deletions src/components/robot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@ use amethyst::{
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PrefabData)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum LogicModule {
SillyRun,
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PrefabData)]
#[prefab(Component)]
pub struct Robot;
pub struct Robot {
pub logic_module: LogicModule,
}

impl Default for Robot {
fn default() -> Self {
Robot {
logic_module: LogicModule::SillyRun,
}
}
}

impl Component for Robot {
type Storage = DenseVecStorage<Self>;
Expand Down
50 changes: 45 additions & 5 deletions src/fbsim.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
use crate::{components, config};
use amethyst::{
animation::AnimationSetPrefab,
assets::{PrefabData, PrefabLoader, ProgressCounter, RonFormat},
assets::{AssetStorage, Loader, PrefabData, PrefabLoader, ProgressCounter, RonFormat},
core::transform::Transform,
derive::PrefabData,
ecs::Entity,
ecs::{Entity, Read, ReadExpect},
error::Error,
prelude::*,
renderer::{
sprite::{prefab::SpriteScenePrefab, SpriteRender},
Camera,
},
ui,
};
use serde::{Deserialize, Serialize};

/// Animation ids used in a AnimationSet
#[derive(Eq, PartialOrd, PartialEq, Hash, Debug, Copy, Clone, Deserialize, Serialize)]
pub enum AnimationId {
PlayerRun,
PlayerJump,
PlayerCelebrate,
PlayerStand,
}

Expand All @@ -34,9 +33,13 @@ pub enum FieldSceneExtras {
robot: Option<components::Robot>,
},
BallData {
/// Ball info.
/// Ball component.
ball: components::Ball,
},
NetData {
/// Net component.
net: components::Net,
},
StaticData,
}

Expand All @@ -62,6 +65,42 @@ fn initialize_field(world: &mut World, progress_counter: &mut ProgressCounter) {
world.create_entity().with(field_prefab).build();
}

fn initialize_score(world: &mut World, progress_counter: &mut ProgressCounter) {
// If we can't load the font just let it crash.
let font = world.exec(
|(loader, asset_storage): (
ReadExpect<'_, Loader>,
Read<'_, AssetStorage<ui::FontAsset>>,
)| {
loader.load(
"fonts/slkscr.ttf",
ui::TtfFormat,
progress_counter,
&asset_storage,
)
},
);
let text = ui::UiText::new(
font,
"0 - 0".to_string(),
[0.0, 0.0, 0.0, 1.0],
25.0,
ui::LineMode::Single,
ui::Anchor::BottomLeft,
);
let ui_transform = ui::UiTransform::new(
String::from("scoreboard"), // id
ui::Anchor::TopLeft, // anchor
ui::Anchor::TopLeft, // pivot
20.0, // x
0.0, // y
0.4, // z
100.0, // width
30.0, // height
);
world.create_entity().with(text).with(ui_transform).build();
}

fn initialize_camera(world: &mut World) {
let mut transform = Transform::default();
transform.set_translation_xyz(config::SCREEN_WIDTH / 2.0, config::SCREEN_HEIGHT / 2.0, 1.0);
Expand Down Expand Up @@ -94,5 +133,6 @@ impl SimpleState for FieldState {
let world = data.world;
initialize_field(world, &mut self.progress_counter);
initialize_camera(world);
initialize_score(world, &mut self.progress_counter);
}
}
Loading

0 comments on commit 86b2e02

Please sign in to comment.