<commit_before>package player

import (
	"time"

	"github.com/go-gl/mathgl/mgl32"
	"github.com/omustardo/gome/core/entity"
	"github.com/omustardo/gome/demos/asteroids/bullet"
	"github.com/omustardo/gome/model"
	"github.com/omustardo/gome/model/mesh"
	"github.com/omustardo/gome/util"
)

type Player struct {
	model.Model
	MoveSpeed     float32
	RotationSpeed mgl32.Quat

	// canFireAt is the next time the player is able to fire a weapon.
	canFireAt time.Time
	// FireRate is the duration between attacks.
	FireRate time.Duration
}

func New(mesh mesh.Mesh) *Player {
	return &Player{
		Model: model.Model{
			Mesh: mesh,
			Entity: entity.Entity{
				Position: mgl32.Vec3{0, -400, 0},
				// Rotate the model so it starts facing directly toward the positive Y axis, which is up on the user's screen.
				// Remember that these rotations are applied in the order specified by the final parameter
				// and that like a unit circle, positive values go to the "left" and negative values go to the "right".
				// X,Y,Z correspond to Roll, Pitch, and Yaw.
				Rotation: mgl32.AnglesToQuat(mgl32.DegToRad(90), mgl32.DegToRad(-90), 0, mgl32.XYZ),
				Scale:    mgl32.Vec3{50, 50, 50},
			},
		},
		MoveSpeed:     500,
		RotationSpeed: mgl32.AnglesToQuat(0, 0, mgl32.DegToRad(360/3), mgl32.XYZ),
		canFireAt:     time.Now(),
		FireRate:      time.Second * 1,
	}
}

func (p *Player) FireWeapon() *bullet.Bullet {
	if !p.CanFire() {
		return nil
	}
	p.canFireAt = p.canFireAt.Add(p.FireRate)
	b := bullet.New()

	// TODO: This is an odd forward vector - it's dependent on how the model is originally defined and loaded facing -X
	forward := p.Rotation.Rotate(mgl32.Vec3{-1, 0, 0}) // Forward is rotated to point in the direction the ship faces.
	b.Velocity = forward.Mul(800)
	b.Position = p.Position.Add(forward.Mul(p.Scale.X() * 1.3))
	return b
}

func (p *Player) CanFire() bool {
	return time.Now().After(p.canFireAt)
}

func (p *Player) Move(forward, back bool, delta float32) {
	var move float32
	if forward {
		move += delta
	}
	if back {
		move -= delta
	}<commit_msg>Fix bug with firing rate<commit_after>package player

import (
	"time"

	"github.com/go-gl/mathgl/mgl32"
	"github.com/omustardo/gome/core/entity"
	"github.com/omustardo/gome/demos/asteroids/bullet"
	"github.com/omustardo/gome/model"
	"github.com/omustardo/gome/model/mesh"
	"github.com/omustardo/gome/util"
)

type Player struct {
	model.Model
	MoveSpeed     float32
	RotationSpeed mgl32.Quat

	// canFireAt is the next time the player is able to fire a weapon.
	canFireAt time.Time
	// FireRate is the duration between attacks.
	FireRate time.Duration
}

func New(mesh mesh.Mesh) *Player {
	return &Player{
		Model: model.Model{
			Mesh: mesh,
			Entity: entity.Entity{
				Position: mgl32.Vec3{0, -400, 0},
				// Rotate the model so it starts facing directly toward the positive Y axis, which is up on the user's screen.
				// Remember that these rotations are applied in the order specified by the final parameter
				// and that like a unit circle, positive values go to the "left" and negative values go to the "right".
				// X,Y,Z correspond to Roll, Pitch, and Yaw.
				Rotation: mgl32.AnglesToQuat(mgl32.DegToRad(90), mgl32.DegToRad(-90), 0, mgl32.XYZ),
				Scale:    mgl32.Vec3{50, 50, 50},
			},
		},
		MoveSpeed:     500,
		RotationSpeed: mgl32.AnglesToQuat(0, 0, mgl32.DegToRad(360/3), mgl32.XYZ),
		canFireAt:     time.Now(),
		FireRate:      time.Millisecond * 300,
	}
}

func (p *Player) FireWeapon() *bullet.Bullet {
	if !p.CanFire() {
		return nil
	}
	p.canFireAt = time.Now().Add(p.FireRate)
	b := bullet.New()

	// TODO: This is an odd forward vector - it's dependent on how the model is originally defined and loaded facing -X
	forward := p.Rotation.Rotate(mgl32.Vec3{-1, 0, 0}) // Forward is rotated to point in the direction the ship faces.
	b.Velocity = forward.Mul(800)
	b.Position = p.Position.Add(forward.Mul(p.Scale.X() * 1.3))
	return b
}

func (p *Player) CanFire() bool {
	return time.Now().After(p.canFireAt)
}

func (p *Player) Move(forward, back bool, delta float32) {
	var move float32
	if forward {
		move += delta
	}
	if back {
		move -= delta
	}
{'fraction_non_alphanumeric': 0.12376595232362148, 'fraction_numerical': 0.03274741150975199, 'mean_word_length': 3.4050901378579, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4603912', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1506, 'n_words': 442}