1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- var floatingItems = [];
- sets.push({
- id: "begin-pickup-cargo",
- setup: () => {
- if(!setsLoaded['begin-pickup-cargo']) {
- buildBeginPickup();
- setsLoaded['begin-pickup-cargo'] = true;
- }
- },
- update: (delta) => {
- updateBeginPickup(delta);
- },
- draw: (context, delta) => {
- drawBeginPickup(context, delta);
- },
- });
- function buildBeginPickup() {
- floatingItems = [];
- floatingItems.push({
- sprite: `pill_red.png`,
- x: -50,
- y: 50,
- angle: Math.floor(360 * Math.random()),
- rotationSpeed: (4 * Math.random()) - 2,
- velocity: {x: 0, y: 0},
- });
- floatingItems.push({
- sprite: `pill_green.png`,
- x: 130,
- y: 75,
- angle: Math.floor(360 * Math.random()),
- rotationSpeed: (4 * Math.random()) - 2,
- velocity: {x: 0, y: 0},
- });
- floatingItems.push({
- sprite: `pill_yellow.png`,
- x: 0,
- y: -100,
- angle: Math.floor(360 * Math.random()),
- rotationSpeed: (4 * Math.random()) - 2,
- velocity: {x: 0, y: 0},
- });
- }
- function updateBeginPickup(delta) {
- for(let i = 0; i < floatingItems.length; i++) {
- let pickup = floatingItems[i];
- pickup.angle += pickup.rotationSpeed;
- pickup.angle %= 360;
- pickup.x += pickup.velocity.x;
- pickup.y += pickup.velocity.y;
- }
- }
- function drawBeginPickup(context, delta) {
- for (let i = 0; i < floatingItems.length; i++) {
- let pickup = floatingItems[i];
- context.save();
- context.translate(pickup.x, pickup.y);
- context.rotate(pickup.angle * Math.PI / 180);
- atlas.drawCentered(context, pickup.sprite, { x: 0, y: 0 });
- context.restore();
- }
- }
|