Skip to content

Instantly share code, notes, and snippets.

@sophiathekitty
Created June 22, 2013 07:36
Show Gist options
  • Save sophiathekitty/5836223 to your computer and use it in GitHub Desktop.
Save sophiathekitty/5836223 to your computer and use it in GitHub Desktop.
a really simple javascript dialog system.
<div class="item half npc">
<ul id="creamsicle" class="npc">
<li><img src="https://graph.facebook.com/448128811931322/picture" class="user">The Creamsicle Bellwether</li>
<li class="dialog"></li>
<li class="option"><a href="#talk" class="action">talk</a></li>
<li class="option"><a href="#pet" class="action">pet</a></li>
<li class="option"><a href="#look" class="action">look</a></li>
</ul>
</div>
// dialog
$(document).ready(function(e) {
$(".npc .action").click(function(e) {
switch($(this).attr("href")){
case "#talk":
talk($(this).parent().parent());
break;
case "#pet":
pet($(this).parent().parent());
$(this).parent().slideUp(100);
break;
case "#look":
look($(this).parent().parent());
$(this).parent().slideUp(100);
break;
default:
alert($(this).parent().parent().attr("id")+": "+$(this).attr("href"));
}
});
function talk(who){
console.log(speech[$(who).attr("id")]);
var i = Math.floor(Math.random()*speech[$(who).attr("id")].talk.length);
$("#"+$(who).attr("id")+" .dialog").text(speech[$(who).attr("id")].talk[i]);
$('#container').masonry( 'reload' );
}
function pet(who){
if(Math.random() > speech[$(who).attr("id")].pet){
$("#"+$(who).attr("id")+" .dialog").text("nope!");
$(who).parent().hide(1000,function(){
$(this).remove();
$('#container').masonry( 'reload' );
});
} else {
$("#"+$(who).attr("id")+" .dialog").text("omg! i love you!");
$('#container').masonry( 'reload' );
}
}
function look(who){
$(who).parent().removeClass("half");
$(who).addClass("look");
$('#container').masonry( 'reload' );
}
});
var speech = {
sushi:{
pet:0.25,
talk:[
"I'm sushi, Lavender's first born son.",
"I'm a tiny runt, that Morgynne had to help pull out of my mom.",
"I was born around 3am on the last day of september.",
"One time I got attacked by a crazy dog, so now I only have one eye.",
"I like to try to steal pet mice, but i'm learning not to.",
"I like to be friends with pet rats.",
"I like to head boop you in the eyes.",
"I am high energy, and never went through puberty, because i'm stunted as a kitten."]},
creamsicle:{
pet:0.15,
talk:[
"When The Creamsicle was about 5 weeks old, he was one of the many sickly kittens, ditched on the highway in VA.",
"When Morgynne was hitchhiking from TN to MA, he rolled out like a ball, and landed on her foot.",
"He was fat, and his eyes were crusty, and he had brain damage from heat stroke.",
"Morgynne scooped him up, and put him in the car. He decided he was not a cat, but a dog.",
"Fooooooooot @}\~~~ @______@ ~n»o»n~ yes",
"OMG MY BAAAAALLLLLLLSSSSSS!!!! MY BALLS!!! BAALS!1"]},
weenis:{
pet:0.95,
talk:[
"Hi!",
"I like you!",
"I'm an old man.",
"woof", "arf arf",
"arrrrooo arwoof",
"I had most of my teeth removed because they were bad."]},
lily:{
pet:0.75,
talk:[
"I am the sister of poppy. I am a happy tiger kitty.",
"I am Lily. I was born to two stray cats, in an attic near Dallas TX.",
"I was neglected, and malnourished, and headed to a high kill shelter, before M & D adopted me.",
"I ate a LOT of roast chicken to regain my strength.",
"I traveled around the world with M, D, Lavender, Poppy, Jezebel, and then creamcicle.",
"I lived with them in tents, and got carried around in backpacks.",
"I helped nurse Lavenders kittens too.",
"I love to climb trees, and I know to always return home.",
"I sometimes get frustrated with the kittens.",
"a lot of people cannot tell me & my sister apart.",
"I'm very cuddly."]},
daisy:{
pet:0.5,
talk:[
"I'm a Nigerian dwarf nanny goat.",
"Have you seen my baby? I was nursing a baby.",
"I really like the dead leaves and bark.",
"There's a lot of small things that aren't goats around here.",
"I really would like something to eat.",
"Do you have any carrots on you?",
"I like fresh onions.",
"Please feed me.",
"So itchy."]}};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment