Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

How to make a capstone game? (game with multiple levels in it)

I am trying to make a multi-stage or multi-level game in Game Development 3 as my final project but I cannot make my game move onto the second stage after completing the requirements to pass the first stage of the game, and I am checking to see if the requirements for the first stage are met or not.

hero = game.spawnHeroXY(30, 30)
hero.attackDamage = 40
hero.maxHealth = 400
hero.speed = 20
ui.track(game, "time")
ui.track(hero, "health")

game.addSurviveGoal(10)
goal1 = game.addManualGoal("Defeat at least 10 enemies. Collect lightstones to drive away the skeletons. ")
goal2 = game.addMoveGoalXY(60, 40)
enemy = game.spawnXY("skeleton", 10, 20)
enemy.attack(hero)
enemy.speed = 15
enemy = game.spawnXY("munchkin", 30, 40)
enemy.attack(hero)
enemy.attackDamage = 5
enemy.speed = 15
enemy = game.spawnXY("skeleton", 30, 20)
enemy.attack(hero)
enemy.speed = 15
enemy = game.spawnXY("munchkin", 60, 10)
enemy.attack(hero)
enemy.attackDamage = 5
enemy.speed = 15
enemy = game.spawnXY("skeleton", 10, 60)
enemy.attack(hero)
enemy.attackDamage = 10
enemy.speed = 15
enemy = game.spawnXY("skeleton", 50, 40)
enemy.attack(hero)
spawner = game.spawnXY("generator", 45, 56)
spawner.spawnDelay = 10
spawner.spawnType = "munchkin"
spawner.spawnAI = "AttacksNearest"
spawner = game.spawnXY("generator", 30, 10)
spawner.spawnDelay = 8
spawner.spawnType = "munchkin"
spawner.spawnAI = "AttacksNearest"
xmark = game.spawnXY("x-mark-stone", 60, 40)
def spawnRandomLightstone():
    x = game.randomInteger(20, 60)
    y = game.randomInteger(10, 58)
    lightstone = game.spawnXY("lightstone", x, y)
    lightstone.dirX = game.randomInteger(-1, 1)
    lightstone.dirY = game.randomInteger(-1, 1)
    lightstone.scale = 1.5
spawnRandomLightstone()
spawnRandomLightstone()
spawnRandomLightstone()
spawnRandomLightstone()
spawnRandomLightstone()
spawnRandomLightstone()
spawnRandomLightstone()

lightstoneSpeed = 0.6


def onUpdate(event):
    item = event.target
    
    diffX = item.dirX * lightstoneSpeed
    diffY = item.dirY * lightstoneSpeed
    
    item.pos.x += diffX
    item.pos.y += diffY
    if item.pos.x > 70 or item.pos.x < 10:
        item.dirX *= -1
    if item.pos.y > 58 or item.pos.y < 10 :
        item.dirY *= -1

game.setActionFor("lightstone", "update", onUpdate)

def spawnRandomPotion():
    x = game.randomInteger(20, 60)
    y = game.randomInteger(10, 58)
    potion = game.spawnXY("potion-large", x, y)
    potion.dirX = game.randomInteger(-1, 1)
    potion.dirY = game.randomInteger(-1, 1)
    potion.scale = 1.5
spawnRandomPotion()
spawnRandomPotion()
spawnRandomPotion()
spawnRandomPotion()
spawnRandomPotion()
def onDefeat(event):
    defeated = event.target
    game.defeated += 1
    if game.defeated > 10 :
        game.setGoalState(goal1, True)
