Skip to content

Commit

Permalink
Add pet menu
Browse files Browse the repository at this point in the history
  • Loading branch information
alesan99 committed Feb 22, 2024
1 parent 7463873 commit 8b1070a
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 50 deletions.
2 changes: 1 addition & 1 deletion website/game/menu/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MENUS["chatMenu"] = new class extends Menu {
this.emoteMenuOpen = false

this.buttons = {}
this.buttons[0] = new Button(false, ()=>{this.emoteMenuOpen = !this.emoteMenuOpen}, {image: IMG.chat, frames:[SPRITE.chatButton.getFrame(0,0),SPRITE.chatButton.getFrame(1,0),SPRITE.chatButton.getFrame(2,0)]}, 216,535, 34,34)
this.buttons[0] = new Button(false, ()=>{this.emoteMenuOpen = !this.emoteMenuOpen; closeMenu()}, {image: IMG.chat, frames:[SPRITE.chatButton.getFrame(0,0),SPRITE.chatButton.getFrame(1,0),SPRITE.chatButton.getFrame(2,0)]}, 216,535, 34,34)
this.buttons[1] = new Button(false, ()=>{this.enter()}, {image: IMG.chat, frames:[SPRITE.chatButton.getFrame(0,1),SPRITE.chatButton.getFrame(1,1),SPRITE.chatButton.getFrame(2,1)]}, 661,535, 34,34)
this.buttons[2] = new Button(false, ()=>{if (getOpenMenu() != "customization") {openMenu("customization")} else {closeMenu()}}, {image: IMG.chat, frames:[SPRITE.chatButton.getFrame(0,2),SPRITE.chatButton.getFrame(1,2),SPRITE.chatButton.getFrame(2,2)]}, 699,535, 34,34)
this.buttons[3] = new Button(false, ()=>{if (getOpenMenu() != "mapMenu") {openMenu("mapMenu")} else {closeMenu()}}, {image: IMG.chat, frames:[SPRITE.chatButton.getFrame(0,3),SPRITE.chatButton.getFrame(1,3),SPRITE.chatButton.getFrame(2,3)]}, 737,535, 34,34)
Expand Down
40 changes: 20 additions & 20 deletions website/game/menu/customization.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ MENUS["customization"] = new class extends Menu {
super(234,104, 560,350)
}

load () {
load () {
this.openTimer = 0

this.buttons = {}
Expand All @@ -26,16 +26,16 @@ MENUS["customization"] = new class extends Menu {
PROFILE = SAVEDATA.profile;
}, null, 373,404, 100,32)

// Name
// Name
this.buttons["name"] = new Button(PROFILE.name, ()=>{}, null, 292,129, 140,32)

// Color
// Color
this.buttons["color"] = new Button("Random", ()=>{
PROFILE.color = RGBtoHEX(Math.floor(100 + Math.random()*155),
Math.floor(100 + Math.random()*155),
Math.floor(100 + Math.random()*155));
PLAYER.updateProfile(PROFILE, "sendToServer");
}, null, 348,365, 100,32)
PROFILE.color = RGBtoHEX(Math.floor(100 + Math.random()*155),
Math.floor(100 + Math.random()*155),
Math.floor(100 + Math.random()*155));
PLAYER.updateProfile(PROFILE, "sendToServer");
}, null, 348,365, 100,32)

// Inventory
this.tab = "allTab"
Expand Down Expand Up @@ -79,10 +79,10 @@ MENUS["customization"] = new class extends Menu {
// PROFILE.body = keys[Math.floor(Math.random() * keys.length)];
// }
// PLAYER.updateProfile(PROFILE, "sendToServer");
// }, null, 733,322, 32,32)
// Pet
// }, null, 733,322, 32,32)
// Pet
this.buttons["pet"] = new Button("None", ()=>{}, null, 665,362, 100,32)
}
}

filterInventory(category) {
this.inventory.length = 0
Expand All @@ -100,23 +100,23 @@ MENUS["customization"] = new class extends Menu {
}

draw() {
// Window
// Window
let scale = 1
if (this.openTimer < 1) {
scale = easing("easeOutBack", this.openTimer)
}
DRAW.image(IMG.menu, null, this.x+this.w*0.5, this.y+this.h*0.5, 0, scale, scale, 0.5, 0.5)
DRAW.image(IMG.menu, null, this.x+this.w*0.5, this.y+this.h*0.5, 0, scale, scale, 0.5, 0.5)

// Text
DRAW.setColor(112, 50, 16, scale)
DRAW.setFont(FONT.caption)
DRAW.text("Inventory", 620, 142, "center")
// Text
DRAW.setColor(112, 50, 16, scale)
DRAW.setFont(FONT.caption)
DRAW.text("Inventory", 620, 142, "center")

DRAW.text("Color", 285, 388, "left")
DRAW.text("Color", 285, 388, "left")

DRAW.text("Pet", 613, 384, "left")
DRAW.text("Pet", 613, 384, "left")

PLAYER.draw(360,340,"down")
PLAYER.draw(360,340,"down")

// Render all buttons
this.drawButtons()
Expand Down
17 changes: 9 additions & 8 deletions website/game/menu/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ MENUS["mapMenu"] = new class extends Menu {
super(234,104, 560,350)
}

load (config) {
load (config) {
this.openTimer = 0

this.buttons = {}
}
this.buttons["close"] = new Button("X", ()=>{closeMenu()}, null, 740,128, 32,32)
}

keyPress(key) {
}
Expand All @@ -27,17 +28,17 @@ MENUS["mapMenu"] = new class extends Menu {
}

draw() {
// Window
// Window
let scale = 1
if (this.openTimer < 1) {
scale = easing("easeOutBack", this.openTimer)
}
DRAW.image(IMG.menu, null, this.x+this.w*0.5, this.y+this.h*0.5, 0, scale, scale, 0.5, 0.5)
DRAW.image(IMG.menu, null, this.x+this.w*0.5, this.y+this.h*0.5, 0, scale, scale, 0.5, 0.5)

// Text
DRAW.setColor(112, 50, 16, scale)
DRAW.setFont(FONT.caption)
DRAW.text("Map", 512, 142, "center")
// Text
DRAW.setColor(112, 50, 16, scale)
DRAW.setFont(FONT.caption)
DRAW.text("Map", 512, 142, "center")

// Render all buttons
this.drawButtons()
Expand Down
36 changes: 29 additions & 7 deletions website/game/menu/pet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ MENUS["petMenu"] = new class extends Menu {
super(234,104, 560,350)
}

load (config) {
load (config) {
this.openTimer = 0

this.buttons = {}
}
this.buttons["close"] = new Button("X", ()=>{closeMenu()}, null, 740,128, 32,32)

// Get Pet information
this.pet = PLAYER.petObj

// Name
this.buttons["name"] = new Button(SAVEDATA.pet.name, ()=>{}, null, 292,129, 140,32)
}

keyPress(key) {
}
Expand All @@ -31,16 +38,31 @@ MENUS["petMenu"] = new class extends Menu {
}

draw() {
// Window
// Window
let scale = 1
if (this.openTimer < 1) {
scale = easing("easeOutBack", this.openTimer)
}
DRAW.image(IMG.menu, null, this.x+this.w*0.5, this.y+this.h*0.5, 0, scale, scale, 0.5, 0.5)
DRAW.image(IMG.menu, null, this.x+this.w*0.5, this.y+this.h*0.5, 0, scale, scale, 0.5, 0.5)

DRAW.setColor(112, 50, 16, scale)
DRAW.setFont(FONT.caption)

// Pet
this.pet.draw(360,340,"down")

// Pet Status
DRAW.setColor(112, 50, 16, scale)
DRAW.text(`Feeling ${this.pet.getMood()}.`, 476, 184, "left")
DRAW.text("Health", 476, 224, "left")
DRAW.text("Hunger", 476, 284, "left")

DRAW.setColor(112, 50, 16, scale)
DRAW.setFont(FONT.caption)
DRAW.text("Pet", 512, this.y+38, "center")
DRAW.setColor(240, 240, 240, scale)
DRAW.rectangle(476, 238, 200, 20)
DRAW.rectangle(476, 298, 200, 20)
DRAW.setColor(20, 200, 20, scale)
DRAW.rectangle(476, 238, 200*(this.pet.health/100), 20)
DRAW.rectangle(476, 298, 200*(this.pet.hunger/100), 20)

// Render all buttons
this.drawButtons()
Expand Down
15 changes: 8 additions & 7 deletions website/game/menu/quests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ MENUS["questsMenu"] = new class extends Menu {
super(234,104, 560,350)
}

load (config) {
load (config) {
this.openTimer = 0

this.buttons = {}
this.buttons["close"] = new Button("X", ()=>{closeMenu()}, null, 740,128, 32,32)

this.quests = QuestSystem.getAllActiveQuests()
}
}

keyPress(key) {
}
Expand All @@ -30,18 +31,18 @@ MENUS["questsMenu"] = new class extends Menu {
}

draw() {
// Window
// Window
let scale = 1
if (this.openTimer < 1) {
scale = easing("easeOutBack", this.openTimer)
}
DRAW.image(IMG.menu, null, this.x+this.w*0.5, this.y+this.h*0.5, 0, scale, scale, 0.5, 0.5)
DRAW.image(IMG.menu, null, this.x+this.w*0.5, this.y+this.h*0.5, 0, scale, scale, 0.5, 0.5)
DRAW.setColor(255,255,255,1.0)
DRAW.rectangle(this.x+20, this.y+80, this.w-40, this.h-100, 1.0, 0, 0, 0, 0.5)

// Text
DRAW.setColor(112, 50, 16, scale)
DRAW.setFont(FONT.caption)
// Text
DRAW.setColor(112, 50, 16, scale)
DRAW.setFont(FONT.caption)
DRAW.text("Quests", 512, this.y+38, "center")

let y = this.y+100
Expand Down
1 change: 1 addition & 0 deletions website/game/menu/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ MENUS["usersMenu"] = new class extends Menu {
this.openTimer = 0

this.buttons = {}
this.buttons["close"] = new Button("X", ()=>{closeMenu()}, null, 740,128, 32,32)

// Get list of connected player names
this.connectedPlayers = [PROFILE.name]
Expand Down
33 changes: 28 additions & 5 deletions website/game/objects/pet.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ class Pet extends PhysicsObject {

// Pet data
this.id = id
this.name = SAVEDATA.pet.name
this.owner = owner

// Status
this.happiness = SAVEDATA.pet.health || 50
this.health = SAVEDATA.pet.health || 100
this.hunger = SAVEDATA.pet.hunger || 100

// Clickable
this.mouseOver = false
this.clickRegion = {
Expand All @@ -35,13 +41,13 @@ class Pet extends PhysicsObject {
this.activated = false

// Graphics
this.image = ITEMS.pet[id].image
this.image = ITEMS.pet[id].image
this.sprite = ITEMS.pet[id].sprite
this.anim = new Animation(this.sprite, 0)
this.anim.setFrame(0,0)

this.flip = 1
this.scale = 1
this.flip = 1
this.scale = 1

this.active = false
this.static = false
Expand Down Expand Up @@ -76,14 +82,14 @@ class Pet extends PhysicsObject {
}
}

draw(drawX=this.x, drawY=this.y, dir=this.dir) {
draw(drawX=this.x, drawY=this.y, dir=this.dir) {
DRAW.setColor(255,255,255,1.0)
DRAW.image(IMG.shadow, null, drawX, drawY, 0, this.scale, this.scale, 0.5, 1)

// Chicken and accessories
DRAW.setColor(255,255,255,1.0)
DRAW.image(this.image, this.anim.getFrame(), drawX, drawY, 0, this.flip*this.scale, this.scale, 0.5, 1)
}
}

checkMouseOver() {
let [mouseX, mouseY] = getMousePos()
Expand All @@ -107,4 +113,21 @@ class Pet extends PhysicsObject {

startCollide (name, obj, nx, ny) {
}

// Pet behavior
getMood() {
let moods = [
"jolly",
"happy",
"groovy",
"bored",
"so-so",
"meh",
"emo",
"sad",
"dorceless",
]
let word = moods[((1-this.happiness/100)*(moods.length-1))|0]
return word
}
}
10 changes: 8 additions & 2 deletions website/game/objects/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ class Player {
let futureY = char.y + dy*char.speed*dt

if ((((targetX-futureX > 0) != (targetX-char.x > 0)) || ((targetY-futureY > 0) != (targetY-char.y > 0)))) { // Don't move anymore if crossing target coordinate
this.target = false
char.move(0, 0)
this.stop()
} else {
char.move(dx, dy)
}
Expand Down Expand Up @@ -154,6 +153,13 @@ class Player {
this.target = false
}

stop() {
let char = this.obj
// Stop movement
this.target = false
char.move(0, 0)
}

mouseClick(button, x, y) {
// Movement
// Check if left mouse button is being held
Expand Down
6 changes: 6 additions & 0 deletions website/game/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ function openMenu(name, args) {
}
open_menu = name
MENUS[name].load(args)

// Stop world events
if (PLAYER_CONTROLLER) {
// Stop moving player
PLAYER_CONTROLLER.stop()
}
}

function closeMenu() {
Expand Down

0 comments on commit 8b1070a

Please sign in to comment.