Skip to content

Commit

Permalink
started writing pacmaze in tQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeetienne committed Feb 26, 2013
1 parent ed63acb commit f6f07e2
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions plugins/pacman/examples/pacmaze.html
@@ -0,0 +1,79 @@
<!doctype html><title>Minimal tQuery Page</title>
<script src="../../../build/tquery-bundle-require.js"></script>
<script src="../tquery.pacman.js"></script>
<body><script>
require([ 'tquery.skymap'
, 'tquery.simplemaze'
, 'tquery.controls'
, 'tquery.keyboard'
], function(){
var world = tQuery.createWorld().boilerplate().start();

// put some lights
tQuery.createAmbientLight().addTo(world)
.color(0x444444)
tQuery.createDirectionalLight().addTo(world)
.position(1,1,1)

// add pacman
var pacman = tQuery.Pacman.create().addTo(world)
.translateX(-1.5)
world.loop().hook(function(delta, now){
pacman.rotateY(0.02)
})

// world.removeCameraControls();
// tQuery(world.tCamera()).addTo(pacman).positionY(1.5)
// world.tCamera().lookAt(tQuery.createVector3())
world.loop().hook(function(delta, now){
var camera = tQuery(world.tCamera())
if( camera.positionY() < 3.5 ) camera.positionY(3.5)
});

// add a skymap
tQuery.createSkymap('mars').addTo(world);

var maze = tQuery.createSimpleMaze({
map : [
'*********',
'* * *',
'* ** ***',
'* *',
'*** *',
'* *',
'*********'
],
enableCeiling : false
}).addTo(world)
var maze3D = maze.object3D();

// to fix z-fighting with pacman shadow
maze3D.positionY(-0.001)

// very minimal controls
var controls = {
update : function(delta, now){
var keyboard = tQuery.keyboard();
var speed = 2;
if( keyboard.pressed('left') ){
pacman.translateX(-speed * delta)
}
if( keyboard.pressed('right') ){
pacman.translateX(+speed * delta)
}
if( keyboard.pressed('up') ){
pacman.translateZ(-speed * delta)
}
if( keyboard.pressed('down') ){
pacman.translateZ(+speed * delta)
}
}
};

// wrapper for this controls
tQuery.createControlsWrapper({
controls : controls
}).start()

})
</script></body>
6 changes: 5 additions & 1 deletion plugins/pacman/tquery.pacman.js
Expand Up @@ -32,6 +32,7 @@ tQuery.registerStatic('Pacman', function(opts){
if( opts.shape === 'pacman' ){
tQuery.createSphere().addTo(container)
.addClass('ball')
.translateY(0.5)
.setPhongMaterial()
.map(texture)
.back()
Expand All @@ -43,9 +44,11 @@ tQuery.registerStatic('Pacman', function(opts){
.map(texture)
.back()
.positionY(0.25 + 0.125)
.translateY(0.5)
// build the robe
tQuery.createCylinder(0.5, 0.5, 0.75, 64).addTo(container)
.addClass('robe')
.translateY(0.5)
.setLambertMaterial()
.color(0xffff00)
.back()
Expand All @@ -58,6 +61,7 @@ tQuery.registerStatic('Pacman', function(opts){
.back()
.positionX(0.25)
.positionY(0.25 + 0.125)
.translateY(0.5)
tQuery.createSphere().addTo(container)
.addClass('eyeL')
.scaleBy(0.25)
Expand All @@ -66,6 +70,7 @@ tQuery.registerStatic('Pacman', function(opts){
.back()
.positionX(-0.25)
.positionY(0.25 + 0.125)
.translateY(0.5)
}else console.assert(false);

// add the shadow on the ground
Expand All @@ -76,7 +81,6 @@ tQuery.registerStatic('Pacman', function(opts){
tQuery.createPlane().addTo(container)
.addClass('shadow')
.rotationX(-Math.PI/2)
.positionY(-0.5)
.setLambertMaterial()
.map(texture)
.opacity(0.5)
Expand Down

0 comments on commit f6f07e2

Please sign in to comment.