Commit 939faf4a authored by Léo TRANCHET's avatar Léo TRANCHET
Browse files

modivication de la fonction Nettoyage

parent d173bfbc
......@@ -4,14 +4,13 @@
"WindowSizeY": 600,
"ParticleImage": "assets/particle.png",
"Debug": true,
"InitNumParticles": 10,
"InitNumParticles": 100000,
"RandomSpawn": true,
"SpawnX": 400,
"SpawnY": 400,
"SpawnRate": 0,
"SpeedLimit": [0,0,0,0],
"Colors": [1,1,1,1,1,1],
"SpeedLimit": [-1,1,-1,1],
"Colors": [0,1,0,1,0,1],
"Gravity": false,
"GravityCenter": false,
// "LifeCycle": 0
"GravityCenter": false
}
\ No newline at end of file
......@@ -15,12 +15,16 @@ import (
func (g *game) Draw(screen *ebiten.Image) {
for _, p := range g.system.Content {
options := ebiten.DrawImageOptions{}
options.GeoM.Rotate(p.Rotation)
options.GeoM.Scale(p.ScaleX, p.ScaleY)
options.GeoM.Translate(p.PositionX, p.PositionY)
options.ColorM.Scale(p.ColorRed, p.ColorGreen, p.ColorBlue, p.Opacity)
screen.DrawImage(assets.ParticleImage, &options)
if p.Overflow{
continue
}else{
options := ebiten.DrawImageOptions{}
options.GeoM.Rotate(p.Rotation)
options.GeoM.Scale(p.ScaleX, p.ScaleY)
options.GeoM.Translate(p.PositionX, p.PositionY)
options.ColorM.Scale(p.ColorRed, p.ColorGreen, p.ColorBlue, p.Opacity)
screen.DrawImage(assets.ParticleImage, &options)
}
}
if config.General.Debug {
......
......@@ -30,6 +30,7 @@ func GenPart() (Particle) { // Crée une particule avec Px,Py comme position
Opacity: 1,
SpeedX: config.General.SpeedLimit[0] + rand.Float64()* (config.General.SpeedLimit[1]-config.General.SpeedLimit[0]),
SpeedY: config.General.SpeedLimit[2] + rand.Float64()* (config.General.SpeedLimit[3]-config.General.SpeedLimit[2]),
Overflow: false,
}
}
......
......@@ -22,4 +22,5 @@ type Particle struct {
SpeedX,SpeedY float64
Gravity bool
GravityCenter bool
Overflow bool
}
......@@ -8,13 +8,10 @@ import "project-particles/config"
// projet.
// C'est à vous de développer cette fonction.
func Nettoyage(tab []*Particle) ([]*Particle){
maxi := float64(config.General.WindowSizeX)
mini := float64(config.General.WindowSizeY)
func Nettoyage(tab []Particle) ([]Particle){
for i:=0; i< len(tab); i++{
if tab[i].PositionX > maxi|| tab[i].PositionX < 0 || tab[i].PositionY > mini || tab[i].PositionY < -10{
tab = append(tab[:i], tab[i+1:]...)
i = i -1
if int(tab[i].PositionX) > config.General.WindowSizeX || int(tab[i].PositionX) < 100 || int(tab[i].PositionY) > config.General.WindowSizeY || int(tab[i].PositionY) < -10{
tab[i].Overflow = true
}
}
return tab
......@@ -94,15 +91,7 @@ func spirale(p Particle) (Particle){
func (s *System) Update() {
var tabPointeursParticle []*Particle
for i:=0; i<len(s.Content); i++{
tabPointeursParticle = append(tabPointeursParticle, &s.Content[i])
}
tabPointeursParticle = Nettoyage(tabPointeursParticle)
s.Content = []Particle{}
for i:=0; i<len(tabPointeursParticle); i++{
s.Content = append(s.Content, *tabPointeursParticle[i])
}
s.Content = Nettoyage(s.Content)
for i:=0; i < len(s.Content); i++ {
s.Content[i].PositionX += s.Content[i].SpeedX
......@@ -115,10 +104,10 @@ func (s *System) Update() {
}
}
NbSpaw := config.General.SpawnRate + s.SpawBuffer
for i:=0; i < int(NbSpaw); i++ {
NbSpawn := config.General.SpawnRate + s.SpawBuffer
for i:=0; i < int(NbSpawn); i++ {
s.Content = append(s.Content,GenPart())
}
s.SpawBuffer = NbSpaw - float64(int(NbSpaw))
s.SpawBuffer = NbSpawn - float64(int(NbSpawn))
}
\ No newline at end of file
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