From 095095023d5175aedcdc6feeb1b76b3e05861666 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Tue, 6 Sep 2022 15:05:39 -0500 Subject: [PATCH] kickin ass now --- assets/grass-tile.png | Bin 0 -> 1422 bytes assets/snow-tile.png | Bin 0 -> 976 bytes src/main.rs | 55 +++++++++++++++++++++++++++++++++++------- 3 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 assets/grass-tile.png create mode 100644 assets/snow-tile.png diff --git a/assets/grass-tile.png b/assets/grass-tile.png new file mode 100644 index 0000000000000000000000000000000000000000..25c6237dc2a35b0526325b5922a2851166a3aa0e GIT binary patch literal 1422 zcmV;91#$X`P)00001b5ch_0Itp) z=>Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D1tUpBK~!i%m6g$r z*^FA@JZo=f&VoRZ^kFDR61*iYIuKs4AzJ^{i=nqPna`Mveezkg-Mm>c3D#l1rC z#Y3L>R-&&PV24KT6(nMs#E_P;0xOE&92wp>F!C8VFanl|w;)w3r9;81p;znU5eh0| zzf(y3F6?NpG25de_%XlOnJ=O+=BZp!Rzn*{@R!tUbpHZm@l0!Xexf>(i&#J#`X#5M z>jqr?*2mO}-`vm&-%&_KK%)5j20*2XycVw+gS;lCL&SO{aL?-=@%uEbxyi*G1(ft*|FcE2d@sQ$W3P$*FL}8}|$9#N7q2*^D zYphP;F}03yN&5v>?9)q5E6i(-Ui81Ai#LO&$yq1q3fkeeO zJnBb(WQnZslKCzd@pJ)0w2gJ&z{tn4+ISw#i>4Fd;WbMs?^@>Q<0}+7wjr`7jX|4? z>Qt%tv1~YVbiKsKMiI-MT93*pE6@cKIwkY?^B>vK#7DIjv5DXF2_lny1ap5ztC1B| z4Oo#2ct%7)AFxz>JRGCjM9}pA|vMSWhsr|9XUqR=bom1sfM^_C&Kr_!y=; z(Iy`+@s79L$yr32S)IMwB#jF0)Y16{Fh@T#!dEorMHGCnR2|Gd^6?e2K|_4(X^p%V zH}N_%N>qA}W?t_ADE@ec=zpa}j;qO0DeT&i`zu6jgGUA91I^KqLtoe+hO|;?o>I4=U(R7O6#v14X3iF5RS zh>H-};Ndf`cL21_OazaIY`sKLEzJc>Knk* zi-{*KZ)k;kdWC$e-Gp3Up`hx)H;jphN~A9x4^6ZQ`p#8qXSH;|Y%-<}v10I;F!`h-^dr zHYmgjtci}%m?sa3ziwd1hE@@GVwiAX`ELtek8||(2w4+E_NZz$+ZTiYiL4N&JFLK& z_b)(Tna4jhkII!J!yVZl<*h2!D_aj6j#(IK27=kZR zuD(|U+=dlhpHT;1@mr)-+owXz#{gwKj?FN65!wfbdFLt?FRhq=WYwgC{NX c<^TNt52l#05>{Y^fdBvi07*qoM6N<$g1j}U3IG5A literal 0 HcmV?d00001 diff --git a/assets/snow-tile.png b/assets/snow-tile.png new file mode 100644 index 0000000000000000000000000000000000000000..b67880953a10dec010561571fe18df2ddfb36ade GIT binary patch literal 976 zcmV;>126oEP)00001b5ch_0Itp) z=>Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D17%4>K~!i%<(NTw z<1h$D)A{CDS>|9lSa!+1GB^-|0RfWiY0|z$i)Hi!5|-V5-S79q5VzZnERW;yNY;~H z{~~<_oX=;n*0!6R%&C>V^kG4%obrc$&jEQLbR9yj4`^tDZ3Q{rP-Mpz3U+`=#bXBu@pZjk`H1MPBvmKtLGUC1N~)L%91^PnB(8)UY{kHF`wbT_ zlNzk}V2EY`jGR`nk)QxZ&Em_}xB^3b=bIQN#&c5#U@5?^mV#9RL&Acv>b&r2lrC89 z`;Sqz7Ve4!yzhIUSP2!-)kU$i>>p)p)kQMIYX=6@Z6&El><}*vq7+sw1osfSE<@95 z6UkLL+q~VSLFoF)@+o0Q8Qy(F>8f|FL`?+ZC`y?x)7(~n4+P!-h6$1eY~GeQ3Vd;N zg;*89#4#+Dye(Z(S|Q%|7%lQ6S}4t%to1|OTS=NXSr0H!C9&me6t5LF1DQR-BW@(A z&`Je;0%fKZV)YEbHA6!+XijYwxjvww0yM!)c@<#q4Ume=M^Oq?K&s1o3Wl`NkgybQ zIvZ{jsU~eSTx5ukKSqB?0d{BOy_Q?d{o~TB%y5XM0Jk-nSO`cR5F2F^<-hdXP)rM9 z=gO>YmG!?>0(E;Uc2><3{9~(EnXE^PE}s&CHxS=NTp#(Z;buRq%s_}{0Tp$NoYg8| zUYUUqAAgMQ*g^nqLaX~{lo7bQ`gywl6i#}hr>T?6rOJeDj*yH0000) { commands.spawn_bundle(Camera2dBundle{ transform: Transform::from_xyz(0.0, 0.0, 0.0), @@ -17,23 +24,52 @@ fn setup(mut commands: Commands, asset_server: Res) { commands.spawn() .insert(Player) .insert_bundle(SpriteBundle{ - texture: asset_server.load("icon.png"), transform: Transform::from_xyz(0.0, 0.0, 0.0), + texture: asset_server.load("icon.png"), + sprite: Sprite{ + color: Color::rgb(1.0, 1.0, 1.0), + custom_size: Some(Vec2::new(32.0, 32.0)), + ..default() + }, ..default() }); + + for x in 0..10 { + for y in 0..10 { + commands.spawn_bundle(SpriteBundle{ + transform: Transform::from_xyz(32.0 * x as f32, 32.0 * y as f32, 0.0), + texture: asset_server.load("grass-tile.png"), + sprite: Sprite{ + color: Color::rgb(1.0, 1.0, 1.0), + custom_size: Some(Vec2::new(32.0, 32.0)), + ..default() + }, + ..default() + }); + } + } + } fn map_key(now: &Res>, key: KeyCode, handler: &mut bool) { - if now.just_pressed(key) { *handler = true; } - if now.just_released(key) { *handler = false; } + *handler = now.just_pressed(key); + // if now.just_pressed(key) { *handler = true; } + // if now.just_released(key) { *handler = false; } } fn keyboard_input(now: Res>, mut input_state: ResMut) { - map_key(&now, KeyCode::A, &mut input_state.left); map_key(&now, KeyCode::W, &mut input_state.up); + map_key(&now, KeyCode::Up, &mut input_state.up); + + map_key(&now, KeyCode::A, &mut input_state.left); + map_key(&now, KeyCode::Left, &mut input_state.left); + map_key(&now, KeyCode::S, &mut input_state.down); + map_key(&now, KeyCode::Down, &mut input_state.down); + map_key(&now, KeyCode::D, &mut input_state.right); + map_key(&now, KeyCode::Right, &mut input_state.right); } fn player_movement( @@ -41,10 +77,10 @@ fn player_movement( input_state: Res ) { let mut player_t = query.single_mut(); - if input_state.up { player_t.translation.y += 1.0; } - if input_state.down { player_t.translation.y -= 1.0; } - if input_state.left { player_t.translation.x -= 1.0; } - if input_state.right { player_t.translation.x += 1.0; } + if input_state.up { player_t.translation.y += 32.0; } + if input_state.down { player_t.translation.y -= 32.0; } + if input_state.left { player_t.translation.x -= 32.0; } + if input_state.right { player_t.translation.x += 32.0; } } #[derive(Default, Debug)] @@ -59,8 +95,9 @@ fn main() { App::new() .add_plugins(DefaultPlugins) .insert_resource(ClearColor(BACKGROUND_COLOR)) - .add_startup_system(setup) .insert_resource(PlayerInput::default()) + .insert_resource(TileSize{width: TILE_WIDTH, height: TILE_HEIGHT}) + .add_startup_system(setup) .add_system(keyboard_input) .add_system(player_movement) .add_system(bevy::window::close_on_esc)