GithubHelp home page GithubHelp logo

aspiesoft / go-game-template Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 2.3 MB

A multi threaded game template for modifying to your needs.

License: MIT License

Go 100.00%
2d-game-engine game-development go golang template template-engine template-project template-repository

go-game-template's Introduction

Go Game Template

donation link

A multi threaded game template for modifying to your needs.

Note: This module is still in Alpha, and it may likely see many breaking changes until it is released under v1.0

Installation

git clone https://github.com/AspieSoft/go-game-template

Setup

Most of the files you will need to configure are in the src directory.

The init.go file is called with its Init method once the game starts (a capital Init, not the default lowercase init).

Creating New Game Objects

import (
  "game/BorderMethod"
  "game/gamehandler"
  "image/color"

  "fyne.io/fyne/v2"
  "fyne.io/fyne/v2/canvas"
)

func init(){
  gamehandler.InitObject(func(game *gamehandler.Game) {
    object := game.Add("object", "MyObject", -game.Size.Width - 5, -game.Size.Height - 5, 5, 5, func(game *gamehandler.Game) fyne.CanvasObject {
      res := canvas.NewRectangle(color.RGBA{255, 0, 0, 255})
      return res
    })

    // by default, border detection and other builtin features run on the 120 fps draw method
    // setting an objects Preferred FPS allows you to override this to use a slower thread if needed
    // recommended: use 60 fps for a player, to prevent input lag (30 fps works better for entities)
    object.PreferredFPS = 30

    object.VelX = 3
    object.VelY = 3

    // there are optional builtin methods for handling basic common tasks
    object.BorderMethod = BorderMethod.Bounce

    object.Update := func(game *gamehandler.Game, thread *gamehandler.ThreadInfo) {
      // run updates on a 60 fps thread
      // useful for most common game updates, or player related updates with less lag
    }

    object.UpdateSlow := func(game *gamehandler.Game, thread *gamehandler.ThreadInfo) {
      // run updates on a slower 30 fps thread
      // useful for a large number of extra objects to share a slower thread
    }

    object.UpdateBasic := func(game *gamehandler.Game, thread *gamehandler.ThreadInfo) {
      // run updates on a slow, cpu saving 15 fps thread
      // useful for larger math operations
    }

    object.Draw := func(game *gamehandler.Game, thread *gamehandler.ThreadInfo) {
      // run updates on a fast 120 fps thread
      // useful for graphics
    }
  }
}

go-game-template's People

Contributors

aspiesoft avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.