kar

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: MIT Imports: 25 Imported by: 0

README

Kar

Kar is a 2D crafting/mining/platformer game (abandoned).

a

Controls

Main Menu
Key Function
Enter Open/Close menu
W/S Menu navigation (up/down)
Confirm the selected menu option.
Gameplay
Key Function
W Look up
S Look down
A Move left
D Move right
⇧ ShiftRight Run
Space Jump
Break block (hold)
Place block (adds block if selected item in inventory is block)
Throw throwable item (if selected item in inventory is throwable)
E Select next inventory slot
Q Select previous inventory slot
R Set Quick-Slot 1
T Set Quick-Slot 2
Tab Switch between Quick-Slot 1 and Quick-Slot 2
Open/Close 2x2 Crafting mode
Open/Close 3x3 Crafting mode (if looking to Crafting Table)
L Switch between camera modes
Special
Key Function
⇧+→ While running at maximum speed, hold down the right arrow key and hit the block to destroy it.
Crafting Mode
Key Function
Move 1 item from inventory to table
Move 1 item from table to inventory
Apply recipe and add to inventory (if space available)
Exits crafting mode and adds slots to inventory, drops items into world if no space
E Select next inventory slot
Q Select previous inventory slot

Documentation

Index

Constants

View Source
const (
	Playing int = iota
	CraftingTable3x3
	Crafting2x2
	Furnace1x2
)

GameplayStates

View Source
const (
	SnowballGravity         float64       = 0.5
	SnowballSpeedX          float64       = 3.5
	SnowballMaxFallVelocity float64       = 2.5
	SnowballBounceHeight    float64       = 9.0
	ItemGravity             float64       = 3.0
	PlayerBestToolDamage    float64       = 5.0
	PlayerDefaultDamage     float64       = 1.0
	RaycastDist             int           = 4 // block unit
	Tick                    time.Duration = time.Second / 60
	ItemCollisionDelay      time.Duration = time.Second / 2
)
View Source
const EPSILON = 1e-8
View Source
const SpaceStr string = " "

Variables

View Source
var (
	Screen      *ebiten.Image
	ScreenSize  = Vec{500, 340}
	WindowScale = 2.0
)

Functions

func AABBPlatform

func AABBPlatform(a, b *AABB, aVel, bVel *Vec, h *HitInfo2) bool

AABBPlatform moving platform b collision

func LoadGame

func LoadGame()

func NewGame

func NewGame()

func Overlap

func Overlap(a, b *AABB, hit *HitInfo) bool

OverlapSweep returns hit info for b

func OverlapSweep

func OverlapSweep(staticA, b *AABB, bDelta Vec, hit *HitInfo) bool

OverlapSweep returns hit info for b

func OverlapSweep2

func OverlapSweep2(a, b *AABB, aDelta, bDelta Vec, hit *HitInfo) bool

OverlapSweep2 returns hit info for b

func SaveGame

func SaveGame()

func Segment

func Segment(a *AABB, pos, delta, padding Vec, hit *HitInfo) bool

func SpawnEffect

func SpawnEffect(pos Vec, id uint8)

func SpawnItem

func SpawnItem(pos Vec, id uint8, durability int) ecs.Entity

func SpawnPlayer

func SpawnPlayer(pos Vec) ecs.Entity

func SpawnProjectile

func SpawnProjectile(id uint8, pos, vel Vec) ecs.Entity

Types

type AABB

type AABB struct {
	Pos  Vec
	Half Vec
}

func (AABB) Bottom

func (a AABB) Bottom() float64

func (AABB) Left

func (a AABB) Left() float64

func (AABB) Right

func (a AABB) Right() float64

func (*AABB) SetBottom

func (a *AABB) SetBottom(b float64)

func (*AABB) SetLeft

func (a *AABB) SetLeft(l float64)

func (*AABB) SetRight

func (a *AABB) SetRight(r float64)

func (*AABB) SetTop

func (a *AABB) SetTop(t float64)

func (AABB) Size

func (a AABB) Size() Vec

func (AABB) Top

func (a AABB) Top() float64

func (AABB) TopLeft

func (a AABB) TopLeft() Vec

type AnimationIndex

type AnimationIndex int // timing-related data for item animations.

type AnimationTick

type AnimationTick float64 // timing-related data for item animations.

type Camera

type Camera struct{}

func (*Camera) Draw

func (c *Camera) Draw()

func (*Camera) Init

func (c *Camera) Init()

func (*Camera) Update

func (c *Camera) Update()

type Collider

type Collider struct {
	Collisions []HitTileInfo // List of collisions from last check
	TileSize   image.Point   // Width and height of tiles
	TileMap    [][]uint8     // 2D grid of tile IDs
}

Collider handles collision detection between rectangles and a 2D tilemap

func (*Collider) Collide

func (c *Collider) Collide(rect AABB, delta Vec, onCollide CollisionCallback) Vec

Collide checks for collisions when moving a rectangle and returns the allowed movement

func (*Collider) CollideX

func (c *Collider) CollideX(rect *AABB, deltaX float64) float64

CollideX checks for collisions along the X axis and returns the allowed X movement

reset list before -> tileCollider.Collisions = tileCollider.Collisions[:0]

func (*Collider) CollideY