game.setActionFor("skeleton", "defeat", onDefeat)
game.setActionFor("munchkin", "defeat", onDefeat)
hero.on("defeat", onDefeat)
if ui.track(game, "defeated") > 10 :
    game.setGoalState(goal1, True)
    if goal1.success and goal2.success :  <--------------this doesn't seem to work and so is the code below this line
        goal3 = game.addManualGoal("Avoid the fences and dodge the fire-traps! Lure enemies into traps and leave them behind!")
        game.addCollectGoal(20)
        ui.track(game, "collected")
        game.collected = 0
        hero.on("collect", onCollect)
        def onCollect(event):
            unit = event.target
            item = event.other
            if item.type == "gold-coin":
                game.collected += 1
        game.spawnXY("forest", -4, 64)
        game.spawnXY("forest", 4, 64)
        game.spawnXY("forest", 12, 64)
        game.spawnXY("forest", 20, 64)
        game.spawnXY("forest", 28, 64)
        game.spawnXY("forest", 36, 64)
        game.spawnXY("forest", 44, 64)
        game.spawnXY("forest", 52, 64)
        game.spawnXY("forest", 60, 64)
        game.spawnXY("forest", 68, 64)
        game.spawnXY("forest", 76, 64)
        game.spawnXY("forest", -4, 4)
        game.spawnXY("forest", 4, 4)
        game.spawnXY("forest", 12, 4)
        game.spawnXY("forest", 20, 4)
        game.spawnXY("forest", 28, 4)
        game.spawnXY("forest", 36, 4)
        game.spawnXY("forest", 44, 4)
        game.spawnXY("forest", 52, 4)
        game.spawnXY("forest", 60, 4)
        game.spawnXY("forest", 68, 4)
        game.spawnXY("forest", 76, 4)
        
        # This moves the environment objects to create the illusion of running.
        def onUpdateStatic(event):
            thing = event.target
            # Each time frame we move a little to the left:
            thing.pos.x -= 0.8
            # If thing's X coordinate is less than -4:
            if thing.pos.x < -4 :
                # If thing's type is "forest":
                if thing.type == "forest" :
                    # Then set thing.pos.x to 84, so it can re-enter the map from the right side:
                    thing.pos.x = 84
                # Otherwise destroy the thing:
                else :
                    thing.destroy()
        
        # Assign onUpdateStatic to handle the "update" event for all "forest" objects.
        game.setActionFor("forest", "update", onUpdateStatic)
        
        # This spawns a fence on the right side of the map, at a random Y coordinate.
        def spawnRandomY(type):
            y = game.randomInteger(12, 56)
            spawn = game.spawnXY(type, 80, y)
            # Fences should move to the left.
            spawn.on("update", onUpdateStatic)
        
        # This spawns a number of fences, based on the game time.
        def spawnFences():
            # Spawn 1 until 10 seconds, 2 until 20 seconds, and so on.
            spawnNumber = 1 + (game.time / 10)
            while spawnNumber >= 1:
                spawnRandomY("fence")
                spawnNumber -= 1
        
        # Setup the game, timers, UI, and goals.
        game.spawnFenceTime = 0
        ui.track(game, "time")
        game.addSurviveGoal(15)
        
        # hero setup.
        
        # This handles the hero's "collide" events. Defeat the hero if they hit a fence!
        def onCollide(event):
            unit = event.target
            other = event.other
            if other.type == "fence":
                unit.defeat()
        
        hero.on("collide", onCollide)
        
        # Those functions define the game loop.
        def checkhero():
            # The hero should be stationary along the X axis, so we set their X position to a constant number.
            hero.pos.x = 20
        
        def checkTimers():
            if game.time > game.spawnFenceTime:
                spawnFences()
                game.spawnFenceTime += 1
        
        def onUpdateGame(event):
            checkhero()
            checkTimers()
        game.on("update", onUpdateGame)
        
            
        
        
        
        
        
        
        
        
        
        
        
    
        
    
        
        





Hi, I’m afraid I’m not really sure how you do this. I was never very good at the game development levels. @Chaboi_3000, might be able to help.
Or you could visit the https://codecombat.slack.com and ask there.
Danny

1 Like

Ok, thank you for your suggestions!

I’m actually not so familiar with how the Game Dev levels work(I only work with the level editor). Will take a look at it later.