wii-js/index.html
2011-07-10 04:01:14 -04:00

116 lines
3.8 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Wii.js Demo</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/demo.css">
</head>
<body>
<h1>Wii.js Demo</h1>
<p>
This is a demo page meant to show how easy it is to interact with the Nintendo Wii remotes using Javascript. It's
powered by <a href="http://github.com/ryanmcgrath/wii-js/">wii-js</a>, a Javascript library that abstracts the differences
and pain points associated with using the Wii remotes.
</p>
<p>
This demo is really simple, and works best with all Wii remotes (Wiimotes). Hold a Wiimote horizontal (sideways), and use
the directional pad to move a box floating in the bottom right corner around. Wiimote #1 is red, #2 is green, #3 is yellow, #4 is purple.
Have fun!
</p>
<p>
If you find bugs or want to get in touch, come find me at the project home on <a href="http://github.com/ryanmcgrath/wii-js/">GitHub</a>! You
can also find me on Twitter (<a href="http://twitter.com/ryanmcgrath">@ryanmcgrath</a>), or my <a href="http://venodesigns.net/">personal website</a>.
I'm always interested in what others are building!
</p>
<p>
- Ryan McGrath
</p>
<div id="player_1" class="player">1</div>
<div id="player_2" class="player">2</div>
<div id="player_3" class="player">3</div>
<div id="player_4" class="player">4</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="js/wii.js"></script>
<script>
var wiimote = new Wii.Remote(1, {horizontal: true}),
wiimote2 = new Wii.Remote(2, {horizontal: true}),
wiimote3 = new Wii.Remote(3, {horizontal: true}),
wiimote4 = new Wii.Remote(4, {horizontal: true}),
p1 = $('#player_1'),
p2 = $('#player_2'),
p3 = $('#player_3'),
p4 = $('#player_4');
wiimote.when('pressed_down', function() {
p1.css({'top': parseInt(x[0].style.top) + 50});
});
wiimote.when('pressed_right', function() {
p1.css({'left': parseInt(x[0].style.left) + 50});
});
wiimote.when('pressed_left', function() {
p1.css({'left': parseInt(x[0].style.left) - 50});
});
wiimote.when('pressed_up', function() {
p1.css({'top': parseInt(x[0].style.top) - 50});
});
wiimote2.when('pressed_down', function() {
p2.css({'top': parseInt(x[0].style.top) + 50});
});
wiimote2.when('pressed_right', function() {
p2.css({'left': parseInt(x[0].style.left) + 50});
});
wiimote2.when('pressed_left', function() {
p2.css({'left': parseInt(x[0].style.left) - 50});
});
wiimote2.when('pressed_up', function() {
p2.css({'top': parseInt(x[0].style.top) - 50});
});
wiimote3.when('pressed_down', function() {
p3.css({'top': parseInt(x[0].style.top) + 50});
});
wiimote3.when('pressed_right', function() {
p3.css({'left': parseInt(x[0].style.left) + 50});
});
wiimote3.when('pressed_left', function() {
p3.css({'left': parseInt(x[0].style.left) - 50});
});
wiimote3.when('pressed_up', function() {
p3.css({'top': parseInt(x[0].style.top) - 50});
});
wiimote4.when('pressed_down', function() {
p4.css({'top': parseInt(x[0].style.top) + 50});
});
wiimote4.when('pressed_right', function() {
p4.css({'left': parseInt(x[0].style.left) + 50});
});
wiimote4.when('pressed_left', function() {
p4.css({'left': parseInt(x[0].style.left) - 50});
});
wiimote4.when('pressed_up', function() {
p4.css({'top': parseInt(x[0].style.top) - 50});
});
Wii.listen();
</script>
</body>
</html>