xxxxxxxxxx
63
const ufo = {
x: 0,
y: -100,
z: -300,
spin: 0,
domeSize: 30
}
// Properties of the world
let grassTexture
const groundLevel = 100
function preload() {
grassTexture = loadImage("grass.png")
}
function setup() {
createCanvas(400, 400, WEBGL);
noStroke()
}
function draw() {
directionalLight(255, 255, 255, 1, 1, -1)
background("violet");
drawGround();
drawUfo();
moveUfo();
}
function drawGround() {
push()
texture(grassTexture)
translate(0, groundLevel, 0)
rotateX(radians(90))
plane(900, 500)
pop()
}
function drawUfo() {
push()
translate(ufo.x, ufo.y, ufo.z)
rotateY(ufo.spin)
ellipsoid(100, 20, 100);
translate(0, -ufo.domeSize / 2, 0);
sphere(ufo.domeSize);
translate(0, 35, 0)
emissiveMaterial('white')
sphere(10)
pop()
}
function moveUfo() {
if (ufo.z < 0) {
ufo.z++
} else if (ufo.y < groundLevel) {
ufo.y++
} else {
noLoop()
}
ufo.spin += 0.01
}