gonutz

LD 39

LD 40

Write your game in Go

Write your game in Go

This was Fun

I created a little 3D thing in the Go programming language.

https://ldjam.com/events/ludum-dare/40/$55425

Unfortunately it is not yet a game, 72 hours is not much. I created the engine from scratch with Go using my Direct3D9 wrapper library.

002.png

003.gif

LD 41

Write Your Game in Go

Write Your Game in Go

Write Your Game in Go

Write Your Game in Go

Write Your Game in Go

Here is my cross-platform Go game prototyping library in action.

video.gif

This little space ship was created in only 47 lines of code:

package main

import "github.com/gonutz/prototype/draw"

func main() {
    x, y := 60, 240
    var bullets []bullet
    draw.RunWindow("Game", 640, 480, func(window draw.Window) {
        // handle input
        if window.IsKeyDown(draw.KeyRight) {
            x += 3
        } else if window.IsKeyDown(draw.KeyLeft) {
            x -= 3
        }
        if window.IsKeyDown(draw.KeyUp) {
            y -= 2
        } else if window.IsKeyDown(draw.KeyDown) {
            y += 2
        }
        if window.WasKeyPressed(draw.KeySpace) {
            bullets = append(bullets, bullet{x: x + 15, y: y, life: 1})
        }

        // update world
        n := 0
        for i := range bullets {
            bullets[i].x += 6
            bullets[i].life -= 0.01
            if bullets[i].life >= 0 {
                bullets[n] = bullets[i]
                n++
            }
        }
        bullets = bullets[:n]

        // render
        for _, b := range bullets {
            window.FillEllipse(b.x-5, b.y-5, 10, 10, draw.RGBA(0, 1, 0, b.life))
        }
        window.FillRect(x-20, y-20, 40, 40, draw.Red)
    })
}

type bullet struct {
    x, y int
    life float32
}

If you love the Go programming language as much as I do, why not create your game in Go? Give it a try. If you have any questions or suggestions for improvement, hit me up!

Write Your Game in Go

Here is another sample for my cross-platform Go game prototyping library.

video.gif

This little jumper was created in only 33 lines of code:

package main

import "github.com/gonutz/prototype/draw"

func main() {
    x, y := 320, 480
    jumping := false
    velY := 0
    draw.RunWindow("Jump'n'Run", 640, 480, func(window draw.Window) {
        // handle input
        if window.IsKeyDown(draw.KeyLeft) {
            x -= 5
        } else if window.IsKeyDown(draw.KeyRight) {
            x += 5
        }
        if !jumping && window.WasKeyPressed(draw.KeySpace) {
            velY = -20
            jumping = true
        }

        // update world
        velY++
        y += velY
        if y > 480 {
            y = 480
            velY = 0
            jumping = false
        }

        // render
        window.FillRect(x-20, y-40, 40, 40, draw.Red)
    })
}

If you love the Go programming language as much as I do, why not create your game in Go? Give it a try. If you have any questions or suggestions for improvement, hit me up!

Write Your Game in Go

Here is yet another sample for my cross-platform Go game prototyping library.

video.gif

This full-blown RPG game was created in only 40 lines of code:

package main

import "github.com/gonutz/prototype/draw"

func main() {
    x, y := 320, 240
    items := []item{
        item{x: 150, y: 30, color: draw.LightBlue, desc: "This is the mythical man month
 blue means mythical"},
        item{x: 200, y: 370, color: draw.Green, desc: "You see the holy ghost

ghosts are green"}, item{x: 550, y: 190, color: draw.LightPurple, desc: " This is purple"}, } draw.RunWindow("RPG", 640, 480, func(window draw.Window) { // handle input if window.IsKeyDown(draw.KeyLeft) { x -= 3 } else if window.IsKeyDown(draw.KeyRight) { x += 3 } if window.IsKeyDown(draw.KeyDown) { y += 3 } else if window.IsKeyDown(draw.KeyUp) { y -= 3 } // render window.FillRect(x-20, y-20, 40, 40, draw.Red) for _, item := range items { window.FillRect(item.x-10, item.y-10, 20, 20, item.color) if (x-item.x)(x-item.x)+(y-item.y)(y-item.y) < 50*50 { w, _ := window.GetTextSize(item.desc) window.DrawText(item.desc, item.x-w/2, item.y+20, draw.White) } } }) }

type item struct {
    x, y  int
    color draw.Color
    desc  string
}

If you love the Go programming language as much as I do, why not create your game in Go? Give it a try. If you have any questions or suggestions for improvement, hit me up!

No Seriously - Write Your Game in Go

Here is yet another sample for my cross-platform Go game prototyping library.

video.gif

This little star-catcher was created in only 57 lines of code:

package main

import (
    "fmt"
    "github.com/gonutz/prototype/draw"
    "math/rand"
)

func main() {
    x := 320
    score := 0
    nextObstacleIn := 0
    var obstacles []obstacle
    draw.RunWindow("Star Catcher", 640, 480, func(window draw.Window) {
        //  handle input
        if window.IsKeyDown(draw.KeyLeft) {
            x -= 9
        } else if window.IsKeyDown(draw.KeyRight) {
            x += 9
        }
        // update world
        if nextObstacleIn <= 0 {
            nextObstacleIn = 15 + rand.Intn(30)
            obstacles = append(obstacles, obstacle{x: 30 + rand.Intn(580), y: -30})
        }
        nextObstacleIn--
        n := 0
        for i := range obstacles {
            o := &obstacles[i]
            o.y += 6
            destroyObstacle := o.y > 510
            if (o.x-x)*(o.x-x)+(o.y-430)*(o.y-430) <= 40*40 {
                score++
                destroyObstacle = true
            }
            if o.y > 510 {
                score--
            }
            if !destroyObstacle {
                obstacles[n] = obstacles[i]
                n++
            }
        }
        obstacles = obstacles[:n]
        // render
        window.FillRect(x-20, 430, 40, 40, draw.Red)
        for _, o := range obstacles {
            window.FillEllipse(o.x-30, o.y-30, 60, 60, draw.LightBlue)
        }
        window.FillRect(0, 0, 640, 30, draw.DarkGray)
        window.DrawScaledText(fmt.Sprintf("score: %d", score), 0, 0, 2, draw.White)
    })
}

type obstacle struct {
    x, y int
}

If you love the Go programming language as much as I do, why not create your game in Go? Give it a try. If you have any questions or suggestions for improvement, hit me up!

Relax, Take a Break, Play my Game!

Here is a demo of my game No-Brain Jogging after day 1. Play it on Windows, no installer, just run the game:

https://github.com/gonutz/ld41/releases/download/v1.0.1/No-Brain.Jogging.exe

Screenshot:

screen 01.png

Gif video:

video 02.gif