Skip to content

Commit

Permalink
Update XP, including freeze (#35)
Browse files Browse the repository at this point in the history
* Increment 2XP per hour

* Add message when pet has levelled up

* Add XP-based chance of unalive after 21 days

* Introduce ideas of XP freeze at a certain age, influences chance of unalive

* Clean up xp-/age-freeze issues

* Add constants to internal data, simplify args throughout

* Add unalive logic based on xp freeze

* Add to unalive logic a multiplier for days since age freeze

* Prevent unalive chance going >1

* Update NEWS, README, start 3/5 hungry and happy
  • Loading branch information
matt-dray committed Oct 24, 2022
1 parent 0207527 commit 471e880
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 305 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tamRgo
Title: Digital Pets in R
Version: 0.0.0.9006
Version: 0.0.0.9007
Authors@R: c(person("Matt", "Dray", , "mwdray@gmail.com", role = c("aut", "cre")),
person("Adriana", "De Palma", , , role = "ctb"))
Description: Store a digital pet on your computer and interact with it in your R
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by roxygen2: do not edit by hand

export(.check_and_update)
export(clean)
export(feed)
export(get_stats)
Expand Down
13 changes: 10 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# tamRgo 0.0.0.9007

* Used concept of 'XP freeze' at a certain age (21); chance of being unalive after this is dependent on that freeze value and the number of days since that age was reached (towards #23).
* Adjusedt passive XP accumulation (#24).
* Alerted user on level up.
* Created internal dataset as `internal`, containing `$sprites` and `$constants` for a single source of truth on level up thresholds, age for XP freeze, etc.

# tamRgo 0.0.0.9006

* Add simple draft of unalive logic (towards #23).
* Added simple draft of unalive logic (towards #23).
* Re-instigated concept of 'dirty'.
* Add warning to `get_stats()` if status bars have reached their maximum negative score.
* Add check_blueprint to utils.
* Added warning to `get_stats()` if status bars have reached their maximum negative score.
* Added check_blueprint to utils.

# tamRgo 0.0.0.9005

Expand Down
5 changes: 3 additions & 2 deletions R/blueprints.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@
),
experience = list(
xp = 0L,
xp_freeze = NA_real_,
level = 0L
),
status = list(
happy = 0L,
hungry = 0L,
happy = 3L,
hungry = 3L,
dirty = 0L
)
)
Expand Down
65 changes: 13 additions & 52 deletions R/draw.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
#' Return a Pet's Image as a Matrix
#'
#' @param species Character. The species of the pet to be drawn.
#'
#' @return A matrix.
#'
#' @examples \dontrun{ .get_pet_matrix("X", level = 3L)}
#'
#' @noRd

.get_pet_matrix <- function(species = c("X", "Y", "Z"), level = 0L:5L) {

species <- match.arg(species)
Expand All @@ -18,61 +10,30 @@
)
}

if (level == 0L) {
return(species_images$XYZ$level_0)
} else if (level == 4L) {
return(species_images$XYZ$level_4)
} else if (level == 5L) {
return(species_images$XYZ$unalive)
}
if (level == 0L) return(internal$sprites$sp_xyz$lvl_0)
if (level == 4L) return(internal$sprites$sp_xyz$lvl_4)
if (level == 5L) return(internal$sprites$sp_xyz$lvl_5)

if (species == "X") {
if (level == 1L) {
return(species_images$X$level_1)
} else if (level == 2L) {
return(species_images$X$level_2)
} else if (level == 3L) {
return(species_images$X$level_3)
}
if (level == 1L) return(internal$sprites$sp_x$lvl_1)
if (level == 2L) return(internal$sprites$sp_x$lvl_2)
if (level == 3L) return(internal$sprites$sp_x$lvl_3)
}

if (species == "Y") {
if (level == 1L) {
return(species_images$Y$level_1)
} else if (level == 2L) {
return(species_images$Y$level_2)
} else if (level == 3L) {
return(species_images$Y$level_3)
}
if (level == 1L) return(internal$sprites$sp_y$lvl_1)
if (level == 2L) return(internal$sprites$sp_y$lvl_2)
if (level == 3L) return(internal$sprites$sp_y$lvl_3)
}

if (species == "Z") {
if (level == 1L) {
return(species_images$Z$level_1)
} else if (level == 2L) {
return(species_images$Z$level_2)
} else if (level == 3L) {
return(species_images$Z$level_3)
}
if (level == 1L) return(internal$sprites$sp_z$lvl_1)
if (level == 2L) return(internal$sprites$sp_z$lvl_2)
if (level == 3L) return(internal$sprites$sp_z$lvl_3)
}

}

#' Print Pet Image to Console
#'
#' @description Draw a matrix representaiton of a pet's image to the console
#' row-by-row.
#'
#' @param pet_matrix Matrix.
#'
#' @return Nothing.
#'
#' @examples \dontrun{
#' mat <- .get_pet_matrix("X")
#' .draw_pet(mat)
#' }
#'
#' @noRd
.draw_pet <- function(pet_matrix) {

for (i in seq(nrow(pet_matrix))) {
Expand Down
20 changes: 7 additions & 13 deletions R/interact.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,12 @@ get_stats <- function() {

bp <- .check_and_update()

if (bp$experience$level == 0L) {
level_text <- "newborn"
} else if (bp$experience$level == 1L) {
level_text <- "child"
} else if (bp$experience$level == 2L) {
level_text <- "youngling"
} else if (bp$experience$level == 3L) {
level_text <- "adult"
} else if (bp$experience$level == 4L) {
level_text <- "mature"
} else if (bp$experience$level == 5L) {
level_text <- "unalive"
}
if (bp$experience$level == 0L) level_text <- internal$constants$level_names$lvl_0
if (bp$experience$level == 1L) level_text <- internal$constants$level_names$lvl_1
if (bp$experience$level == 2L) level_text <- internal$constants$level_names$lvl_2
if (bp$experience$level == 3L) level_text <- internal$constants$level_names$lvl_3
if (bp$experience$level == 4L) level_text <- internal$constants$level_names$lvl_4
if (bp$experience$level == 5L) level_text <- internal$constants$level_names$lvl_5

empty_happy <- rep("\U025A0", bp$status$happy)
empty_hungry <- rep("\U025A0", bp$status$hungry)
Expand Down Expand Up @@ -158,6 +151,7 @@ play <- function() {
bp$status$happy <- min(bp$status$happy + 1L, 5L)
bp$experience$xp <- bp$experience$xp + 5L
suppressMessages(.write_blueprint(bp, ask = FALSE))

message("'Happy' status value is now ", bp$status$happy, "/5")

}
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.

0 comments on commit 471e880

Please sign in to comment.