Golang

Create a Flappy Bird Clone With Golang P3

I hope that by trying removals and changing parameters, you have figured out what these lines of code do:

    op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(-float64(frameWidth)/2, -float64(frameHeight)/2)
	op.GeoM.Translate(screenWidth/2, screenHeight/2)

In case you haven’t, let’s quickly check the Cheatsheet for ebiten.DrawImageOptions

type DrawImageOptions struct {
    // GeoM is a geometry matrix to draw.
    // The default (zero) value is identify, which draws the image at (0, 0).
    GeoM GeoM

    // ColorM is a color matrix to draw.
    // The default (zero) value is identity, which doesn't change any color.
    ColorM ColorM

    // CompositeMode is a composite mode to draw.
    // The default (zero) value is regular alpha blending.
    CompositeMode CompositeMode

    // Filter is a type of texture filter.
    // The default (zero) value is FilterDefault.
    Filter Filter
}

And here is Cheatsheet for ebiten.GeoM

Create a Flappy Bird Clone With Golang P2

Last time, we stopped at mentioning that there are three functions needed for the game loop: Update(), Draw() and Layout(), of which all are functions of the Game struct. According to the cheatsheet, the whole Game struct is an instance of the Game interface, as follow:

type Game interface {
    // Update updates a game by one tick. The given argument represents a screen image.
    Update(screen *Image) error

    // Draw draw the game screen. The given argument represents a screen image.
    //
    // (To be exact, Draw is not defined in this interface due to backward compatibility, but RunGame's
    // behavior depends on the existence of Draw.)
    Draw(screen *Image)

    // Layout accepts a native outside size in device-independent pixels and returns the game's logical
    // screen size. On desktops, the outside is a window or a monitor (fullscreen mode)
    //
    // Even though the outside size and the screen size differ, the rendering scale is automatically
    // adjusted to fit with the outside.
    //
    // You can return a fixed screen size if you don't care, or you can also return a calculated screen
    // size adjusted with the given outside size.
    Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int)
}

If you have a background of C, C++, Java and the like, concepts of interface (and struct) might be familiar to you, but in case they aren’t, here are my quick explanations:

Create a Flappy Bird Clone With Golang P1

This weekend I decided to start another tutorial series in this blog, as I did learn a lot during making the last one. This time I decided to up the ante by picking up on a language that I am not very familiar with: Go Programming Language, or Golang. If it is the first time you heard of it, Go is a language designed at Google, is syntactically similar to C and is very well-designed to support concurrency. One of Go’s authors, Ken Thompson, was also one author of B language (together with Dennis Ritchie) (B was the direct predecessor of C Programming Language).