Creating An Ending (Cosplore Pt:22)
Tags: go, gamedev, learning
Published: 2024-02-26 10:56:43

## 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 finally decided in the last post that beating the last boss and nothing happening just wasn't good enough, we need to reward the player with an ending.

## Lore Based
By the lore, the player finally is able to get to his home planet, but is shot from the sky. This is how he ends up on Schmeltool. The player then finds a life ship, and leaves to an unknown section of space where no one can hurt him, until he obviously comes back in a sequel. Now, I have no idea how to do great cinematics, or complex animations, but I can show pictures. Therefore, a comic book-like approach could be best, showing one picture at a time. This is probably the simplest solution, while still allowing a high execution margin, and, well, I'm too lazy for animation.

## Listing The Pictures
Before we start making these "cinematic" pictures, we need to know what we're making.

1. Life Ship with Crawlers surrounding
2. Life Ship door slamming shut
3. Thrusters hitting crawlers
4. Life Ship shooting off of the planet
5. Life Ship alone in space (maybe a to be continued or something cheesy)

## I was busy
So that didn't end up happening, and neither did any of these posts (': Busy times means this project isn't a priority but I really want to make some sort of ending, so I've come up with a new one. Here is the ending image.

![Ending of cosplore3d](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/npajv6k1kgc5qollpvfp.png)

Or at least, this is one of the 2 image so it looks a bit animated. I fade these images for 10 seconds before finally exiting, here is the code for all that.
```golang
package main

import (
	"os"

	"github.com/hajimehoshi/ebiten/v2"
)

type Ending struct {
	images  []*ebiten.Image
	counter uint16
	max     uint16
}

func (e *Ending) update() {
	e.counter++

	if e.counter == e.max {
		os.Exit(0)
	}
}

func (e *Ending) draw(screen *ebiten.Image) {
	img := e.images[(e.counter/7)%2]
	ogW, ogH := img.Size()

	op := ebiten.DrawImageOptions{}
	op.GeoM.Scale(screenWidth/float64(ogW), screenHeight/float64(ogH))
	op.ColorScale.ScaleAlpha(float32(e.max-e.counter) / float32(e.max))

	screen.DrawImage(img, &op)
}
```
Easy code, simply drawing an image, making sure it fills the entire screen, making it fade out, and having a counter so we do so every frame. We also exit once we're done, as a sort of mic drop to this project.

## Next
I swear I'm getting more views and followers after having missed multiple days working on this project, however, I have 3 changes I want to create before the end of the month.

1. Fix the terrible soundtrack (not Enikoko, that's fire)
2. Add a new weapon, hopefully
3. Cleanup, just like how we did that compiler cleanup on [Pogo](https://dev.to/chigbeef_77/compiling-python-to-go-pogo-pt1-3lah)

3 days and 3 things to do, I'm going to post this post not at regular time so I can start working on the next post straight away. Thank you for those who have been following with me even with my slack (:

One more thing, I was checking my GitHub one day when I realized I had a notification, which I don't usually get on GitHub. Look through the code, recommend that I add things, whatever you want. This project is about to end starting March, but issues mentioned, if interesting enough, might amount to another post. And especially comment about anything that doesn't make sense or should be added (: Remember, Cosplore3D is open source, so you can take my code and do whatever you want with it, just have tinkering with it more than you usually would playing the actual game.