From 33fa6fe5a93aadfd0b351543477228c14ba30321 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 24 Nov 2022 17:56:26 +0100 Subject: [PATCH] use image and move player to the left --- js/Cube.js | 13 ++++++++++--- js/player.js | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/js/Cube.js b/js/Cube.js index 36d6d93..8a15f65 100644 --- a/js/Cube.js +++ b/js/Cube.js @@ -1,12 +1,19 @@ import { Element } from "./Element.js"; export class Cube extends Element { - constructor(color) { + constructor(color, img) { super(); + let texture = null; + if (img) { + const loader = new THREE.TextureLoader(); + texture = loader.load(img); + loader.load; + } + this.data = new THREE.Mesh( - new THREE.BoxGeometry(1, 1, 1), - new THREE.MeshBasicMaterial({ color: color }) + new THREE.BoxGeometry(), + new THREE.MeshPhongMaterial({ color: color, map: texture }) ); // Create shadows diff --git a/js/player.js b/js/player.js index 30ef058..05ed082 100644 --- a/js/player.js +++ b/js/player.js @@ -3,9 +3,10 @@ import { Rotation } from "./utils.js"; export class Joueur extends Cube { constructor(color) { - super(color); + super(color, "assets/images/player1.png"); this.data.position.y = 0.5; + this.data.position.x = -2; this.data.rotation.x = this.gameRotation; this.movementData = new Rotation(this.data.position);