Commit 7fd6585e authored by Vivien Leclercq's avatar Vivien Leclercq
Browse files

Deleted final/agent/agent.go, final/agent/bird.go, final/agent/music.go,...

Deleted final/agent/agent.go, final/agent/bird.go, final/agent/music.go, final/game/game.go, final/settings/settings.go, final/settings/window.go, final/vectors/vector2d.go, final/worldelements/food.go, final/worldelements/map.go, final/worldelements/wall.go, final/go.mod, final/go.sum, final/main.go, final/t2.png, final/t3.png files
parent 1c7c0a31
package agent
//Agent interface pour tous les agents de la simulation
type Agent interface {
Start() //Fonction permettant d'initialiser l'agent
Update() //Fonction permettant de modifier le comportement de l'agent (position)
Draw() //Fonction permettant d'afficher l'agent
}
package agent
import (
"math"
"math/rand"
ebiten "github.com/hajimehoshi/ebiten/v2"
settings "gitlab.utc.fr/jedescam/projet_ia04/final/settings"
vectors "gitlab.utc.fr/jedescam/projet_ia04/final/vectors"
)
//Bird type représente un agent qui se déplace de manière groupé dans le monde. Equivalent au comportement d'un oiseau
type Bird struct {
ID int
position vectors.Vector2D
vitesse vectors.Vector2D
acceleration vectors.Vector2D
longueur float64
rayonSeparation float64
rayonCohesion float64
rayonVitesse float64
maxForce float64
maxSpeed vectors.Vector2D
separation map[*Bird]bool
Cohesion map[*Bird]bool
alignement map[*Bird]bool
evitement int
ty int
}
//NewBird constructeur qui permet de créer un nouvel agent
func NewBird(s settings.Settings, id int) *Bird {
return &Bird{id, vectors.Vector2D{0, 0}, vectors.Vector2D{0, 0}, vectors.Vector2D{0, 0}, s.AgentLongueur, s.AgentRayonSeparation, s.AgentRayonCohesion, s.AgentRayonVitesse, s.AgentMaxForce, vectors.Vector2D{X: 10, Y: 10}, make(map[*Bird]bool), make(map[*Bird]bool), make(map[*Bird]bool), 0, 1}
}
//Start fonction qui initialise l'agent
func (b *Bird) Start(window settings.Window) {
//Set agent default position randomly
x, y := rand.Float64()*window.Width, rand.Float64()*window.Height
b.position = vectors.Vector2D{X: x, Y: y}
//Set agent default speed randomly
t := rand.Float64()
var vx, vy float64
vx = 2
vy = 2
if t > 0.25 {
vx, vy = -2, -2
} else if t > 0.5 {
vx, vy = -2, 2
b.ty = 2
} else if t > 0.75 {
vx, vy = 2, -2
}
b.vitesse = vectors.Vector2D{X: float64(vx), Y: float64(vy)}
}
//ApplyForce applique une force sur l'agent
func (b *Bird) ApplyForce(force vectors.Vector2D) {
b.acceleration.X += force.X
b.acceleration.Y += force.Y
}
func (b *Bird) separate() (t vectors.Vector2D) {
steer := vectors.Vector2D{X: 0, Y: 0}
for bird := range b.separation {
steer.X = steer.X - bird.position.X
steer.Y = steer.Y - bird.position.Y
}
if len(b.separation) != 0 {
steer.X = steer.X / float64(len(b.separation))
steer.Y = steer.Y / float64(len(b.separation))
}
return steer
}
func (b *Bird) align() (t vectors.Vector2D) {
alignement := vectors.Vector2D{X: 0, Y: 0}
for bird := range b.alignement {
alignement.X = alignement.X + bird.vitesse.X
alignement.Y = alignement.Y + bird.vitesse.Y
}
if len(b.alignement) != 0 {
alignement.X = alignement.X / float64(len(b.alignement))
alignement.Y = alignement.Y / float64(len(b.alignement))
}
return alignement
}
func (b *Bird) cohesion() (t vectors.Vector2D) {
cohesion := vectors.Vector2D{X: 0, Y: 0}
for bird := range b.Cohesion {
cohesion.X = cohesion.X + bird.position.X
cohesion.Y = cohesion.Y + bird.position.Y
}
if len(b.Cohesion) != 0 {
cohesion.X = cohesion.X / float64(len(b.Cohesion))
cohesion.Y = cohesion.Y / float64(len(b.Cohesion))
}
return cohesion
}
func (b *Bird) random() (t vectors.Vector2D) {
r := vectors.Vector2D{X: 0, Y: 0}
u := rand.Float64()
if u < 0.1 {
r.X = rand.Float64() * 20
r.Y = rand.Float64() * 20
}
if u < 0.5 {
r.X = -r.X
r.Y = -r.Y
}
return r
}
func (b *Bird) limit() {
norme := math.Sqrt(math.Pow(b.vitesse.X, 2) + math.Pow(b.vitesse.Y, 2))
normeMax := math.Sqrt(math.Pow(b.maxSpeed.X, 2) + math.Pow(b.maxSpeed.Y, 2))
if norme >= normeMax {
if b.vitesse.X > 0 {
b.vitesse.X = b.maxSpeed.X / 2
} else {
b.vitesse.X = -(b.maxSpeed.X / 2)
}
if b.vitesse.Y > 0 {
b.vitesse.Y = b.maxSpeed.Y / 2
} else {
b.vitesse.Y = -(b.maxSpeed.Y / 2)
}
}
}
//Update fonction qui permet de mettre à jour le comportement de l'agent
func (b *Bird) Update(window settings.Window, birds []*Bird) {
b.getCouches(birds)
b.flock()
b.checkEdges(window)
b.updatePosition()
}
//getCouches fonction qui met à jour les couches de l'agents
func (b *Bird) getCouches(birds []*Bird) {
r := 0
for _, bird := range birds {
if bird.ty != b.ty && (math.Sqrt(math.Pow(b.position.X-bird.position.X, 2)+math.Pow(b.position.Y-bird.position.Y, 2))) <= 20 && b.ty == 1 && b.evitement != 2 {
b.evitement = 1
r = 1
}
if (math.Sqrt(math.Pow(b.position.X-bird.position.X, 2)+math.Pow(b.position.Y-bird.position.Y, 2))) < 20 && b.evitement == 2 && bird.ty != b.ty && b.ty == 1 {
r = 1
}
}
if r == 0 {
b.evitement = 0
}
// Couche separation, cohesion, alignement
for _, bird := range birds {
if bird.ty == b.ty && b.evitement == 0 {
if bird.ID == b.ID {
continue
}
distance := math.Sqrt(math.Pow(b.position.X-bird.position.X, 2) + math.Pow(b.position.Y-bird.position.Y, 2))
if distance <= b.rayonSeparation {
b.separation[bird] = true
b.alignement[bird] = true
b.Cohesion[bird] = true
//separation = append(separation, boid) // map plutot que tableau
} else if distance > b.rayonSeparation && distance <= b.rayonVitesse {
b.alignement[bird] = true
b.Cohesion[bird] = true
//alignement = append(alignement, boid)
} else if distance > b.rayonVitesse && distance <= b.rayonCohesion {
b.Cohesion[bird] = true
//cohesion = append(cohesion, boid)
}
}
}
}
//flock fonction
func (b *Bird) flock() {
if b.evitement == 1 {
b.vitesse.X = -b.vitesse.X
b.vitesse.Y = -b.vitesse.Y
b.evitement = 2
} else if b.evitement == 0 {
sep := b.separate()
ali := b.align()
coh := b.cohesion()
r := b.random()
b.ApplyForce(sep)
b.ApplyForce(ali)
b.ApplyForce(coh)
b.ApplyForce(r)
}
}
func (b *Bird) checkEdges(window settings.Window) {
if b.position.X < 0 {
b.position.X = 0
b.vitesse.X = -b.vitesse.X
} else if b.position.X > window.Width {
b.position.X = window.Width
b.vitesse.X = -b.vitesse.X
}
if b.position.Y < 0 {
b.position.Y = 0
b.vitesse.Y = -b.vitesse.Y
} else if b.position.Y > window.Height {
b.position.Y = window.Height
b.vitesse.Y = -b.vitesse.Y
}
}
//updatePosition fonction qui actualise la position de l'agent
func (b *Bird) updatePosition() {
b.vitesse.X += b.acceleration.X
b.vitesse.Y += b.acceleration.Y
b.limit()
b.position.X += b.vitesse.X
b.position.Y += b.vitesse.Y
b.acceleration.X = 0
b.acceleration.Y = 0
for k := range b.separation {
b.separation[k] = false
}
for k := range b.alignement {
b.alignement[k] = false
}
for k := range b.Cohesion {
b.Cohesion[k] = false
}
}
//Draw fonction permet d'afficher l'agent sur l'écran
func (b *Bird) Draw(screen *ebiten.Image, s settings.Settings) {
op := ebiten.DrawImageOptions{}
w, h := s.BirdImage.Size()
op.GeoM.Reset()
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Rotate(-1*math.Atan2(b.vitesse.Y*-1, b.vitesse.X) + math.Pi/2)
op.GeoM.Translate(b.position.X, b.position.Y)
switch b.ty {
case 2:
screen.DrawImage(s.BirdImage2, &op)
default: //1 inclus
screen.DrawImage(s.BirdImage, &op)
}
}
package game
import (
"image/color"
"sync"
ebiten "github.com/hajimehoshi/ebiten/v2"
agent "gitlab.utc.fr/jedescam/projet_ia04/final/agent"
settings "gitlab.utc.fr/jedescam/projet_ia04/final/settings"
worldelements "gitlab.utc.fr/jedescam/projet_ia04/final/worldelements"
)
//Game type regroupe tous les états du monde
type Game struct {
birds []*agent.Bird
settings settings.Settings
window settings.Window
worldMap worldelements.Map
}
//NewGame fonction constructeur de Game, regroupe tous les états du monde
func NewGame() *Game {
g := &Game{}
//Initialize settings
g.settings = settings.GetDefaultSettings()
g.window = settings.GetWindowDefault()
//Create birds
g.birds = make([]*agent.Bird, g.settings.AgentsNum)
for i := 0; i < len(g.birds); i++ {
g.birds[i] = agent.NewBird(g.settings, i)
}
//Initialize birds
var wg sync.WaitGroup
wg.Add(g.settings.AgentsNum)
for i := 0; i < g.settings.AgentsNum; i++ {
go func(i int) {
g.birds[i].Start(g.window)
wg.Done()
}(i)
}
wg.Wait()
return g
}
//Update fonction appelée lorsque l'état du monde est mis à jour
func (g *Game) Update() error {
//Update birds
var wg sync.WaitGroup
wg.Add(g.settings.AgentsNum)
for i := 0; i < g.settings.AgentsNum; i++ {
go func(i int) {
g.birds[i].Update(g.window, g.birds)
wg.Done()
}(i)
}
wg.Wait()
return nil
}
//Draw fonction permet d'afficher le monde en déléguant l'affichage aux éléments inclus dans le monde
func (g *Game) Draw(screen *ebiten.Image) {
//Draw background
screen.Fill(color.White)
//Draw agents
for i := 0; i < g.settings.AgentsNum; i++ {
g.birds[i].Draw(screen, g.settings)
}
//Draw world elements
}
//Layout fonction permet de définir la taille de la fenêtre d'affichage
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
return int(g.window.Width), int(g.window.Height)
}
module gitlab.utc.fr/jedescam/projet_ia04/final
go 1.17
require (
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210727001814-0db043d8d5be // indirect
github.com/hajimehoshi/ebiten/v2 v2.2.3 // indirect
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240 // indirect
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
golang.org/x/mobile v0.0.0-20210902104108-5d9a33257ab5 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678 // indirect
)
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210727001814-0db043d8d5be h1:vEIVIuBApEBQTEJt19GfhoU+zFSV+sNTa9E9FdnRYfk=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210727001814-0db043d8d5be/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/hajimehoshi/bitmapfont/v2 v2.1.3/go.mod h1:2BnYrkTQGThpr/CY6LorYtt/zEPNzvE/ND69CRTaHMs=
github.com/hajimehoshi/ebiten/v2 v2.2.3 h1:jZUP3XWP6mXaw9SCrjWT5Pl6EPuz6FY737dZQgN1KJ4=
github.com/hajimehoshi/ebiten/v2 v2.2.3/go.mod h1:olKl/qqhMBBAm2oI7Zy292nCtE+nitlmYKNF3UpbFn0=
github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41/go.mod h1:CqqAHp7Dk/AqQiwuhV1yT2334qbA/tFWQW0MD2dGqUE=
github.com/hajimehoshi/go-mp3 v0.3.2/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.2/go.mod h1:rUKQmwMkqmRxe+IAof9+tuYA2ofm8cAWXFmSfzDN8vQ=
github.com/jakecoffman/cp v1.1.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240 h1:dy+DS31tGEGCsZzB45HmJJNHjur8GDgtRNX9U7HnSX4=
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240/go.mod h1:3P4UH/k22rXyHIJD2w4h2XMqPX4Of/eySEZq9L6wqc4=
github.com/jfreymuth/oggvorbis v1.0.3/go.mod h1:1U4pqWmghcoVsCJJ4fRBKv9peUJMBHixthRlBeD6uII=
github.com/jfreymuth/vorbis v1.0.2/go.mod h1:DoftRo4AznKnShRl1GxiTFCseHr4zR9BN3TWXyuzrqQ=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190703141733-d6a02ce849c9/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mobile v0.0.0-20210902104108-5d9a33257ab5 h1:peBP2oZO/xVnGMaWMCyFEI0WENsGj71wx5K12mRELHQ=
golang.org/x/mobile v0.0.0-20210902104108-5d9a33257ab5/go.mod h1:c4YKU3ZylDmvbw+H/PSvm42vhdWbuxCzbonauEAP9B8=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678 h1:J27LZFQBFoihqXoegpscI10HpjZ7B5WQLLKL2FZXQKw=
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.6/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
package main
import (
"fmt"
"log"
ebiten "github.com/hajimehoshi/ebiten/v2"
game "gitlab.utc.fr/jedescam/projet_ia04/final/game"
settings "gitlab.utc.fr/jedescam/projet_ia04/final/settings"
)
func main() {
fmt.Println("Start of the program")
ebiten.SetWindowSize(int(settings.GetWindowDefault().Width), int(settings.GetWindowDefault().Height))
ebiten.SetWindowTitle("Final Project IA04")
if err := ebiten.RunGame(game.NewGame()); err != nil {
log.Fatal(err)
}
}
package settings
import (
"log"
_ "image/png" //sinon ça fait une erreur quand on load l'image
ebiten "github.com/hajimehoshi/ebiten/v2"
ebitenutil "github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
//Settings type regroupe les paramêtres globaux de la simulation
type Settings struct {
AgentsNum int
AgentLongueur float64
AgentRayonSeparation float64
AgentRayonCohesion float64
AgentRayonVitesse float64
AgentMaxForce float64
BirdImage *ebiten.Image
BirdImage2 *ebiten.Image
}
//GetDefaultSettings fonction qui renvoie les paramêtres globaux par défaut de la simulation
func GetDefaultSettings() Settings {
bImg, _, err := ebitenutil.NewImageFromFile("t2.png")
bImg2, _, err := ebitenutil.NewImageFromFile("t3.png")
if err != nil {
log.Fatal(err)
}
return Settings{100, 5, 32, 30, 27, 30, bImg, bImg2}
}
package settings
//Window type
type Window struct {
Width float64
Height float64
}
//Window size
func GetWindowDefault() Window {
//return Window{1280, 720} //HD resolution
return Window{1600, 900} //HD+ resolution
//return Window{1920, 1080}//Full HD resolution
}
package vectors
import "math"
//Vector2D type permet de définir un vecteur
type Vector2D struct {
X float64
Y float64
}
//Add fonction permet d'ajouter un vecteur au vecteur
func (v *Vector2D) Add(v2 Vector2D) {
v.X += v2.X
v.Y += v2.Y
}
//Substract fonction permet de soustraire un vecteur au vecteur
func (v *Vector2D) Substract(v2 Vector2D) {
v.X -= v2.X
v.Y -= v2.Y
}
func (v *Vector2D) Limit(max float64) {
magSq := v.MagnitudeSquared()
if magSq > max*max {
v.Divide(math.Sqrt(magSq))
v.Multiply(max)
}
}
func (v *Vector2D) Normalize() {
mag := math.Sqrt(v.X*v.X + v.Y*v.Y)
v.X /= mag
v.Y /= mag
}
func (v *Vector2D) SetMagnitude(z float64) {
v.Normalize()
v.X *= z
v.Y *= z
}
func (v *Vector2D) MagnitudeSquared() float64 {
return v.X*v.X + v.Y*v.Y
}
func (v *Vector2D) Divide(z float64) {
v.X /= z
v.Y /= z
}
func (v *Vector2D) Multiply(z float64) {
v.X *= z
v.Y *= z
}
//Distance fonction permet de calculer la distance entre le vecteur et un autre vecteur
func (v Vector2D) Distance(v2 Vector2D) float64 {
return math.Sqrt(math.Pow(v2.X-v.X, 2) + math.Pow(v2.Y-v.Y, 2))
}
package worldelements
//Map type [coord x][coord y][mask] = value
type Map [][][]float64
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment