refactor buddy system

now the concept of a buddy is disconnected from funfriend, allowing different types of buddies

buddies can be defined in buddies.cr
This commit is contained in:
Jill 2023-06-02 13:35:23 +03:00
parent f288916b9d
commit d2ed057df3
Signed by: oat
GPG Key ID: 33489AA58A955108
103 changed files with 139 additions and 58 deletions

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
assets/buddies/god_00.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
assets/buddies/god_01.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
assets/buddies/god_02.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
assets/buddies/god_03.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
assets/buddies/god_04.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
assets/buddies/god_05.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

BIN
assets/buddies/god_06.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
assets/buddies/god_07.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
assets/buddies/god_08.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
assets/buddies/god_09.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
assets/sfx/talk_god1.ogg Normal file

Binary file not shown.

BIN
assets/sfx/talk_god2.ogg Normal file

Binary file not shown.

BIN
assets/sfx/talk_god3.ogg Normal file

Binary file not shown.

BIN
assets/sfx/talk_god4.ogg Normal file

Binary file not shown.

BIN
assets/sfx/talk_god5.ogg Normal file

Binary file not shown.

BIN
assets/sfx/talk_god6.ogg Normal file

Binary file not shown.

BIN
assets/sfx/talk_god7.ogg Normal file

Binary file not shown.

BIN
assets/sfx/talk_god8.ogg Normal file

Binary file not shown.

102
src/buddies.cr Normal file
View File

@ -0,0 +1,102 @@
module Funfriend
enum DialogType
# Upon boot-up; random chatter
Chatter
# Upon being moved
Moved
# Upon being touched, but not moved
Touched
end
abstract class Buddy
# Used in window titles
abstract def name : String
# Given a specific `DialogType`, returns a list of possible dialogue choices
abstract def dialog(type : DialogType) : Array(Array(String))
# Returns the textures this buddy uses
abstract def textures : TextureMan::TextureBasket
# Implements the logic for the talk SFX, similar to corru.observer's `talk: () => ...`
abstract def talk_sound
end
class FunfriendBuddy < Buddy
def name : String
"FUNFRIEND"
end
def dialog(type) : Array(Array(String))
case type
when .chatter?
[
["HELLO AGAIN"],
["HI INTERLOPER"],
["HELLO!", "IS THE AUTH LAYER STILL DISSOCIATED?", "I MISS THEM"],
["INTERLOPER!", "WELCOME", "BUT ALSO PLEASE DO NOT BOTHER ME", "VERY BUSY"]
]
when .moved?
[
["OK I'LL BE HERE"]
]
when .touched?
[
["HI INTERLOPER!"],
["HELLO!"],
["HI!"]
]
else
[] of Array(String)
end
end
def textures : TextureMan::TextureBasket
TextureMan::TextureBasket.new(
(0..39).map { |i| TextureMan.load_texture("assets/buddies/funfriend_#{i.to_s.rjust(2, '0')}.png") },
10
)
end
def talk_sound
SoundMan.play_sound("assets/sfx/talk#{(1..8).sample}.ogg")
end
end
class CatfriendBuddy < FunfriendBuddy
def textures : TextureMan::TextureBasket
TextureMan::TextureBasket.new(
(0..39).map { |i| TextureMan.load_texture("assets/buddies/catfriend_#{i.to_s.rjust(2, '0')}.png") },
10
)
end
end
class GodBuddy < Buddy
def name : String
"GOD"
end
def dialog(type) : Array(Array(String))
case type
when .chatter?
[
["hello!"]
]
else
[] of Array(String)
end
end
def textures : TextureMan::TextureBasket
TextureMan::TextureBasket.new(
(0..9).map { |i| TextureMan.load_texture("assets/buddies/god_#{i.to_s.rjust(2, '0')}.png") },
10
)
end
def talk_sound
SoundMan.play_sound("assets/sfx/talk_god#{(1..8).sample}.ogg")
end
end
end

View File

@ -1,27 +1,12 @@
class Funfriend::FunfriendContext < Funfriend::WindowContext
class Funfriend::BuddyContext < Funfriend::WindowContext
CHATTER_TIMER = 3.0
CHATTER_ARRAY = [
["HELLO AGAIN"],
["HI INTERLOPER"],
["HELLO!", "IS THE AUTH LAYER STILL DISSOCIATED?", "I MISS THEM"],
["INTERLOPER!", "WELCOME", "BUT ALSO PLEASE DO NOT BOTHER ME", "VERY BUSY"]
]
getter buddy : Buddy
STAY_ARRAY = [
"OK I'LL BE HERE"
]
TOUCH_ARRAY = [
"HI INTERLOPER!",
"HELLO!",
"HI!"
]
getter renderer : FunfriendRenderer
getter renderer : BuddyRenderer
property chatter_timer : Float64 = 1.0
property chatter_index : Int32 = 0
property chatter_array : Array(String)? = CHATTER_ARRAY.sample
property chatter_array : Array(String)?
property held : Bool = false
property held_at : Vec2 = Vec2.zero
@ -40,24 +25,21 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
WANDER_TIMER = 4.0
property wander_timer : Float64 = WANDER_TIMER
def initialize
def initialize(@buddy : Buddy)
super(
title: "??_FUNFRIEND_??",
title: "??_#{buddy.name}_??",
width: window_size.x_i, height: window_size.y_i,
transparent: true
)
# just for initialization, let OpenGL know this is the current context
window.make_context_current
@renderer = FunfriendRenderer.new
@renderer = BuddyRenderer.new(buddy)
window.on_mouse_button do |event|
if event.action.press? && event.mouse_button.two?
renderer.catmoding = !renderer.catmoding
end
if event.mouse_button.one?
if event.action.press?
SoundMan.play_sound("assets/sfx/talk#{(1..8).sample}.ogg")
buddy.talk_sound
@easing_dur = 0.0
@held = true
@held_at = Vec2.new({
@ -91,6 +73,8 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
}
window.position = random_pos
@static_pos = Vec2.new(random_pos)
@chatter_array = buddy.dialog(DialogType::Chatter).sample
end
def window_size
@ -189,10 +173,10 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
if !speaking
if stable_pos_dist > 50
# moved quite a bit from initial point
say STAY_ARRAY.sample
say buddy.dialog(DialogType::Moved)
else
# just touched
say TOUCH_ARRAY.sample
say buddy.dialog(DialogType::Touched)
end
end
end
@ -214,7 +198,19 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
window.position[:y] - 20
), parent: self))
SoundMan.play_sound("assets/sfx/talk#{(1..8).sample}.ogg")
buddy.talk_sound
end
def say(text : Array(String))
@chatter_array = text
@chatter_timer = 0.0
@chatter_index = 0
end
def say(text : Array(Array(String)))
if text.size > 0
say text.sample
end
end
def speaking

Some files were not shown because too many files have changed in this diff Show More