diff --git a/DESCRIPTION b/DESCRIPTION
new file mode 100644
index 0000000..ba4845c
--- /dev/null
+++ b/DESCRIPTION
@@ -0,0 +1,11 @@
+Package: pacman
+Version: 1.0.0
+Depends:
+ nara,
+ eventloop,
+ audio,
+ grid
+Remotes:
+ coolbutuseless/nara,
+ coolbutuseless/eventloop
+RoxygenNote: 7.2.0
diff --git a/NAMESPACE b/NAMESPACE
new file mode 100644
index 0000000..2492c04
--- /dev/null
+++ b/NAMESPACE
@@ -0,0 +1,4 @@
+# Generated by roxygen2: do not edit by hand
+
+export(play)
+import(nara)
diff --git a/board.R b/R/board.R
similarity index 98%
rename from board.R
rename to R/board.R
index 0dc79a1..07ee5b1 100644
--- a/board.R
+++ b/R/board.R
@@ -88,7 +88,7 @@ board <- matrix(board, nrow = 31, ncol = 28, byrow = TRUE)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' Load the maze parts
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-im <- suppressWarnings(png::readPNG("image/game-maze.png"))
+im <- suppressWarnings(png::readPNG(system.file("image/game-maze.png", package = "pacman")))
if (FALSE) {
dim(im)
grid.raster(im)
diff --git a/game.R b/R/game.R
similarity index 97%
rename from game.R
rename to R/game.R
index 75633ad..576ddd0 100644
--- a/game.R
+++ b/R/game.R
@@ -1,18 +1,3 @@
-
-
-if (FALSE) {
- remotes::install_github('coolbutuseless/eventloop')
- remotes::install_github('coolbutuseless/nara')
-}
-
-library(grid)
-library(nara)
-library(eventloop)
-
-source("board.R")
-source("sprites.R")
-source("sound.R")
-
# set.seed(1)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -274,7 +259,7 @@ update_game <- function(event, frame_num, ...) {
}
# Render to screen
- grid.raster(board_nr)
+ grid::grid.raster(board_nr)
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -310,12 +295,10 @@ update_game <- function(event, frame_num, ...) {
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# Run the game within an event loop
+#' Run the game within an event loop
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-eventloop::run_loop(update_game, width = 7, height = 8, fps_target = 50)
-
-
-
-
-
-
+#' @import nara
+#' @export
+play <- function() {
+ eventloop::run_loop(update_game, width = 7, height = 8, fps_target = 50)
+}
diff --git a/R/sound.R b/R/sound.R
new file mode 100644
index 0000000..ba59759
--- /dev/null
+++ b/R/sound.R
@@ -0,0 +1,19 @@
+
+library(audio)
+
+
+# Tweak the audio to be compatible with the audio package
+# sox -r 8000 -b 8 -e signed-integer -c 1 %s -b 16 %s
+# sox %s -b 16 %s
+
+sound <- list(
+ intro = audio::load.wave(system.file("./sound/intro.wav", package = "pacman")),
+ chomp = audio::load.wave(system.file("./sound/chomp.wav", package = "pacman")),
+ death = audio::load.wave(system.file("./sound/death.wav", package = "pacman")),
+ ghost = audio::load.wave(system.file("./sound/ghost.wav", package = "pacman")),
+ extra = audio::load.wave(system.file("./sound/extra.wav", package = "pacman")),
+ fruit = audio::load.wave(system.file("./sound/fruit.wav", package = "pacman")),
+ inter = audio::load.wave(system.file("./sound/inter.wav", package = "pacman"))
+)
+
+# audio::play(sound$inter)
diff --git a/sprites.R b/R/sprites.R
similarity index 97%
rename from sprites.R
rename to R/sprites.R
index 93b5c64..1c2e408 100644
--- a/sprites.R
+++ b/R/sprites.R
@@ -6,7 +6,7 @@ library(nara)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Load the spritemap for pacman and the ghosts
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-spritemap <- png::readPNG("image/game-sprites.png")
+spritemap <- png::readPNG(system.file("image/game-sprites.png", package = "pacman"))
if (FALSE) {
dim(spritemap)
diff --git a/README.md b/README.md
index e09cb86..1cd16c1 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ The game plays in realtime using 2 key packages:
## Gameplay
-
+
## Controls
@@ -34,33 +34,11 @@ your 5 pacman lives.
## Installation
-1. Install the dependencies
- * [`{nara}`](https://github.com/coolbutuseless/nara)
- * [`{eventloop}`](https://github.com/coolbutuseless/eventloop)
-2. Retrieve the pacman game code from [github](https://github.com/coolbutless/pacman)
- * Note that this is *not* a package, but just a collection of R scripts and
- code. This should make it easier to hack on, extend and adapt.
-
+1. `remotes::install_github("coolbutuseless/pacman")`
+```{r}
+pacman::play()
```
-library(remotes)
-
-# Packages required for interactive rendering
-remotes::install_github("coolbutuseless/eventloop")
-remotes::install_github("coolbutuseless/nara")
-
-install.packages('audio')
-
-# Grab a copy of the pacman game code by cloning the repository
-system("git clone https://github.com/coolbutuseless/pacman.git")
-
-
-
-# Change into the source code directory and run
-setwd('pacman')
-source('game.R')
-```
-
## Requirements
diff --git a/image/game-maze.png b/inst/image/game-maze.png
similarity index 100%
rename from image/game-maze.png
rename to inst/image/game-maze.png
diff --git a/image/game-sprites.png b/inst/image/game-sprites.png
similarity index 100%
rename from image/game-sprites.png
rename to inst/image/game-sprites.png
diff --git a/sound/chomp.wav b/inst/sound/chomp.wav
similarity index 100%
rename from sound/chomp.wav
rename to inst/sound/chomp.wav
diff --git a/sound/death.wav b/inst/sound/death.wav
similarity index 100%
rename from sound/death.wav
rename to inst/sound/death.wav
diff --git a/sound/extra.wav b/inst/sound/extra.wav
similarity index 100%
rename from sound/extra.wav
rename to inst/sound/extra.wav
diff --git a/sound/fruit.wav b/inst/sound/fruit.wav
similarity index 100%
rename from sound/fruit.wav
rename to inst/sound/fruit.wav
diff --git a/sound/ghost.wav b/inst/sound/ghost.wav
similarity index 100%
rename from sound/ghost.wav
rename to inst/sound/ghost.wav
diff --git a/sound/inter.wav b/inst/sound/inter.wav
similarity index 100%
rename from sound/inter.wav
rename to inst/sound/inter.wav
diff --git a/sound/intro.wav b/inst/sound/intro.wav
similarity index 100%
rename from sound/intro.wav
rename to inst/sound/intro.wav
diff --git a/video/pacman-game.gif b/inst/video/pacman-game.gif
similarity index 100%
rename from video/pacman-game.gif
rename to inst/video/pacman-game.gif
diff --git a/man/extract.Rd b/man/extract.Rd
new file mode 100644
index 0000000..69c212c
--- /dev/null
+++ b/man/extract.Rd
@@ -0,0 +1,11 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/sprites.R
+\name{extract}
+\alias{extract}
+\title{Extract a sprite from the spritemap}
+\usage{
+extract(row, col)
+}
+\description{
+Extract a sprite from the spritemap
+}
diff --git a/man/im.Rd b/man/im.Rd
new file mode 100644
index 0000000..17f2964
--- /dev/null
+++ b/man/im.Rd
@@ -0,0 +1,16 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/board.R
+\docType{data}
+\name{im}
+\alias{im}
+\title{Load the maze parts}
+\format{
+An object of class \code{array} of dimension 248 x 368 x 3.
+}
+\usage{
+im
+}
+\description{
+Load the maze parts
+}
+\keyword{datasets}
diff --git a/man/play.Rd b/man/play.Rd
new file mode 100644
index 0000000..b2b88ad
--- /dev/null
+++ b/man/play.Rd
@@ -0,0 +1,11 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/game.R
+\name{play}
+\alias{play}
+\title{Run the game within an event loop}
+\usage{
+play()
+}
+\description{
+Run the game within an event loop
+}
diff --git a/man/str_rev.Rd b/man/str_rev.Rd
new file mode 100644
index 0000000..90bd5e9
--- /dev/null
+++ b/man/str_rev.Rd
@@ -0,0 +1,11 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/board.R
+\name{str_rev}
+\alias{str_rev}
+\title{Helper function: Reverse the characters in a string}
+\usage{
+str_rev(x)
+}
+\description{
+Helper function: Reverse the characters in a string
+}
diff --git a/sound.R b/sound.R
deleted file mode 100644
index 5a2c633..0000000
--- a/sound.R
+++ /dev/null
@@ -1,19 +0,0 @@
-
-library(audio)
-
-
-# Tweak the audio to be compatible with the audio package
-# sox -r 8000 -b 8 -e signed-integer -c 1 %s -b 16 %s
-# sox %s -b 16 %s
-
-sound <- list(
- intro = audio::load.wave("./sound/intro.wav"),
- chomp = audio::load.wave("./sound/chomp.wav"),
- death = audio::load.wave("./sound/death.wav"),
- ghost = audio::load.wave("./sound/ghost.wav"),
- extra = audio::load.wave("./sound/extra.wav"),
- fruit = audio::load.wave("./sound/fruit.wav"),
- inter = audio::load.wave("./sound/inter.wav")
-)
-
-# audio::play(sound$inter)
\ No newline at end of file