Created
November 25, 2020 10:57
-
-
Save joshuaChoiXD/5f1eb4311a283d14cbf83fa5a4eeee1f to your computer and use it in GitHub Desktop.
CodeCombat Game Development 3 (1 - 10) Answers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#CodeCombat | |
#Game Development 3 | |
#Level 1 - 10 Answers | |
#Level 1 | |
ui.setText("directions", "Code Provided by Revolution Game") | |
def shouldAttack(who, target): | |
if who.type == "scout" and target.type == "soldier": | |
return True | |
if who.type == "soldier" and target.type == "thrower": | |
return True | |
if who.type == "thrower" and target.type == "archer": | |
return True | |
if who.type == "archer" and target.type == "scout": | |
return True | |
def onUpdateUnit(event): | |
unit = event.target | |
enemy = unit.findNearestEnemy() | |
if enemy and shouldAttack(unit, enemy): | |
unit.attack(enemy) | |
else: | |
if unit.team == "ogres": | |
unit.moveXY(unit.pos.x - 3, unit.pos.y) | |
else: | |
unit.moveXY(unit.pos.x + 3, unit.pos.y) | |
pass | |
if unit.pos.x > 80 or unit.pos.x < 0: | |
unit.destroy() | |
game.setActionFor("thrower", "update", onUpdateUnit) | |
game.setActionFor("scout", "update", onUpdateUnit) | |
game.setActionFor("archer", "update", onUpdateUnit) | |
game.setActionFor("soldier", "update", onUpdateUnit) | |
game.interval = 2 | |
game.spawnTime = 0 | |
game.addDefeatGoal(10) | |
def spawnRandomUnit(x, type0, type1): | |
typeNumber = game.randomInteger(0, 1) | |
y = game.randomInteger(12, 56) | |
if typeNumber == 0: | |
game.spawnXY(type0, x, y) | |
else: | |
game.spawnXY(type1, x, y) | |
def onUpdateGame(event): | |
if game.time > game.spawnTime: | |
game.spawnTime += game.interval | |
spawnRandomUnit(2, "archer", "soldier") | |
spawnRandomUnit(78, "thrower", "scout") | |
game.on("update", onUpdateGame) | |
#Level 2 | |
#Probably my computer is trash so that this code won't work when I tried it again. | |
#Comment below that does this code work for you | |
ui.setText("directions", "Code Provided by Revolution Game") | |
game.scoutInterval = 3 | |
game.scoutSpawnTime = 0 | |
game.ogreInterval = 5 | |
game.ogreSpawnTime = 2 | |
game.ogresDefeated = 0 | |
ui.track(game, "ogresDefeated") | |
ogreGoal = game.addManualGoal("Defeat 5 big ogres.") | |
scaleGoal = game.addManualGoal("Grow twice.") | |
def spawnRandomXY(type): | |
x = game.randomInteger(12, 68) | |
y = game.randomInteger(12, 56) | |
unit = game.spawnXY(type, x, y) | |
unit.behavior = "AttacksNearest" | |
def onDefeat(event): | |
game.ogresDefeated += 1 | |
game.setActionFor("ogre", "defeat", onDefeat) | |
player = game.spawnPlayerXY("goliath", 40, 34) | |
player.attackDamage = 1000 | |
player.maxHealth = 100000 | |
def onUpdatePlayer(event): | |
unit = event.target | |
if unit.health < unit.maxHealth / 3: | |
# Increase the health, size and damage. | |
unit.maxHealth *= 1.2 | |
unit.health = unit.maxHealth | |
unit.scale *= 1.2 | |
unit.attackDamage *= 1.2 | |
unit.say("SMASH!") | |
player.on("update", onUpdatePlayer) | |
def checkTimers(): | |
if game.time > game.scoutSpawnTime: | |
spawnRandomXY("scout") | |
game.scoutSpawnTime += game.scoutInterval | |
if game.time > game.ogreSpawnTime: | |
spawnRandomXY("ogre") | |
game.ogreSpawnTime += game.ogreInterval | |
def checkGoals(): | |
if player.scale >= 2: | |
game.setGoalState(scaleGoal, True) | |
if game.ogresDefeated >= 5: | |
game.setGoalState(ogreGoal, True) | |
def onUpdateGame(event): | |
checkTimers() | |
checkGoals() | |
pass | |
game.on("update", onUpdateGame) | |
#Level 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WHERE IS LEVEL 3!?!