Skip to content

Instantly share code, notes, and snippets.

@stevekrouse
Created July 3, 2017 16:55
Show Gist options
  • Select an option

  • Save stevekrouse/1a66539026cc5f80a4cb1d8f255bd0f9 to your computer and use it in GitHub Desktop.

Select an option

Save stevekrouse/1a66539026cc5f80a4cb1d8f255bd0f9 to your computer and use it in GitHub Desktop.
setBackdropColor('black')
var rocket = new Image({
url: "./docs/images/rocket.png",
width: 120,
height: 60,
y: minY + 100,
angle: UP
})
when(() => keysDown.includes('LEFT'), () => {
rocket.x -= 5
})
when(() => keysDown.includes('RIGHT'), () => {
rocket.x += 5
})
var enemies = []
for (var y = -3; y < 3; y++) {
var row = []
for (var x = -3; x < 3; x++) {
var enemy = new Image({
url: "./docs/images/space_ship.png",
width: 30 * 2,
height: 17 * 2,
x: (x * 60) - 100,
y: (y * 50) + 200,
rotationStyle: "NO ROTATE"
})
row.push(enemy)
}
enemies.push(row)
}
var flatten = a => a.reduce(
( acc, cur ) => acc.concat(cur),
[]
);
every(700, 'miliseconds', () => {
var allEnemies = flatten(enemies)
if (allEnemies.length > 0) {
var leftMost = allEnemies.reduce((min, next) => next.x < min.x ? next : min , allEnemies[0])
var rightMost = allEnemies.reduce((max, next) => next.x > max.x ? next : max , allEnemies[0])
if (leftMost.x < minX || rightMost.x > maxX) {
allEnemies.forEach(enemy => enemy.turnRight(180))
allEnemies.forEach(enemy => enemy.y -= 10)
}
allEnemies.forEach(enemy => enemy.move(10))
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment