The Cosplorer, Level 2 (Cosplore3D Pt:12)

chigbeef_77

Chig Beef

Posted on February 14, 2024

The Cosplorer, Level 2 (Cosplore3D Pt:12)

Intro

This is a series following Cosplore3D, a raycaster game to learn 3D graphics. This project is part of 12 Months 12 Projects, a challenge I set myself. We just made a level editor in the last post, so now we're going to push it by creating another level.

Loading What I've Already Got

I've already got a baseline for The Cosplorer, a very bare level, but a level nonetheless. I want to see how my level editor shows this level. And... it didn't load, but it wasn't a hard fix, I simply forgot that to split on newline I don't use '\n', but "\r\n", very different. Anyway, here is what we get now.

Top down view of the cosplorer in the editor

Not too bad, but I need to be able to move around the map, and for this I'm going to use the arrow keys. I'm not going to talk too much about improving the editor, as this isn't the post for that, and they'll just be minor changes like this.

Adding Enemies

The ship is currently extremely bare, only with walls, but it would be great to add enemies and ammo.

Enemies and ammo in The Cosplorer

You may also notice the heart, this is where the player will start in the world, which actually took a while to implement because I forgot that we load all levels at the start of running the game, which was a skill issue on my part.

The Cosplorer rendered in 3D

From Ankaran To The Cosplorer

Currently, the two levels are disconnected, and if I want to play them in succession then I have to restart the whole application. However, in the lore, the player acquires the Cosmium and takes it back to the ship. In this way, I would like the player to pick up the Cosmium, and head back to their spawn location. Then, a hit box will load the next level, but only if the player is holding Cosmium.
Let's start by allowing the player to hold items.

func pickup_cosmium(g *Game) {
    g.player.inventory = append(g.player.inventory, "Cosmium")
}
Enter fullscreen mode Exit fullscreen mode

Simple, now let's create these hitboxes.

type Progressor struct {
    x         float64
    y         float64
    w         float64
    h         float64
    check     Check
    levelName string
}

type Check func(*Game) bool

func (p *Progressor) check_collide(g *Game) {
    x := g.player.x
    y := g.player.y

    if p.x <= x && x <= p.x+p.w {
        if p.y <= y && y <= p.y+p.h {
            if p.check(g) {
                g.player.curLevel = p.levelName
            }
        }
    }
}

func has_cosmium(g *Game) bool {
    return slices.Contains(g.player.inventory, "Cosmium")
}
Enter fullscreen mode Exit fullscreen mode

Progressors are just like Tiles, except when you collide with them you get transported to the next level (if you meet the requirements). Now I'm going to place some in the Ankaran map. Now when I collide with one, I'm transported to The Cosplorer, so this worked perfectly. Lastly, I added progressors to the editor.

Next

Constantly seeing the same type of enemy is kind of dull, so I really want to add more. There are 2 types of enemies in the game, but they both have the same art. I don't enjoy making art as much as programming, so by getting a few enemies out of the way I'll be good for enemies for a while.

Also, happy Valentine's day, maybe try coding your partner a present? It's always a fun challenge, especially for creativity.

💖 💪 🙅 🚩
chigbeef_77
Chig Beef

Posted on February 14, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related