The Cosplorer, Level 2 (Cosplore3D Pt:12)
Tags: go, gamedev, learning
Published: 2024-02-14 01:30:00

## Intro
This is a series following [Cosplore3D](https://github.com/Chig-Beef/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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kxvbrdy08tmr7c07iwod.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7zs39z2wwusunpxnld7.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2hatakp5bzo2f272sjb.png)

## 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.
```golang
func pickup_cosmium(g *Game) {
    g.player.inventory = append(g.player.inventory, "Cosmium")
}
```
Simple, now let's create these hitboxes.
```golang
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")
}
```
`Progressor`s are just like `Tile`s, 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.