Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 9ba4d8aa rédigé par Camille MOREAU's avatar Camille MOREAU
Parcourir les fichiers

coucu

parent
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!1coucu
package assets
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
_ "image/png"
"log"
"project-particles/config"
)
// ParticleImage est une variable globale pour stocker l'image d'une particule
var ParticleImage *ebiten.Image
// Get charge en mémoire l'image de la particule. (particle.png)
// Vous pouvez changer cette image si vous le souhaitez, et même en proposer
// plusieurs, qu'on peut choisir via le fichier de configuration. Cependant
// ceci n'est pas du tout central dans le projet et ne devrait être fait que
// si vous avez déjà bien avancé sur tout le reste.
func Get() {
var err error
ParticleImage, _, err = ebitenutil.NewImageFromFile(config.General.ParticleImage)
if err != nil {
log.Fatal("Problem while loading particle image: ", err)
}
}
assets/particle.png

11,3 ko

{
"WindowTitle": "Project particles",
"WindowSizeX": 1920,
"WindowSizeY": 1080,
"ParticleImage": "assets/particle.png",
"Debug": true,
"InitNumParticles": 10,
"RandomSpawn": false,
"SpawnX": 900,
"SpawnY": 520,
"SpawnRate": 5,
"Vitesse": 10,
"Gravite":true,
"VitesseGravY":0.02,
"VitesseGravX":0.005,
"Explosion":true
}
package config
import (
"encoding/json"
"io/ioutil"
"log"
)
// Get récupère le contenu du fichier config.json et le stocke dans la variable
// General du package config. Normalement vous ne devriez jamais modifier cette
// fonction.
func Get(fileName string) {
content, err := ioutil.ReadFile(fileName)
if err != nil {
log.Fatal("Error when opening config file: ", err)
}
err = json.Unmarshal(content, &General)
if err != nil {
log.Fatal("Error when reading config file: ", err)
}
}
package config
// Config définit les champs qu'on peut trouver dans un fichier de config.
// Dans le fichier les champs doivent porter le même nom que dans le type si
// dessous, y compris les majuscules. Tous les champs doivent obligatoirement
// commencer par des majuscules, sinon il ne sera pas possible de récupérer
// leurs valeurs depuis le fichier de config.
// Vous pouvez ajouter des champs et ils seront automatiquement lus dans le
// fichier de config. Vous devrez le faire plusieurs fois durant le projet.
type Config struct {
WindowTitle string
WindowSizeX, WindowSizeY int
ParticleImage string
Debug bool
InitNumParticles int
RandomSpawn bool
SpawnX, SpawnY int
SpawnRate float64
Vitesse float64
Gravite bool
VitesseGravY float64
VitesseGravX float64
Explosion bool
}
var General Config
package main
import (
"fmt"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"project-particles/assets"
"project-particles/config"
)
// Draw se charge d'afficher à l'écran l'état actuel du système de particules
// g.system. Elle est appelée automatiquement environ 60 fois par seconde par
// la bibliothèque Ebiten. Cette fonction pourra être légèrement modifiée quand
// c'est précisé dans le sujet.
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 config.General.Debug {
ebitenutil.DebugPrint(screen, fmt.Sprint(ebiten.CurrentTPS()))
}
}
package main
import "project-particles/particles"
// game est un type qui implémente l'interface Game de la bibliothèque Ebiten
// car il dispose d'une méthode Update, d'une méthode Draw et d'une méthode
// Layout. C'est un élément de ce type qui est utilisé pour mettre à jour et
// afficher un système de particules. Ce type ne devrait pas être modifié sauf
// pour les deux dernières extensions.
type game struct {
system particles.System
}
module project-particles
go 1.15
require (
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210727001814-0db043d8d5be // indirect
github.com/hajimehoshi/ebiten/v2 v2.2.2
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.2 h1:92E+ogdNyH1P/LlvMQ7vonbFDh6bl+O7Ak+H1HX0RX8=
github.com/hajimehoshi/ebiten/v2 v2.2.2/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
// Layout définit la taille en pixels de la zone d'affichage des particules
// en fonction de la taille en pixels de la fenêtre. Vous n'avez jamais à
// modifier cette fonction.
func (g *game) Layout(outsideWidth, outsideHeight int) (int, int) {
return outsideWidth, outsideHeight
}
package main
import (
"github.com/hajimehoshi/ebiten/v2"
"log"
"project-particles/assets"
"project-particles/config"
"project-particles/particles"
"math/rand"
"time"
)
// main est la fonction principale du projet. Elle commence par lire le fichier
// de configuration, puis elle charge en mémoire l'image d'une particule. Elle
// initialise ensuite la fenêtre d'affichage, puis elle crée un système de
// particules encapsulé dans un "game" et appelle la fonction RunGame qui se
// charge de faire les mise-à-jour (Update) et affichages (Draw) de manière
// régulière.
func main() {
rand.Seed(time.Now().UnixNano())
config.Get("config.json")
assets.Get()
ebiten.SetWindowTitle(config.General.WindowTitle)
ebiten.SetWindowSize(config.General.WindowSizeX, config.General.WindowSizeY)
g := game{system: particles.NewSystem()}
err := ebiten.RunGame(&g)
if err != nil {
log.Print(err)
}
}
package particles
import (
"project-particles/config"
"math/rand"
)
// NewSystem est une fonction qui initialise un système de particules et le
// retourne à la fonction principale du projet, qui se chargera de l'afficher.
// C'est à vous de développer cette fonction.
// Dans sa version actuelle, cette fonction affiche une particule blanche au
// centre de l'écran.
// Fonction qui crée un nombre random parmis une valeur entre un minimum et un maximum
func RandomNum(min, max float64) float64{
return min + rand.Float64() * (max-min)
}
// Fonction qui crée une particule
func CreatePart(position_x, position_y, vitesse float64) Particle{
return Particle {
PositionX: position_x,
PositionY: position_y,
ScaleX: 1, ScaleY: 1,
ColorRed: RandomNum(0,1), ColorGreen: RandomNum(0,0), ColorBlue: RandomNum(0,1),
Opacity:RandomNum(0.5,1),
VitesseX: RandomNum(-vitesse, vitesse),
VitesseY: RandomNum(-vitesse, vitesse),
}
}
func NewSystem() System {
// Récupération des valeurs situées dans 'config.json'
NbParticules := config.General.InitNumParticles // 10
ScreenX := config.General.WindowSizeX // taille : 800
ScreenY := config.General.WindowSizeY // taille : 600
random := config.General.RandomSpawn
// Création d'un tableau 'tabPart' accueillant les particules et d'une particule 'P'
var tabPart []Particle = []Particle{}
var P Particle
var position_x float64
var position_y float64
var vitesse float64 = config.General.Vitesse
// Boucle permettant l'ajout des particules 'P' créées dans notre tableau 'tabPart'
for i := 1; i<= NbParticules; i++{
if random {
position_x = rand.Float64() * float64(ScreenX)
position_y = rand.Float64() * float64(ScreenY)
} else {
position_x = float64(config.General.SpawnX)
position_y = float64(config.General.SpawnY)
}
P = CreatePart(position_x, position_y, vitesse)
tabPart = append(tabPart,P)
}
return System{Content: tabPart}
}
package particles
import (
"project-particles/config"
"testing"
)
// Fonction qui vérifie si une particule est en mouvement
func TestCreatePart1(t *testing.T) {
// Récupère les valeurs du fichier config.json
config.Get("../config.json")
config.General.SpawnX = 900
config.General.SpawnY = 520
config.General.InitNumParticles = 1
// Initailise un nouveau système
T:=NewSystem()
OriginalPosX:= T.Content[0].PositionX
OriginalPosY:= T.Content[0].PositionY
// On rajoute des particules dans notre tableau de particules pour 1 seconde.
for j:=0; j<1; j++{
T.Update()
}
if T.Content[0].PositionX == OriginalPosX || T.Content[0].PositionY == OriginalPosY {
t.Fail()
}
}
func TestCreatePart2(t *testing.T) {
// Récupère les valeurs du fichier config.json
config.Get("../config.json")
config.General.SpawnX = 600
config.General.SpawnY = 400
config.General.InitNumParticles = 1
// Initailise un nouveau système
T:=NewSystem()
OriginalPosX:= T.Content[0].PositionX
OriginalPosY:= T.Content[0].PositionY
// On rajoute une particule dans notre tableau de particules pour 1 seconde.
for j:=0; j<1; j++{
T.Update()
}
if T.Content[0].PositionX == OriginalPosX || T.Content[0].PositionY == OriginalPosY {
t.Fail()
}
}
// Fonction qui vérifie si le nombre de particules voulues sont bien créent
func TestSpawnRateEntier(t *testing.T) {
// Récupère les valeurs du fichier config.json
config.Get("../config.json")
config.General.InitNumParticles = 0
config.General.SpawnRate = 3
// Initailise un nouveau système
T := NewSystem()
// On rajoute des particules dans notre tableau de particules pour 1 seconde.
for i:=0; i<60; i++ {
T.Update()
}
// On vérifie que la taille du tableau de particules est bien égale à InitParticules plus le nombre dans SpawnRate multiplié par le tour de boucle, soit 60.
if len(T.Content) != 180{
t.Fail()
}
}
func TestSpawnRateDecimal1(t *testing.T) {
// Récupère les valeurs du fichier config.json
config.Get("../config.json")
config.General.InitNumParticles = 5
config.General.SpawnRate = 0.5
// Initailise un nouveau système
T := NewSystem()
// On rajoute des particules dans notre tableau de particules pour 1 seconde.
for i:=0; i<60; i++ {
T.Update()
}
// On vérifie que la taille du tableau de particules est bien égale à InitParticules plus le nombre dans SpawnRate multiplié par le tour de boucle, soit 35.
if len(T.Content) != 35 {
t.Fail()
}
}
func TestSpawnRateDecimal2(t *testing.T) {
// Récupère les valeurs du fichier config.json
config.Get("../config.json")
config.General.InitNumParticles = 0
config.General.SpawnRate = 0.01666667
// Initailise un nouveau système
T := NewSystem()
// On rajoute des particules dans notre tableau de particules pour 1 seconde.
for i:=0; i<60; i++ {
T.Update()
}
// On vérifie que la taille du tableau de particules est bien égale à InitParticules plus le nombre dans SpawnRate multiplié par le tour de boucle, soit 1.
if len(T.Content) != 1 {
t.Fail()
}
}
package particles
// System définit un système de particules.
// Pour le moment il ne contient qu'un tableau de particules, mais cela peut
// évoluer durant votre projet.
type System struct {
Content []Particle
}
// Particle définit une particule.
// Elle possède une position, une rotation, une taille, une couleur, et une
// opacité. Vous ajouterez certainement d'autres caractéristiques aux particules
// durant le projet.
type Particle struct {
PositionX, PositionY float64
Rotation float64
ScaleX, ScaleY float64
ColorRed, ColorGreen, ColorBlue float64
Opacity float64
VitesseX, VitesseY float64
}
package particles
import(
"project-particles/config"
"math/rand"
)
// Update mets à jour l'état du système de particules (c'est-à-dire l'état de
// chacune des particules) à chaque pas de temps. Elle est appellée exactement
// 60 fois par seconde (de manière régulière) par la fonction principale du
// projet.
// C'est à vous de développer cette fonction.
func Gravite(s *System, i int, vitesseGravY float64, vitesseGravX float64){
s.Content[i].VitesseY+=vitesseGravY
if s.Content[i].VitesseX>0 {
s.Content[i].VitesseX-=vitesseGravX
} else {
s.Content[i].VitesseX+=vitesseGravX
}
}
func Explosion(s *System){
config.Get("../config.json")
config.General.SpawnRate = 0
config.General.RandomSpawn = false
postmpx := RandomNum(0, float64(config.General.WindowSizeX))
postmpy := RandomNum(0, float64(config.General.WindowSizeY))
nbrandom := RandomNum(float64(config.General.InitNumParticles),float64(config.General.InitNumParticles+15))
var i float64
for i=0; i<nbrandom; i++{
P := CreatePart(postmpx,postmpy,config.General.Vitesse)
s.Content = append(s.Content,P)
}
}
var generation float64 = 0.0
func (s *System) Update() {
// Récupération des valeurs situées dans 'config.json'
ScreenX := config.General.WindowSizeX // taille : 800
ScreenY := config.General.WindowSizeY // taille : 600
random := config.General.RandomSpawn
gravite := config.General.Gravite
VitesseGravY := config.General.VitesseGravY
VitesseGravX := config.General.VitesseGravX
Explosion := config.General.Explosion
SpawnRate := config.General.SpawnRate
// Création des variables demandées dans la création d'une particule
var position_x float64
var position_y float64
var vitesse float64 = config.General.Vitesse
var P Particle
// Boucle permettant de changer la position des particules au cours du temps
for i:=0; i<len(s.Content); i++ {
s.Content[i].PositionX += s.Content[i].VitesseX
s.Content[i].PositionY += s.Content[i].VitesseY
if gravite {
Gravite(s,i,VitesseGravY,VitesseGravX)
}
}
// Boucle créant des particules en fonctions des paramètres au-dessus (config.json)
if Explosion {
}
generation += SpawnRate
for generation >= 1 {
if random {
position_x = rand.Float64() * float64(ScreenX)
position_y = rand.Float64() * float64(ScreenY)
} else {
position_x = float64(config.General.SpawnX)
position_y = float64(config.General.SpawnY)
}
P = CreatePart(position_x,position_y,vitesse)
s.Content = append(s.Content,P)
generation-=1
}
}
Fichier ajouté
package main
// Update se charge d'appeler la fonction Update du système de particules
// g.system. Elle est appelée automatiquement exactement 60 fois par seconde par
// la bibliothèque Ebiten. Cette fonction ne devrait pas être modifiée sauf
// pour les deux dernières extensions.
func (g *game) Update() error {
g.system.Update()
return nil
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter