Skip to content

Instantly share code, notes, and snippets.

@ehzhang
Created March 25, 2014 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehzhang/9754681 to your computer and use it in GitHub Desktop.
Save ehzhang/9754681 to your computer and use it in GitHub Desktop.
[wearscript] PokemonPebble
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<script>
trainer = {
name: "Edwin",
pokemon: [
{
name: "Pikachu",
level: 23,
hp: 80,
totalHP: 100,
moves: [
{
name: "Thundershock",
type: "Electric",
power: 40
},
{
name: "Thunder",
type: "Electric",
power: 110
},
{
name: "Tail Whip",
type: "Normal",
power: 0
},
{
name: "Tackle",
type: "Normal",
power: 50
}
]
}
},
{
name: "Pikachu",
level: 23,
hp: 80,
totalHP: 100,
moves: [
{
name: "Thundershock",
type: "Electric",
power: 40
},
{
name: "Thunder",
type: "Electric",
power: 110
},
{
name: "Tail Whip",
type: "Normal",
power: 0
},
{
name: "Tackle",
type: "Normal",
power: 50
}
]
}
},
{
name: "Pikachu",
level: 20,
hp: 80,
totalHP: 100,
moves: [
{
name: "Thundershock",
type: "Electric",
power: 40
},
{
name: "Thunder",
type: "Electric",
power: 110
},
{
name: "Tail Whip",
type: "Normal",
power: 0
},
{
name: "Tackle",
type: "Normal",
power: 50
}
]
}
},
{
name: "Pikachu",
level: 20,
hp: 80,
totalHP: 100,
moves: [
{
name: "Thundershock",
type: "Electric",
power: 40
},
{
name: "Thunder",
type: "Electric",
power: 110
},
{
name: "Tail Whip",
type: "Normal",
power: 0
},
{
name: "Tackle",
type: "Normal",
power: 50
}
]
}
},
{
name: "Pikachu",
level: 20,
hp: 80,
totalHP: 100,
moves: [
{
name: "Thundershock",
type: "Electric",
power: 40
},
{
name: "Thunder",
type: "Electric",
power: 110
},
{
name: "Tail Whip",
type: "Normal",
power: 0
},
{
name: "Tackle",
type: "Normal",
power: 50
}
]
}
},
{
name: "Pikachu",
level: 20,
hp: 80,
totalHP: 100,
moves: [
{
name: "Thundershock",
type: "Electric",
power: 40
},
{
name: "Thunder",
type: "Electric",
power: 110
},
{
name: "Tail Whip",
type: "Normal",
power: 0
},
{
name: "Tackle",
type: "Normal",
power: 50
}
]
}
}
]
};
function main() {
if (WS.scriptVersion(1)) return;
// States
var MOVES = 0,
POKEDEX = 1,
PARTY = 2;
var currentMoveIndex = 0,
currentPokemonIndex = 0,
currentPokemon = getPokemon(currentPokemonIndex);
function getPokemon(pokemonIndex) {
return trainer.pokemon[pokemonIndex];
};
// Display the specified move object
function displayMove(moveIndex) {
var move = currentPokemon.moves[moveIndex];
WS.pebbleSetTitle(move.name, true);
WS.pebbleSetBody('Type: ' + move.type + '\nPower: ' + move.power, false);
};
// Iterate over the moves using +1, -1
function nextMove(iter) {
currentMoveIndex = (currentMoveIndex + iter + currentPokemon.moves.length)
% currentPokemon.moves.length;
displayMove(currentMoveIndex);
};
// Use the current move
function useMove() {
var currentMove = currentPokemon.moves[currentMoveIndex],
isEffective = true;
WS.pebbleSetTitle(currentPokemon.name + ' used ' + currentMove.name + '!', true);
// Delay the super/not very effective message
setTimeout(function() {
WS.pebbleSetSubtitle(
"It's "
+ (isEffective ? "super " : "not very ")
+ "effective"
+ (isEffective ? "!" : "...") , false);
}, 2000);
// Reset the currentMove
setTimeout(function() {
displayMove(currentMoveIndex);
}, 5000);
};
// Put up the first move
displayMove(0);
WS.gestureCallback('onPebbleSingleClick', function(name) {
switch (name) {
case "down":
nextMove(1);
break;
case "up":
nextMove(-1);
break;
case "select":
useMove();
break;
default:
WS.log("What the fuck did you press");
break;
}
});
}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment