Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Atelier] Fond animé Space Invaders

Venez vous entraîner avec le langage de votre choix :)

Anonyme
    3 mai 2013 à 13:30:54

    Est-ce que ma participation en Pseudo-C est valide, car ce n'est pas un langage de programmation officiel ?
    • Partager sur Facebook
    • Partager sur Twitter
      3 mai 2013 à 13:36:05

      La version que vous attendiez (presque) tous : Minecraft !


      Miniatures (Cliquez pour la taille réelle) : Miniature Miniature


      Map : https://mega.co.nz/#!s54BgbZJ!ChrjqwVbhKh3zIF5MjZC8B-PXBZdFqmKBXldwDfIfAA Pack de texture "oCd by Disco (c)" édité : https://mega.co.nz/#!Y0g0BBYC!HpBEiCT7jXPyvD1cH-OvY1g0ZyUrDHovknEhd3xkbOE

      • Partager sur Facebook
      • Partager sur Twitter
        3 mai 2013 à 13:55:39

        Ah ah, énorme ! Fallait y penser !

        Maintenant, faut le faire avec des bloc de commandes :p

        Voilà un programme en AutoIt qui vous ouvre paint, et vous dessine plein de space invaders !

        Je suppose que ce programme ne marche que sur windows 7 ! Les «touches» ne sont pas au même endroit.

        De plus, je n'ai pas trouver un moyen simple d'ouvrir paint, donc j'ai donné le chemin d'accès, je ne sais pas si c'est possible, mais il pourrait être installer à un autre endroit, il vous suffirait de modifier la ligne 43.

        ------------------------------------------------------

        Global $pos[2]
        Global $taille = 10
        Global $space[26][2] = [[0,0],[0,$taille],[$taille,$taille],[$taille,2*$taille],[$taille,3*$taille],[$taille,4*$taille],[2*$taille,0],[2*$taille,$taille],[2*$taille,4* $taille],[2*$taille,5*$taille],[3*$taille,$taille],[3*$taille,2*$taille],[3* $taille,3*$taille],[3*$taille,4*$taille],[ 4*$taille,0], [4*$taille, $taille],[4*$taille ,4*$taille],[4*$taille,5 *$taille],[5*$taille ,$taille],[5*$taille,2* $taille], [5*$taille,3*$taille],[5*$taille,4*$taille],[6 *$taille,0],[6*$taille,$taille],[2* $taille,2*$taille],[4*$taille, 2*$taille]]
        Global $i
        Global $y
        Global $oeil

        func Quitter()
            Exit
        EndFunc

        Func dessin()
            $pos[0] = int (Random(83,1164))
            $pos[1] = int (Random(211,798))

            for $i=0 to 23
                for $y = 0 to 6 step + 2
                    MouseClickDrag("left", $pos[0] - $space[$i][0],$pos[1] - $space[$i][1] - $y,$pos[0] - $space[$i][0] - 6,$pos[1] - $space[$i][1] - $y, 0)
                Next
            Next

            for $i=24 to 25
                $oeil = int (Random(0,2))
                for $y = 0 to 6 step + 2
                    MouseClickDrag("right", $pos[0] - $space[$i][0],$pos[1] - $space[$i][1] - $y - $oeil * 10,$pos[0] - $space[$i][0] - 6,$pos[1] - $space[$i][1] - $y - $oeil * 10, 0)
                Next
            Next

        EndFunc

        func changercouleur()

            mouseclick("left", 1128,82,1,0)
            Sleep(100)
            mouseclick("left", 801,387,1,0)
            Sleep(100)
            mouseclick("left", int (Random(606,777)),int (Random(292,477)),1,0)
            Sleep(100)
            mouseclick("left", 411,562,1,0)

        endfunc

        Run("C:\Windows\system32\mspaint.exe")
        WinWait("Paint")
        WinMove("Paint", "",0,0,1300,1500,1)

        mouseclick("left", 854,85,1,0)
        mouseclick("left", 888,68,1,0)
        mouseclick("left", 808,81,1,0)

        HotKeySet("{ESC}", "Quitter")
        while (1)
            changercouleur()
            dessin()
        WEnd

        ------------------------------------------------------

        Désolé, c'est moche, mais je ne sais pas trop quel langage de programmation s’approche de la syntaxe de l'AutoIt. Et, le programme met pas mal de temps à dessiner, en tout cas chez moi.

        Le simple fait d'appuyer sur échap ferme le programme.

        Le lien de téléchargement de l'exe ici

        Sinon, je voudrais bien voir un p'tit programme en UnrealScript :p


        -
        Edité par BlackFart 3 mai 2013 à 15:31:40

        • Partager sur Facebook
        • Partager sur Twitter
          3 mai 2013 à 17:39:05

          J'y est mis du temps mais je vient de faire une version en java-script. Comme le programme fait 1 Mo je l'ai mit ici. Le refresh ce fait toutes les 15s car les calculs sont super lourds.

          Voici quand même un extrait de code ^^
          this[(!!+[]+[])[(~+[]+~+[])*~+[]]+(+[][+[]]+[])[~+[]*~+[]]+this[([][+[]]+[])[(~+[]+~+[
          ]+~+[]+~+[]+~+[])*~+[]]+([][+[]]+[])[~+[]*~+[]]+([][+[]]+[])[~+[]*~+[]]+(!!+[]+[])[(~+
          []+~+[]+~+[]+~+[])*~+[]]+(!+[]+[])[~+[]*~+[]]+
          (this+[])[~+[]*~+[]<<(~+[]+~+[]+~+[])*~+[]]+(this+[])[(~+[]*~+[]<<(~+[]+~+[]+~+[])*~+[
          ])+~+[]*~+[]]+(this+[])[(~+[]+~+[]+~+[]+~+[]+~+[])*~+[]*(~+[]+~+[])*~+[]]+(this+[])[(~
          +[]*~+[]<<(~+[]+~+[]+~+[])*~+[])+(~+[]+~+[]+~+
          [])*~+[]]][~+[]*~+[]]+(!+[]+[])[+[]]+

          Une version plus légère et permettant de comprendre (un peu) comment ça fonctionne. Il y a des notes en bas et en haut.

          -
          Edité par jo_link_noir 3 mai 2013 à 17:44:23

          • Partager sur Facebook
          • Partager sur Twitter
            3 mai 2013 à 18:29:10

            J'dois avouer que c'est une obfucation originale :)

            • Partager sur Facebook
            • Partager sur Twitter
              3 mai 2013 à 18:32:12

              @geeex : comment as tu fait le fond, ça n' a pas l'air d'un bloc normal.

              J'ai aussi tenté de faire quelque chose, mais je suis partit dans un truc vraiment plus compliqué que toi ^^

              Je vais essayer de faire une version LabView, ça fait plus d'un an que je n'ai pas pratiqué ^^

              • Partager sur Facebook
              • Partager sur Twitter
              "Tout devrait être rendu aussi simple que possible, mais pas plus." A.Einstein
                3 mai 2013 à 18:36:58

                C'est de l'eau. C'est pour ça qu'il y a le pack de texture.

                • Partager sur Facebook
                • Partager sur Twitter
                  4 mai 2013 à 0:08:20

                  Et voici ma version Labview !

                  Le rendu :

                  Et voici le "code source" .... ou plutôt blocs source

                  Pour ceux que ça intéresse, voici l’exécutable (il faut labview pour le lancer)

                  https://dl.dropboxusercontent.com/u/77857161/space.vi

                  @geeex : Je trouve que c'est un peut tricher de changer la couleur de l'eau ^^

                  Mais bien trouvé

                  -
                  Edité par n!co69 4 mai 2013 à 0:09:00

                  • Partager sur Facebook
                  • Partager sur Twitter
                  "Tout devrait être rendu aussi simple que possible, mais pas plus." A.Einstein
                  Anonyme
                    4 mai 2013 à 9:02:31

                    Salut, super ce petit défi ! Je n'ai pas lu toutes les réponses du post mais j'aimerais savoir si il y avait un moyen de le faire entièrement en HTML/CSS ? Merci !
                    • Partager sur Facebook
                    • Partager sur Twitter
                      4 mai 2013 à 9:27:36

                      @Wizix: Regarde les derniers posts de la page 1

                      • Partager sur Facebook
                      • Partager sur Twitter

                      🍊 - Étudiant - Codeur en C | Zeste de Savoir apprenez avec une communauté | Articles  - ♡ Copying is an act of love.

                      Anonyme
                        4 mai 2013 à 9:40:11

                        @@che: Merci, j'aurais jamais pensé à utiliser un tableau ! Merci beaucoup et au boulot ! :)
                        • Partager sur Facebook
                        • Partager sur Twitter
                          4 mai 2013 à 12:28:00

                          Au passage, ça peut sembler long 8 pages mais il n'y a pas trop de flood inutile. Donc si tu les lis tu verras pleins de façon de faire différentes en plein de langages. C'est tres sympa pour l'apprentissage !

                          Surtout si tu es dev web, des version web il y en a eu sur toutes les pages ou presques !

                          • Partager sur Facebook
                          • Partager sur Twitter
                            4 mai 2013 à 16:24:29

                            Si jamais quelqu'un m'indique comment faire pour faire des appels systèmes en BrainFuck je veux bien améliorer ma version statique toute moche ;)
                            • Partager sur Facebook
                            • Partager sur Twitter

                            Retrouvez moi sur mon blog et ma chaine Youtube !

                              4 mai 2013 à 16:27:21

                              Voici ma version fait en C++/Qt avec utilisation de bibliothèque du langage C :

                              #include <QLabel>
                              #include <QPainter>
                              #include <QApplication>
                              #include <QTimer>
                              #include <ctime>
                              class SpaceInvader : public QLabel
                              {
                              public:
                                  SpaceInvader();
                                  ~SpaceInvader() { delete timer; }
                              private:
                                  void paintEvent(QPaintEvent *);
                                  QTimer *timer;
                              };
                              
                              SpaceInvader::SpaceInvader()
                              {
                                  timer = new QTimer(this);
                                  timer->start(3000);
                                  connect(timer, SIGNAL(timeout()), this, SLOT(update()));
                              }
                              void SpaceInvader::paintEvent(QPaintEvent *)
                              {
                                  srand(time(0));
                                  int r = rand() % 254, g = rand() % 254, b = rand() % 254, x, y, width = size().width(), height = size().height();
                                  do
                                  {
                                       x = rand() % (width - 1);
                                       y = rand() % (height - 1);
                                  }while( (x + 390) > width || (y + 55) > height || (y - 335) < 0 || x < 0);
                                  QPainter painter(this);
                                  painter.setBrush(QColor(r, g, b));
                                  for(int i = 0; i < 7; ++i)
                                  {
                                      if(i % 2 != 1)
                                          painter.drawRect((x + (i * 55)), y, 50, 50);
                                      painter.drawRect((x + (i * 55)), (y-55), 50, 50);
                                      if(i % 2 != 0)
                                      {
                                          painter.drawRect((x + (i * 55)), (y-110), 50, 50);
                                          painter.drawRect((x + (i * 55)), (y - 165), 50, 50);
                                      }
                                      if(i != 0 && i != 6)
                                          painter.drawRect((x + (i * 55)), (y - 220), 50, 50);
                                      if(i == 2 || i == 4)
                                          painter.drawRect((x + (i * 55)), (y - 275), 50, 50);
                                  }
                                  painter.setBrush(Qt::black);
                                  painter.drawRect((x + (2 * 55)), (y - (110 + ((rand() % 2) * 55))), 50, 50);
                                  painter.drawRect((x + (4 * 55)), (y - (110 + ((rand() % 2) * 55))), 50, 50);
                                  painter.end();
                              }
                              int main(int argc, char* argv[])
                              {
                                  QApplication app(argc, argv);
                                  SpaceInvader invader;
                                  invader.showMaximized();
                                  invader.setFixedSize(invader.size());
                                  return app.exec();
                              }

                              couleur aléatoire, position des yeux aléatoire et le déplacement aléatoire dans une fenêtre en taille maximum ! :D

                              edit : réduction du code.

                              -
                              Edité par keke222 4 mai 2013 à 16:58:45

                              • Partager sur Facebook
                              • Partager sur Twitter
                              Anonyme
                                4 mai 2013 à 16:31:16

                                @Eskimon: Je ne pense pas que ce soit possible, ce serait pas drôle sinon :D .

                                Après pour faire une simili-pause tu peux toujours faire une énorme boucle avec des milliards d'itérations, mais ce n'est pas d'une propreté exceptionnelle et ça risque d'être délicat pour régler le délai :-° ...

                                -
                                Edité par Anonyme 4 mai 2013 à 16:31:43

                                • Partager sur Facebook
                                • Partager sur Twitter
                                  4 mai 2013 à 16:33:44

                                  Normalement vu que le BrainFuck est "Turing Compliant" ca devrait etre possible de faire des appels systèmes, mais j'ai pas trouvé de ressources qui expliquerait comment faire...

                                  Wikipédia a écrit:

                                  Le brainfuck est pourtant un langage Turing-complet1, ce qui signifie que, malgré les apparences, il est théoriquement possible d'écrire n'importe quel programme informatique en brainfuck.



                                  • Partager sur Facebook
                                  • Partager sur Twitter

                                  Retrouvez moi sur mon blog et ma chaine Youtube !

                                    4 mai 2013 à 16:39:22

                                    Je pense que du coup, ça (les appels systemes et/ou de fonctions) dépendent surtout du compilo/interpreteur que tu va utiliser.

                                    Tu peux manip a mémoire, donc tu peux tout faire

                                    • Partager sur Facebook
                                    • Partager sur Twitter
                                      4 mai 2013 à 16:39:30

                                      Ce n'est pas parce qu'un langage est Turing-complet qu'il a un accès complet aux ressources du système. Tout le problème est là...

                                      • Partager sur Facebook
                                      • Partager sur Twitter
                                        4 mai 2013 à 16:42:16

                                        Oui, c'est ce que je dis. Ça dépend de la plateforme d'execution...

                                        Sinon tu pourrais utiliser brainf*ck++

                                        • Partager sur Facebook
                                        • Partager sur Twitter
                                        Anonyme
                                          4 mai 2013 à 17:02:45

                                          La grande classe ce serait d'utiliser BF++ pour générer un .gif contenant l'animation, mais là... :p
                                          • Partager sur Facebook
                                          • Partager sur Twitter
                                          Anonyme
                                            4 mai 2013 à 19:30:43

                                            Encore une version JS (/o/), mais j'ai utilisé la librairie CreateJS :).

                                            Avec un index.html

                                            <html>
                                            <head>
                                            	<title>Space Invaders</title>
                                            	<style>
                                            	body{
                                            		width:100%; height:100%;
                                            		overflow: hidden;
                                            	}
                                            	canvas{
                                            		margin:0 auto; padding: 0;
                                            		display: block;overflow: hidden;
                                            	}
                                            	</style>
                                            	<script type="text/javascript" src="createjs.min.js"></script>
                                            	<script type="text/javascript" src="spaceinvader.js"></script>
                                            </head>
                                            <body onload="init()">
                                            	<canvas id="canvas" width=800 height=800>Votre navigateur internet ne semble pas capable d'utiliser canvas... Mettez le à jour !</canvas>
                                            </body>
                                            	<script type="text/javascript">
                                            		function init () {
                                            			if(typeof(createjs) != "undefined"){
                                            				cjs = createjs; new Invader(null, 50, 'canvas');
                                            				setInterval("new Invader(null, 50, 'canvas')", 3000);	
                                            			}
                                            		}
                                            	</script>
                                            </html>

                                            et la Class qui va bien : spaceinvader.js

                                            (function(window){
                                            
                                            		function Invader(color, size, canvas){
                                            			
                                            			this.canvas = document.querySelector(canvas);	
                                            			this.canvas.width = window.innerWidth; this.canvas.height = window.innerHeight;
                                            		
                                            			Invader.color = (color != null) ? color : randomColor();
                                            			Invader.square = {size : size};
                                            			Invader.pattern = [
                                            			 [0,0,1,0,1,0,0],
                                            			 [0,1,1,1,1,1,0],
                                            			 [0,1,2,1,2,1,0],
                                            			 [0,1,2,1,2,1,0],
                                            			 [1,1,1,1,1,1,1],
                                            			 [1,0,1,0,1,0,1]
                                            			];
                                            
                                            			_stage =  new cjs.Stage(this.canvas); this.getStage = function(){return _stage};
                                            			_g = new cjs.Graphics(); this.getGraphics = function(){return _g};
                                            			_container = []; this.getContainer = function(){return _container};
                                            
                                            			invade(this);
                                            		};
                                            
                                            		
                                            		function invade(self){
                                            			
                                            			self.getStage().autoClear = true;
                                            
                                            			Invader.X =  random(-Invader.square.size, self.canvas.width - 7*Invader.square.size);
                                            			Invader.Y =  random(-Invader.square.size, self.canvas.height - 6*Invader.square.size);
                                            			
                                            			for (var i = 0; i <= Invader.pattern.length - 1; i++) {
                                            				
                                            				Invader.square.Y = (i+1)*Invader.square.size;
                                            
                                            				for (var j = 0; j <= Invader.pattern[i].length - 1; j++) {
                                            					
                                            					Invader.square.X = (j+1)*Invader.square.size;
                                            
                                            					if(Invader.pattern[i][j] == 1){
                                            						self.getContainer().push(drawSquare(self));		
                                            					}else if(Invader.pattern[i][j] == 2){
                                            						r = random(0,2);
                                            						if(r == 1){
                                            							Invader.pattern[i+1][j] = 0;
                                            							self.getContainer().push(drawSquare(self, '#000'));
                                            						}else{
                                            							Invader.pattern[i][j] = 0;
                                            							Invader.pattern[i+1][j] = 3;
                                            						}
                                            					}else if(Invader.pattern[i][j] == 3){
                                            						self.getContainer().push(drawSquare(self, '#000'));
                                            					}
                                            				}
                                            			}
                                            			
                                            
                                            			for (var i = 0; i <= self.getContainer().length; i++) {
                                            				s = new cjs.Shape(self.getContainer()[i]);
                                            				self.getStage().addChild(s);
                                            				s.x = Invader.X;
                                            				s.y = Invader.Y;
                                            			};
                                            			
                                            			self.getStage().update();
                                            		}
                                            
                                            		random = function(From, To){
                                            			return Math.floor((Math.random()*To)+From);
                                            		}
                                            
                                            		randomColor = function (self){
                                            			r = random(1,255);
                                            			g = random(1,255);
                                            			b = random(1,255);
                                            			return cjs.Graphics.getRGB(r, g, b);
                                            
                                            		}
                                            
                                            		drawSquare = function(self, color){
                                            			return self.getGraphics()
                                            			.f((color != null) ? color : Invader.color)
                                            			.ss(Invader.square.size/10,2).s('#FFF')
                                            			.r(Invader.square.X, Invader.square.Y, Invader.square.size, Invader.square.size);
                                            		}
                                            
                                            	window.Invader = Invader;
                                            
                                            })(window);




                                            -
                                            Edité par Anonyme 7 mai 2013 à 12:46:36

                                            • Partager sur Facebook
                                            • Partager sur Twitter
                                              4 mai 2013 à 23:39:27

                                              Une version pourrie en C#, vous excuserez la qualité du code (et, surtout, surtout, de la sortie), il se fait tard et j'ai mal aux yeux.

                                              using System;
                                              using System.Windows.Forms;
                                              using System.Drawing;
                                              
                                              namespace WindowsFormsApplication1
                                              {
                                                  public partial class Form1 : Form
                                                  {
                                                      const int BLOCK_SIZE = 32;
                                              
                                                      int[,] map = new int[,]
                                                      {
                                                          {0,0,1,0,1,0,0},
                                                          {0,1,1,1,1,1,0},
                                                          {0,1,2,1,2,1,0},
                                                          {0,1,0,1,0,1,0},
                                                          {1,1,1,1,1,1,1},
                                                          {1,0,1,0,1,0,1}
                                                      };
                                              
                                                      int startX;
                                                      int startY;
                                              
                                                      Bitmap bmp;
                                                      Graphics graph;
                                                      Pen pen;
                                              
                                                      public Form1()
                                                      {
                                                          InitializeComponent();
                                                          InitializeGrapher();
                                              
                                                          tim_Timer.Start();
                                                      }
                                              
                                                      private void InitializeGrapher()
                                                      {
                                                          bmp = new Bitmap(Width, Height);
                                                          graph = Graphics.FromImage(bmp);
                                                      }
                                              
                                                      private void InitializePosition()
                                                      {
                                                          startX = GetRandom(Width / BLOCK_SIZE - 7);
                                                          startY = GetRandom(Height / BLOCK_SIZE - 6);
                                                      }
                                              
                                                      private int GetRandom(int max)
                                                      {
                                                          Random rand = new Random();
                                              
                                                          return rand.Next(max);
                                                      }
                                              
                                                      private void Render()
                                                      {
                                                          InitializeRender();
                                                          GetNewEyesPosition();
                                              
                                                          for (int x = 0; x < 6; x++)
                                                          {
                                                              for (int y = 0; y < 7; y++)
                                                              {
                                                                  int posX = (startX + y) * BLOCK_SIZE;
                                                                  int posY = (startY + x) * BLOCK_SIZE;
                                              
                                                                  if (map[x, y] == 1) DrawCell(posX, posY);
                                                                  if (map[x, y] == 2) DrawEye(posX, posY);
                                                              }
                                                          }
                                              
                                                          pb_Ozone.Image = bmp;
                                                      }
                                              
                                                      private void InitializeRender()
                                                      {
                                                          pen = GetPen();
                                              
                                                          InitializePosition();
                                                          graph.Clear(Color.White);
                                                      }
                                              
                                                      private void GetNewEyesPosition()
                                                      {
                                                          int first = GetRandom(10);
                                                          int second = GetRandom(10);
                                              
                                                          PlaceFirstEye(first);
                                                          PlaceSecondEye(second);
                                                      }
                                              
                                                      private void PlaceFirstEye(int first)
                                                      {
                                                          map[2, 2] = 0;
                                                          map[3, 2] = 0;
                                              
                                                          if (first <= 4) map[2, 2] = 2;
                                                          else map[3, 2] = 2;
                                                      }
                                              
                                                      private void PlaceSecondEye(int second)
                                                      {
                                                          map[2, 4] = 0;
                                                          map[3, 4] = 0;
                                              
                                                          if (second >= 4) map[2, 4] = 2;
                                                          else map[3, 4] = 2;
                                                      }
                                              
                                                      private void DrawCell(int posX, int posY)
                                                      {
                                                          graph.FillRectangle(new SolidBrush(pen.Color),
                                                              new Rectangle(new Point(posX, posY),
                                                                  new Size(BLOCK_SIZE, BLOCK_SIZE)));
                                                      }
                                              
                                                      private void DrawEye(int posX, int posY)
                                                      {
                                                          graph.FillEllipse(new SolidBrush(pen.Color),
                                                              new Rectangle(new Point(posX, posY),
                                                                  new Size(BLOCK_SIZE, BLOCK_SIZE)));
                                                      }
                                              
                                                      private Pen GetPen()
                                                      {
                                                          int r = GetRandom(255);
                                                          int g = GetRandom(255);
                                                          int b = GetRandom(255);
                                              
                                                          return new Pen(Color.FromArgb(r, g, b));
                                                      }
                                              
                                                      private void tim_Timer_Tick(object sender, EventArgs e)
                                                      {
                                                          Render();
                                                      }
                                                  }
                                              }
                                              


                                              Avec les yeux qui deviennent lourds, je n'ai eu ni le courage, ni l'envie de repasser les fonctions au propre.

                                              EDIT : je viens d'y penser, mais l'effet est encore meilleur avec TransparencyKey = Color.White; dans le constructeur de la Form ! Notre petit extraterreux envahi l'écran sans même nous gêner !

                                              -
                                              Edité par Chiheb2012 4 mai 2013 à 23:56:54

                                              • Partager sur Facebook
                                              • Partager sur Twitter
                                              "Il est impossible pour un homme d'apprendre ce qu'il croit déjà connaître"
                                                4 mai 2013 à 23:59:32

                                                Bon je tenterais peut être une version BF++ pour faire un gif (si il fait moche et que j'arrive à m'ennuyer :p )... Ce qui serait cool c'est que quelqu'un me sorte une spec du format gif (j'en avais trouvé une mais elle allais pas assez à l'essentiel et j'ai pas de temps à perdre ce soir) ou un algo de codage de ces derniers...
                                                • Partager sur Facebook
                                                • Partager sur Twitter

                                                Retrouvez moi sur mon blog et ma chaine Youtube !

                                                  5 mai 2013 à 0:36:00

                                                  regarde le code à nohar, il en a fait une lib python !

                                                  • Partager sur Facebook
                                                  • Partager sur Twitter
                                                  Anonyme
                                                    5 mai 2013 à 9:00:41

                                                    @Eskimon: Bonne chance...

                                                    • Partager sur Facebook
                                                    • Partager sur Twitter
                                                    Anonyme
                                                      5 mai 2013 à 9:31:49

                                                      Une version en WhiteSpace :
                                                      http://www.mediafire.com/?l6ii08roxzqqhfy (en .zip, à ouvrir avec un éditeur de texte si vous n'avez pas le compilateur)
                                                      Un langage assez spécial dans sa syntaxe... ;)
                                                      La prochaine fois, une version en Alb !
                                                      :p

                                                      -
                                                      Edité par Anonyme 5 mai 2013 à 9:58:09

                                                      • Partager sur Facebook
                                                      • Partager sur Twitter
                                                        5 mai 2013 à 17:03:30

                                                        salut !!

                                                        aller je me lance, attention les yeux, ca risque de piquer un peu ... mais au moins ca marche !!

                                                        #include <time.h>
                                                        #include <SDL/SDL.h>
                                                        #include <SDL/SDL_image.h>
                                                        
                                                        #define FPS_DELAY       (1000/50)
                                                        #define UPDATE_DELAY    1500
                                                        #define NB_COLOR        6
                                                        
                                                        typedef struct{
                                                            Uint32  precedent;
                                                            Uint32  present;
                                                        }Temps;
                                                        
                                                        int spaceInvader[6][7] = {{0, 0, 1, 0, 1, 0, 0},
                                                                                  {0, 1, 1, 1, 1, 1, 0},
                                                                                  {0, 1, 0, 1, 0, 1, 0},
                                                                                  {0, 1, 0, 1, 0, 1, 0},
                                                                                  {1, 1, 1, 1, 1, 1, 1},
                                                                                  {1, 0, 1, 0, 1, 0, 1}};
                                                        
                                                        Uint32 getRandomColor(void);
                                                        SDL_Surface *initSdl(int largeur, int hauteur, char *titre);
                                                        SDL_Surface* my_createSdlSurface(int largeur, int hauteur, Uint8 r, Uint8 g, Uint8 b);
                                                        void my_blitSurface(SDL_Surface *surface, int x, int y);
                                                        int updateEvent();
                                                        void gererTemps(Temps *temps, Uint32 delay);
                                                        
                                                        int main(int argc, char *argv[])
                                                        {
                                                            /* VARIABLES */
                                                            SDL_Surface *ecran=NULL, *carre=NULL;
                                                            int x, y, i, j;
                                                            Uint32 colorWhite, colorBlack, lastUpdate;
                                                            Temps temps;
                                                        
                                                            /* INIT */
                                                            (void)argc, (void)argv; /* avoid warning */
                                                            ecran = initSdl(600, 600, "Space invader");
                                                            carre = SDL_CreateRGBSurface(SDL_HWSURFACE, 38, 38, 32, 0, 0, 0, 0);
                                                            if (carre == NULL) {
                                                                printf("ERREUR de creation d'une surface : %s\n", SDL_GetError());
                                                                exit(EXIT_FAILURE);}
                                                            colorWhite = SDL_MapRGB(ecran->format, 255, 255, 255);
                                                            colorBlack = SDL_MapRGB(ecran->format, 0, 0, 0);
                                                            srand(time(NULL));
                                                        
                                                            /* BOUCLE PRINCIPALE */
                                                            temps.precedent = SDL_GetTicks();
                                                            lastUpdate = SDL_GetTicks()-UPDATE_DELAY;
                                                            while (updateEvent())
                                                            {
                                                                while (lastUpdate+UPDATE_DELAY<SDL_GetTicks())
                                                                {
                                                                    SDL_FillRect(carre, NULL, getRandomColor());
                                                                    SDL_FillRect(ecran, NULL, colorWhite);
                                                                    /* corps */
                                                                    x=rand()%(15-7), y=rand()%(15-6);
                                                                    for (i=0; i<7; i++)
                                                                        for (j=0; j<6; j++)
                                                                            if (spaceInvader[j][i])
                                                                                my_blitSurface(carre, (x+i)*40+1, (y+j)*40+1);
                                                        
                                                                    /* yeux */
                                                                    SDL_FillRect(carre, NULL, colorBlack);
                                                                    my_blitSurface(carre, (x+2)*40+1, (y+2+(rand()%2))*40+1);
                                                                    my_blitSurface(carre, (x+4)*40+1, (y+2+(rand()%2))*40+1);
                                                        
                                                                    SDL_Flip(ecran);
                                                                    lastUpdate += UPDATE_DELAY;
                                                                }
                                                        
                                                                gererTemps(&temps, FPS_DELAY);
                                                            }
                                                        
                                                            /* FREE */
                                                            SDL_FreeSurface(carre);
                                                            SDL_Quit();
                                                        
                                                            return 0;
                                                        }
                                                        
                                                        
                                                        Uint32 getRandomColor(void)
                                                        {
                                                            switch (rand() % NB_COLOR)
                                                            {
                                                                case 0:
                                                                    return SDL_MapRGB(SDL_GetVideoSurface()->format, 0, 0, 255);
                                                                    break;
                                                                case 1:
                                                                    return SDL_MapRGB(SDL_GetVideoSurface()->format, 0, 255, 0);
                                                                    break;
                                                                case 2:
                                                                    return SDL_MapRGB(SDL_GetVideoSurface()->format, 0, 255, 255);
                                                                    break;
                                                                case 3:
                                                                    return SDL_MapRGB(SDL_GetVideoSurface()->format, 255, 0, 0);
                                                                    break;
                                                                case 4:
                                                                    return SDL_MapRGB(SDL_GetVideoSurface()->format, 255, 0, 255);
                                                                    break;
                                                                case 5:
                                                                    return SDL_MapRGB(SDL_GetVideoSurface()->format, 255, 255, 0);
                                                                    break;
                                                                /* avoid warning */
                                                                default:
                                                                    return SDL_MapRGB(SDL_GetVideoSurface()->format, 0, 0, 255);
                                                                    break;
                                                            }
                                                        
                                                        }
                                                        
                                                        
                                                        SDL_Surface *initSdl(int largeur, int hauteur, char *titre)
                                                        {
                                                            SDL_Surface *ecran = NULL;
                                                        
                                                            if (SDL_Init(SDL_INIT_VIDEO) != 0) {
                                                                printf("ERREUR d'initialisation de la SDL : %s\n", SDL_GetError());
                                                                exit(EXIT_FAILURE);}
                                                        
                                                            SDL_putenv("SDL_VIDEO_WINDOW_POS=40,60");
                                                            if (titre != NULL) SDL_WM_SetCaption(titre, NULL);
                                                        
                                                            ecran = SDL_SetVideoMode(largeur, hauteur, 32, SDL_SWSURFACE);
                                                            if (ecran == NULL) {
                                                                printf("ERREUR d'initialisation de l'ecran : %s\n", SDL_GetError());
                                                                exit(EXIT_FAILURE);}
                                                        
                                                            return ecran;
                                                        }
                                                        
                                                        
                                                        void my_blitSurface(SDL_Surface *surface, int x, int y)
                                                        {
                                                            SDL_Rect position;
                                                            position.x = x;
                                                            position.y = y;
                                                        
                                                            SDL_BlitSurface(surface, NULL, SDL_GetVideoSurface(), &position);
                                                        }
                                                        
                                                        
                                                        int updateEvent(void)
                                                        {
                                                            SDL_Event event;
                                                        
                                                            while (SDL_PollEvent(&event))
                                                            {
                                                                switch(event.type)
                                                                {
                                                                    case SDL_QUIT:
                                                                        return 0;
                                                                        break;
                                                                    case SDL_KEYDOWN:
                                                                        if (event.key.keysym.sym == SDLK_SPACE)
                                                                            return 0;
                                                                        break;
                                                                    /* avoid warning */
                                                                    default:
                                                                        break;
                                                                }
                                                            }
                                                        
                                                           return 1;
                                                        }
                                                        
                                                        
                                                        void gererTemps(Temps *temps, Uint32 delay)
                                                        {
                                                            int pause;
                                                        
                                                            temps->present = SDL_GetTicks();
                                                            pause = delay - (temps->present - temps->precedent);
                                                        
                                                            if (pause >= 0)
                                                                SDL_Delay(pause);
                                                        
                                                            temps->precedent = temps->present;
                                                        }
                                                        

                                                         EDIT : bon aller je vous le fait aussi en Ti Basic :p

                                                        [[0,0,1,0,1,0,0][0,1,1,1,1,1,0][0,1,0,1,0,1,0][0,1,0,1,0,1,0][1,1,1,1,1,1,1][1,0,1,0,1,0,1]]->[A]
                                                        
                                                        While 1
                                                        entAléat(0,8)->Y
                                                        entAléat(0,2)->X
                                                        
                                                        EffEcr
                                                        For(A,1,6)
                                                        For(B,1,7)
                                                        If [A](A,B)
                                                        End
                                                        End
                                                        
                                                        For(Z,0,7)
                                                        69!
                                                        End
                                                        End
                                                        
                                                        

                                                        (Et oui, la syntaxe est deroutante et on fais avec les moyens du bord ...)

                                                        -
                                                        Edité par nodrak 5 mai 2013 à 17:26:16

                                                        • Partager sur Facebook
                                                        • Partager sur Twitter
                                                        Vive le peupl et les clémentines !
                                                          5 mai 2013 à 18:31:39

                                                          J'ai commence à coder en TI-Basic il y a peu et je dois avouer que le 69! me déroute un peu. À quoi il sert ?
                                                          • Partager sur Facebook
                                                          • Partager sur Twitter
                                                          "Il est impossible pour un homme d'apprendre ce qu'il croit déjà connaître"
                                                            5 mai 2013 à 18:37:02

                                                            C'est pour faire une pause d'une demi seconde, tu peux en mettre plusieurs à la (69!:69!...).
                                                            • Partager sur Facebook
                                                            • Partager sur Twitter

                                                            [Atelier] Fond animé Space Invaders

                                                            × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                                                            × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                                                            • Editeur
                                                            • Markdown