opesvengine

package module
v0.0.0-...-4ab08ed Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

README

OPESV Engine

Orthogonal Perspective Elevation Side View Game Engine.

A simplistic 2d game plataform shooter boiler plate.

OpesV-Engine aims to provide a simplistic platform for 2d games.

This is not production ready and probably never will. This is Work in Progress, plus it's done only for enterteinment purposes, so probably it wont be useful to you... yet.

It uses ebiten game library. The images in the demo game belongs to that project, it is their default image samples.

What can be done with it for now:

- create a tile based map.
- control a player that jumps and shoot his gun.
- control enemies that fiercely tries to kill our hero.
- collision detection.
- guns can be changed, and can be parametrized (damage, rate of fire, range, etc)

To be done:

- looking for a performant way to flip images when player changes direction.
- allow maps larger than screen.
- make usage of different tile sizes easier.
- better AI for npcs.
- different actions for NPCs (now they just care about one thing: Kill you).
- a score panel.
- (SOLVED) still get stuck on the walls sometimes...
- documentation.

Running the example:

    git clone https://github.com/gsteixeira/opesvengine
    cd opesvengine/
    # get dependencies
    go mod tidy
    go run sample/demo.go

Create a sprite (static object):

    // you can specify an image or use the images described in ebiten
    img := opesvengine.Get_img_from_file("some_image.png")
    // create the sprite
    foo := opesvengine.NewSprite(10, 10, img, false)

Create a Character (a live, movable object):

    // specify an image
    img := opesvengine.Get_img_from_file("some_image.png")
    // set initial parameters
    pos_x := 0
    pos_y := 0
    width := 16
    height := 32
    // create the character
    player := opesvengine.NewCharacter(pos_x, pos_y, width, height, img)

Documentation

Index

Constants

View Source
const (
	GRAVITY      = 0.1
	JUMP_POWER   = 4
	FWD_SPEED    = 1
	LEFT         = -1
	RIGHT        = 1
	TILESIZE     = 32
	FRAME_WIDTH  = TILESIZE
	FRAME_HEIGTH = TILESIZE
)

Constants for physics

Variables

This section is empty.

Functions

func GeDraw

func GeDraw(g *Universe, screen *ebiten.Image)

Ebiten Draw method of GamEngine Draw map.

func GeUpdate

func GeUpdate(g *Universe)

Ebiten Update method of GamEngine

func Get_img_from_file

func Get_img_from_file(filename string) image.Image

return an image from a local file

Types

type Character

type Character struct {
	// contains filtered or unexported fields
}

The character represents a live entity.

func NewCharacter

func NewCharacter(x, y float64, width, height int, img image.Image) Character

Character entity constructor method

func (*Character) Get_health

func (c *Character) Get_health() int

Get character's health - getter

func (*Character) Set_weapon

func (c *Character) Set_weapon(gun Weapon)

Change character's weapon

func (*Character) Shoot

func (c *Character) Shoot(universe *Universe)

Act of shooting a gun

type Sprite

type Sprite struct {
	// shape
	Width  int
	Heigth int

	Parent *Character

	Frame_offset_x int
	Frame_offset_y int

	Static bool
	// contains filtered or unexported fields
}

Sprite objects.

func Draw_map

func Draw_map(the_map [][]int, img image.Image,
	frameWidth int, frameHeight int) []Sprite

Convert a matrix of numbers into a nice map. We use this number to find its X and Y on the tilemap file, so we get the right subimages. 0 means blank tile

func NewSprite

func NewSprite(x float64, y float64, imgr image.Image, is_static bool) Sprite

Sprite constructor method

func (*Sprite) Get_position_onmap

func (s *Sprite) Get_position_onmap(game *Universe) (float64, float64)

get X, Y position based on map instead of screen

func (*Sprite) Set_dimensions

func (s *Sprite) Set_dimensions(width, heigth int)

Set sprite dimensions

func (*Sprite) Set_frames

func (s *Sprite) Set_frames(frame_width int, frame_heigth int,
	frame_number int)

Set sprite frame (sub image and tile size) parameters

type SpriteRect

type SpriteRect struct {
	// contains filtered or unexported fields
}

this struct keeps info about the sprite boundaries, so we dont have to calculate it again

type Universe

type Universe struct {
	Player      Character
	Enemies     []Character
	Projectiles []Sprite
	Tile_map    []Sprite
	Keys        []ebiten.Key
	// Screen size
	ScreenWidth  int
	ScreenHeight int
	// Tile size in pixels
	TileSize_X int
	TileSize_Y int
	// To be used by camera
	MapOffset_x int
	MapOffset_y int
}

Universe holds everything related to the game

type Weapon

type Weapon struct {
	// contains filtered or unexported fields
}

this class represent a weapon and it's attributes

func NewWeapon

func NewWeapon(name string, max_speed float64,
	max_distance float64, damage int,
	fire_rate int64, img image.Image) Weapon

Weapon constructor method

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL