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
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 11 KiB |
|
@ -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
|
|
@ -1,27 +1,12 @@
|
||||||
class Funfriend::FunfriendContext < Funfriend::WindowContext
|
class Funfriend::BuddyContext < Funfriend::WindowContext
|
||||||
CHATTER_TIMER = 3.0
|
CHATTER_TIMER = 3.0
|
||||||
|
|
||||||
CHATTER_ARRAY = [
|
getter buddy : Buddy
|
||||||
["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"]
|
|
||||||
]
|
|
||||||
|
|
||||||
STAY_ARRAY = [
|
getter renderer : BuddyRenderer
|
||||||
"OK I'LL BE HERE"
|
|
||||||
]
|
|
||||||
|
|
||||||
TOUCH_ARRAY = [
|
|
||||||
"HI INTERLOPER!",
|
|
||||||
"HELLO!",
|
|
||||||
"HI!"
|
|
||||||
]
|
|
||||||
|
|
||||||
getter renderer : FunfriendRenderer
|
|
||||||
property chatter_timer : Float64 = 1.0
|
property chatter_timer : Float64 = 1.0
|
||||||
property chatter_index : Int32 = 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 : Bool = false
|
||||||
property held_at : Vec2 = Vec2.zero
|
property held_at : Vec2 = Vec2.zero
|
||||||
|
@ -40,24 +25,21 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
|
||||||
WANDER_TIMER = 4.0
|
WANDER_TIMER = 4.0
|
||||||
property wander_timer : Float64 = WANDER_TIMER
|
property wander_timer : Float64 = WANDER_TIMER
|
||||||
|
|
||||||
def initialize
|
def initialize(@buddy : Buddy)
|
||||||
super(
|
super(
|
||||||
title: "??_FUNFRIEND_??",
|
title: "??_#{buddy.name}_??",
|
||||||
width: window_size.x_i, height: window_size.y_i,
|
width: window_size.x_i, height: window_size.y_i,
|
||||||
transparent: true
|
transparent: true
|
||||||
)
|
)
|
||||||
|
|
||||||
# just for initialization, let OpenGL know this is the current context
|
# just for initialization, let OpenGL know this is the current context
|
||||||
window.make_context_current
|
window.make_context_current
|
||||||
@renderer = FunfriendRenderer.new
|
@renderer = BuddyRenderer.new(buddy)
|
||||||
|
|
||||||
window.on_mouse_button do |event|
|
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.mouse_button.one?
|
||||||
if event.action.press?
|
if event.action.press?
|
||||||
SoundMan.play_sound("assets/sfx/talk#{(1..8).sample}.ogg")
|
buddy.talk_sound
|
||||||
@easing_dur = 0.0
|
@easing_dur = 0.0
|
||||||
@held = true
|
@held = true
|
||||||
@held_at = Vec2.new({
|
@held_at = Vec2.new({
|
||||||
|
@ -91,6 +73,8 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
|
||||||
}
|
}
|
||||||
window.position = random_pos
|
window.position = random_pos
|
||||||
@static_pos = Vec2.new(random_pos)
|
@static_pos = Vec2.new(random_pos)
|
||||||
|
|
||||||
|
@chatter_array = buddy.dialog(DialogType::Chatter).sample
|
||||||
end
|
end
|
||||||
|
|
||||||
def window_size
|
def window_size
|
||||||
|
@ -189,10 +173,10 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
|
||||||
if !speaking
|
if !speaking
|
||||||
if stable_pos_dist > 50
|
if stable_pos_dist > 50
|
||||||
# moved quite a bit from initial point
|
# moved quite a bit from initial point
|
||||||
say STAY_ARRAY.sample
|
say buddy.dialog(DialogType::Moved)
|
||||||
else
|
else
|
||||||
# just touched
|
# just touched
|
||||||
say TOUCH_ARRAY.sample
|
say buddy.dialog(DialogType::Touched)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -214,7 +198,19 @@ class Funfriend::FunfriendContext < Funfriend::WindowContext
|
||||||
window.position[:y] - 20
|
window.position[:y] - 20
|
||||||
), parent: self))
|
), 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
|
end
|
||||||
|
|
||||||
def speaking
|
def speaking
|