Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Package: pacman
Version: 1.0.0
Depends:
nara,
eventloop,
audio,
grid
Remotes:
coolbutuseless/nara,
coolbutuseless/eventloop
RoxygenNote: 7.2.0
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(play)
import(nara)
2 changes: 1 addition & 1 deletion board.R → R/board.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 7 additions & 24 deletions game.R → R/game.R
Original file line number Diff line number Diff line change
@@ -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)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -274,7 +259,7 @@ update_game <- function(event, frame_num, ...) {
}

# Render to screen
grid.raster(board_nr)
grid::grid.raster(board_nr)
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -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)
}
19 changes: 19 additions & 0 deletions R/sound.R
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion sprites.R → R/sprites.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 4 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The game plays in realtime using 2 key packages:

## Gameplay

<img src="video/pacman-game.gif" />
<img src="inst/video/pacman-game.gif" />

## Controls

Expand All @@ -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

Expand Down
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
11 changes: 11 additions & 0 deletions man/extract.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions man/im.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions man/play.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions man/str_rev.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions sound.R

This file was deleted.