From 8d20e02a4a79635ee850e7521d82eadd1757cf6d Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 7 Mar 2022 22:04:02 +0000 Subject: [PATCH] fix pong example to use new system TODO: fix transparency --- book/games/pong/Cargo.lock | 170 +++++++++++++++++++++++++-- book/games/pong/gfx/sprites.aseprite | Bin 1012 -> 1588 bytes book/games/pong/gfx/sprites.png | Bin 438 -> 0 bytes book/games/pong/gfx/sprites.toml | 6 - book/games/pong/src/main.rs | 37 ++---- 5 files changed, 168 insertions(+), 45 deletions(-) delete mode 100644 book/games/pong/gfx/sprites.png delete mode 100644 book/games/pong/gfx/sprites.toml diff --git a/book/games/pong/Cargo.lock b/book/games/pong/Cargo.lock index dc5d523b..6f006849 100644 --- a/book/games/pong/Cargo.lock +++ b/book/games/pong/Cargo.lock @@ -24,6 +24,9 @@ dependencies = [ "agb_sound_converter", "bare-metal", "bitflags", + "hashbrown", + "modular-bitfield", + "rustc-hash", ] [[package]] @@ -37,6 +40,7 @@ dependencies = [ name = "agb_image_converter" version = "0.6.0" dependencies = [ + "asefile", "image", "proc-macro2", "quote", @@ -64,6 +68,31 @@ dependencies = [ "syn", ] +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "asefile" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0d5f7de918fd4cb18249819fc4bd27f6a5dbfbc9dcb271727f27dacf17ce880" +dependencies = [ + "bitflags", + "byteorder", + "flate2", + "image", + "log", + "nohash", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -117,11 +146,44 @@ dependencies = [ [[package]] name = "deflate" -version = "1.0.0" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c86f7e25f518f4b81808a2cf1c50996a61f5c2eb394b2393bd87f2a4780a432f" +checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174" dependencies = [ "adler32", + "byteorder", +] + +[[package]] +name = "flate2" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f" +dependencies = [ + "cfg-if", + "crc32fast", + "libc", + "miniz_oxide 0.4.4", +] + +[[package]] +name = "getrandom" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" +dependencies = [ + "ahash", ] [[package]] @@ -132,9 +194,9 @@ checksum = "8a164bb2ceaeff4f42542bdb847c41517c78a60f5649671b2a07312b6e117549" [[package]] name = "image" -version = "0.24.1" +version = "0.23.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db207d030ae38f1eb6f240d5a1c1c88ff422aa005d10f8c6c6fc5e75286ab30e" +checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1" dependencies = [ "bytemuck", "byteorder", @@ -146,14 +208,66 @@ dependencies = [ ] [[package]] -name = "miniz_oxide" -version = "0.5.1" +name = "libc" +version = "0.2.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082" +checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "miniz_oxide" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435" +dependencies = [ + "adler32", +] + +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" dependencies = [ "adler", + "autocfg", ] +[[package]] +name = "modular-bitfield" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a53d79ba8304ac1c4f9eb3b9d281f21f7be9d4626f72ce7df4ad8fbde4f38a74" +dependencies = [ + "modular-bitfield-impl", + "static_assertions", +] + +[[package]] +name = "modular-bitfield-impl" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a7d5f7076603ebc68de2dc6a650ec331a062a13abaa346975be747bbfa4b789" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "nohash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0f889fb66f7acdf83442c35775764b51fed3c606ab9cee51500dbde2cf528ca" + [[package]] name = "num-integer" version = "0.1.44" @@ -177,9 +291,9 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.4.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" dependencies = [ "autocfg", "num-integer", @@ -196,15 +310,21 @@ dependencies = [ ] [[package]] -name = "png" -version = "0.17.5" +name = "once_cell" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc38c0ad57efb786dd57b9864e5b18bae478c00c824dc55a38bbc9da95dde3ba" +checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" + +[[package]] +name = "png" +version = "0.16.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" dependencies = [ "bitflags", "crc32fast", "deflate", - "miniz_oxide", + "miniz_oxide 0.3.7", ] [[package]] @@ -232,6 +352,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "serde" version = "1.0.136" @@ -252,6 +378,12 @@ dependencies = [ "syn", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "syn" version = "1.0.86" @@ -277,3 +409,15 @@ name = "unicode-xid" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" diff --git a/book/games/pong/gfx/sprites.aseprite b/book/games/pong/gfx/sprites.aseprite index 1c5bb9dc052f49f5e4a0a086f96099deee9a4125..5363cd3d01699fee39f23c72161da71e8d21a4e1 100644 GIT binary patch literal 1588 zcmb`Gdq`7J9LJBkO)<%3R=1$My<|a;>#{6zOcJx@g66B2W{KB?uWzqot^LZd+zTBO9**U zFD6p_XyQf)(cu{$SQ8c<_2Je3H|ugI#Afw!sCwbp@pwFGhop>i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bt stGbu1UcIrhc>a#I^vclL`rz4#gxM!Py|Hte2j0((x91&3D+LX|0JVH@d;kCd diff --git a/book/games/pong/gfx/sprites.png b/book/games/pong/gfx/sprites.png deleted file mode 100644 index 9964bf0b6400be2a60e1778c6ee65dbb0f91467f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 438 zcmV;n0ZIOeP)Px$a7jc#R9J=Wm`_T>Kop0++Cq1NRTo(a*|@Qwt`yx^yn+`{=n(|3&=ZK@3A}?M zC4%!x&uJ)c;SYiN>C-J z5>yGQ1pg^PO`Z?Re>>kT#}($co&jiXw6uVr+t*0!2~_1?Yj(2dW*dOPNu-guKO;%| zx)}n{B+9(+kKp4v1d?tjlEmts2+rR|0CX1TG?KJA>ca0Vm_84O!%x8Flc*LdV?bHc zXj)O4dp&sB{{|8rkn``JAl?6w<}ir1W0Lk&CW*f;Ow$2>1o=8pFNi>rB$hoR_5^YY z<(HG3fA<7xk*5dVr!jRtkS5Oy#m$1LKKT2CVX6=QRase{KKLh?rVqvKL7qOiC-|#A g_}c?heXu6@0SQNyXlYPJ`Tzg`07*qoM6N<$g20Wxl>h($ diff --git a/book/games/pong/gfx/sprites.toml b/book/games/pong/gfx/sprites.toml deleted file mode 100644 index 39c68850..00000000 --- a/book/games/pong/gfx/sprites.toml +++ /dev/null @@ -1,6 +0,0 @@ -version = "1.0" - -[image.sprites] -filename = "sprites.png" -tile_size = "16x16" -transparent_colour = "ff0044" \ No newline at end of file diff --git a/book/games/pong/src/main.rs b/book/games/pong/src/main.rs index c5fa5e78..5ccb9dfa 100644 --- a/book/games/pong/src/main.rs +++ b/book/games/pong/src/main.rs @@ -10,42 +10,27 @@ // which won't be a particularly clear error message. #![no_main] -use agb::display::object::Size; +use agb::display::object::{Graphics, Tag}; use agb::Gba; -// Put all the graphics related code in the gfx module -mod gfx { - use agb::display::object::ObjectControl; - - // Import the sprites into this module. This will create a `sprites` module - // and within that will be a constant called `sprites` which houses all the - // palette and tile data. - agb::include_gfx!("gfx/sprites.toml"); - - // Loads the sprites tile data and palette data into VRAM - pub fn load_sprite_data(object: &mut ObjectControl) { - object.set_sprite_palettes(sprites::sprites.palettes); - object.set_sprite_tilemap(sprites::sprites.tiles); - } -} +const GRAPHICS: &Graphics = agb::include_aseprite!("gfx/sprites.aseprite"); // The main function must take 0 arguments and never return. The agb::entry decorator // ensures that everything is in order. `agb` will call this after setting up the stack // and interrupt handlers correctly. #[agb::entry] fn main(mut gba: Gba) -> ! { - let _tiled = gba.display.video.tiled0(); - let mut object = gba.display.object.get(); - gfx::load_sprite_data(&mut object); - object.enable(); + let object = gba.display.object.get(); - let mut ball = object.get_object_standard(); + const BALL: &Tag = GRAPHICS.tags().get("Ball"); + let ball_sprite = object + .get_sprite(BALL.get_sprite(0)) + .expect("We should be able to load a sprite"); + let mut ball = object + .get_object(ball_sprite) + .expect("We should have enoguh space to store an object"); - ball.set_x(50) - .set_y(50) - .set_sprite_size(Size::S16x16) - .set_tile_id(4 * 2) - .show(); + ball.set_x(50).set_y(50).show(); let mut ball_x = 50; let mut ball_y = 50;