func (c *Collider) CollideY(rect *AABB, deltaY float64) float64

CollideY checks for collisions along the Y axis and returns the allowed Y movement

reset list before -> tileCollider.Collisions = tileCollider.Collisions[:0]

type CollisionCallback

type CollisionCallback func(hitInfos []HitTileInfo, delta Vec)

CollisionCallback is called when collisions occur, receiving collision info and final movement

type CollisionDelayer

type CollisionDelayer time.Duration

type Controller

type Controller struct {
	Acceleration                        float64
	AirSkiddingDecel                    float64
	CurrentState                        string
	FallingDamageTempPosY               float64
	Gravity                             float64
	JumpBoost                           float64
	JumpBoostMultiplier                 float64
	JumpHoldTime                        float64
	JumpPower                           float64
	JumpReleaseTimer                    float64
	JumpTimer                           float64
	MaxFallSpeed                        float64
	MaxRunSpeed                         float64
	MaxWalkSpeed                        float64
	MinSpeedThresForJumpBoostMultiplier float64
	PreviousState                       string
	RunAcceleration                     float64
	RunDeceleration                     float64
	ShortJumpVelocity                   float64
	SkiddingFriction                    float64
	SkiddingJumpEnabled                 bool
	SpeedJumpFactor                     float64
	WalkAcceleration                    float64
	WalkDeceleration                    float64
}

type Debug

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

func (*Debug) Draw

func (d *Debug) Draw()

func (*Debug) Init

func (d *Debug) Init()

func (*Debug) Update

func (d *Debug) Update()

type Durability

type Durability int

type Effects

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

block breaking effect system

func (*Effects) Draw

func (e *Effects) Draw()

func (*Effects) Init

func (e *Effects) Init()

func (*Effects) Update

func (e *Effects) Update()

type Enemy

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

func (*Enemy) Draw

func (p *Enemy) Draw()

func (*Enemy) Init

func (p *Enemy) Init()

func (*Enemy) Update

func (p *Enemy) Update()

type Facing

type Facing Vec

type Game

type Game struct {
	Spawn      Spawn
	Platform   Platform
	Enemy      Enemy
	Player     Player
	Item       Item
	Effects    Effects
	Camera     Camera
	Ui         UI
	MainMenu   MainMenu
	Menu       Menu
	Debug      Debug
	Projectile Projectile
}

func (*Game) Draw

func (g *Game) Draw(screen *ebiten.Image)

func (*Game) Init

func (g *Game) Init()

func (*Game) Layout

func (g *Game) Layout(w, h int) (int, int)

func (*Game) LayoutF

func (g *Game) LayoutF(w, h float64) (float64, float64)

func (*Game) Update

func (g *Game) Update() error

type Health

type Health struct {
	Current int
	Max     int
}

type HitInfo

type HitInfo struct {
	Pos    Vec
	Delta  Vec
	Normal Vec
	Time   float64
}

func (*HitInfo) Reset

func (h *HitInfo) Reset()

type HitInfo2

type HitInfo2 struct {
	Right, Bottom, Left, Top bool
	Delta                    Vec
}

func (*HitInfo2) Reset

func (h *HitInfo2) Reset()

type HitTileInfo

type HitTileInfo struct {
	TileCoords image.Point // X,Y coordinates of the tile in the tilemap
	Normal     Vec         // Normal vector of the collision (-1/0/1)
}

HitTileInfo stores information about a collision with a tile

type Item

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

func (*Item) Draw

func (i *Item) Draw()

func (*Item) Init

func (i *Item) Init()

func (*Item) Update

func (i *Item) Update()

type ItemID

type ItemID uint8
type MainMenu struct {
	// contains filtered or unexported fields
}
func (m *MainMenu) Draw()
func (m *MainMenu) Init()
func (m *MainMenu) Update()
type Menu struct {
	// contains filtered or unexported fields
}
func (m *Menu) Draw()
func (m *Menu) Init()
func (m *Menu) Update()

type MobileID

type MobileID int // Mobile character id
const (
	CrabID MobileID = 1
)

MOB ID

type Platform

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

func (*Platform) Draw

func (p *Platform) Draw()

func (*Platform) Init

func (p *Platform) Init()

func (*Platform) Update

func (p *Platform) Update()

type PlatformType

type PlatformType string

type Player

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

func (*Player) Draw

func (c *Player) Draw()

func (*Player) Init

func (p *Player) Init()

func (*Player) Update

func (p *Player) Update()

type Position

type Position Vec

type Projectile

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

func (*Projectile) Draw

func (p *Projectile) Draw()

func (*Projectile) Init

func (p *Projectile) Init()

func (*Projectile) Update

func (p *Projectile) Update()

type Rotation

type Rotation float64

type Spawn

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

func (*Spawn) Draw

func (s *Spawn) Draw()

func (*Spawn) Init

func (s *Spawn) Init()

func (*Spawn) Update

func (s *Spawn) Update()

type UI

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

func (*UI) Draw

func (ui *UI) Draw()

func (*UI) Init

func (ui *UI) Init()

func (*UI) Update

func (ui *UI) Update()

type Vec

type Vec = v.Vec

type Velocity

type Velocity Vec

Directories

Path Synopsis
cmd
kar command
res is resources
res is resources

Jump to

Keyboard shortcuts

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