content/hifi-content/rebecca/testing_utils/collisionTest.js
2022-02-14 02:04:11 +01:00

46 lines
1.6 KiB
JavaScript

//
// collisionTest.js
//
// created by Rebecca Stankus on 01/07/19
// updated on 01/02/19
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
/* global Audio, Entities, Script, SoundCache */
(function() {
var _this;
var COLLISION_COLOR = { blue: 162, green: 77, red: 214 };
var defaultColor;
var CollisionTest = function() {
_this = this;
};
CollisionTest.prototype = {
/* ON PRELOAD: Save a reference to this key and set up some data about its position, sound, and color */
preload: function(entityID){
_this.entityID = entityID;
defaultColor = Entities.getEntityProperties(_this.entityID, 'color').color;
},
/* ON COLLISION WITH AN ENTITY: When an entity starts to collide with this keyboard key, change the key color,
and play the corresponding key sound. When the entity stops colliding, return the key to its default color */
collisionWithEntity: function(thisEntity, otherEntity, collision) {
print("COLLISION TYPE: ", collision.type, " COLIIDED WITH ", collision.idB);
if (collision.type === 0) {
Entities.editEntity(_this.entityID, { color: COLLISION_COLOR });
} else if (collision.type === 2) {
Entities.editEntity(_this.entityID, { color: defaultColor });
}
}
};
return new CollisionTest();
});