Broken Rocket Launcher (Cosplore3D Pt:24)
Tags: go, learning, gamedev
Published: 2024-02-28 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.
Today is our last major feature of this project, which is adding in a second weapon.

## Altering The Weapon
First thing I want to change is the actual `Weapon` struct, so that it's easier to differentiate between the two weapons. Firstly, I implemented a rate of fire, so that we can't spam guns.
```golang
if w.rofCounter > 0 {
	return false
}

w.rofCounter = w.rof
```
That's great, now I want a name added to the gun, which will be displayed on screen.

![Weapon name is now displayed on screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09mr0mmgh678k59vm76e.png)

Wow, doesn't that just look beautiful.

## Player Has More
```golang
type Player struct {
	x          float64
	y          float64
	z          float64
	angle      float64
	camera     *Camera
	curLevel   string
	speed      float64
	haste      float64
	health     float64
	weapon     *Weapon
	weapons    []*Weapon
	inventory  []InvItem
	bobCounter uint8
}
```
Bam, now the player has multiple weapons.

## Switching
```golang
if inpututil.IsKeyJustPressed(ebiten.KeyE) {
	p.curWeaponIndex++
	if p.curWeaponIndex == len(p.weapons) {
		p.curWeaponIndex = 0
	}
	p.weapon = p.weapons[p.curWeaponIndex]
}
```
So simple, and it works. And it's so great being able to one shot things now, but obviously there's a delay that we added in just before. That was pretty easy to implement, and in future I could technically add as many weapons as I would like, but for now 2 is enough.

## Next
There is no next, that's it for Cosplore3D. It's also an early death to 12 Months 12 Projects, sadly, but for good reason. I have a new project, [CompNerdSim](https://chigbeef.itch.io/compnerdsim) that I want to work on. 12 Months 12 Projects, for the limited time I've worked on it, has taught me how to stick to one project at a time, for a variable amount of time. Now I'm going to try to use this to create a game I can sell. So you could think of this as an ad, but I'll give you the rundown of the game, because I think it's a cool concept.

CompNerdSim follows a neckbeard (you), who's girlfriend leaves to live in another state. Sad, I know, but you're determined to go visit her, but that dang inflation means that plane tickets cost a lot. Spending 12 hours a day on a computer, you may as well use that time to make some money. In this way, you start coding to make money, in the amazing language Slither. You create some simple programs, become a gamedev even, and eventually make enough money to buy a ticket over to her.

Damn, that sounds boring, but it's not, and here's why. Firstly, the game has a text editor inside of it, called Bim and BScode. Secondly, _Slither_, which is an interpreted language that will run inside of the game. This means you can write whatever you want. I will also be including graphics for Slither, so you could make your own games in this game. Lastly, such a compelling story, isn't it?