From 83c7f9a20f4a8b72b5899e6d9257be0d1d9e112e Mon Sep 17 00:00:00 2001 From: Fabrice Trillaud Date: Mon, 6 Aug 2018 16:24:40 +0200 Subject: [PATCH] Version sans pixelisation de la video --- grid_video/EntitiesManager.pde | 31 +++++++++++++++---------------- grid_video/enemy.pde | 8 ++++---- grid_video/grid_video.pde | 32 +++++++++++++++++--------------- grid_video/missile.pde | 8 ++++---- grid_video/player.pde | 6 +++--- 5 files changed, 43 insertions(+), 42 deletions(-) diff --git a/grid_video/EntitiesManager.pde b/grid_video/EntitiesManager.pde index 711bb19..971b537 100644 --- a/grid_video/EntitiesManager.pde +++ b/grid_video/EntitiesManager.pde @@ -15,15 +15,15 @@ class EntitiesManager { private Timer timer; public EntitiesManager(SoundFile endGameSound, SoundFile explosionSound, SoundFile hitSound, SoundFile reboundSound) { - this.endGameSound = endGameSound; - this.explosionSound = explosionSound; - this.hitSound = hitSound; - this.reboundSound = reboundSound; + this.endGameSound = endGameSound; + this.explosionSound = explosionSound; + this.hitSound = hitSound; + this.reboundSound = reboundSound; - Enemies = new ArrayList(); + Enemies = new ArrayList(); - timer = new Timer(new Point(width - 98, 5)); - timer.start(); + timer = new Timer(new Point(width - 98, 5)); + timer.start(); } public void setup() { @@ -34,24 +34,24 @@ class EntitiesManager { Enemies.add(new Enemy(width / 2 + 40, 50, 80)); Player = new Player( - 20, 100, //pos - 20, 130, // max x pos + 100, 600, //pos + 100, 1080, // max x pos videoScale); Missiles = new ArrayList(); gameOver = false; - if(endGameSound.isPlaying()>0) { + if (endGameSound.isPlaying()>0) { endGameSound.stop(); } timer.stop(); timer.start(); ps = new ParticleSystem(new PVector(width/2, 50)); - } void checkEndGame() { + if (!gameOver) { if (timer.isOver()) { gameOver = true; @@ -122,7 +122,7 @@ class EntitiesManager { ArrayList allInterectionPoints = new ArrayList(); for (Enemy enemy : Enemies) { for (Segment enemySegment : enemy.segments) { - Point tmpIntersection = new Point(0,0); + Point tmpIntersection = new Point(0, 0); if (missileToTop.GetIntersectionPoint(enemySegment, tmpIntersection)) { allInterectionPoints.add(new HitResult(tmpIntersection, enemy)); } @@ -138,7 +138,7 @@ class EntitiesManager { private void trySpawnMissile() { if (Missiles.size() < _maxMissileCount && abs(_lastMissileSpawn - millis()) > 1000) { Missile newMissile = new Missile(Player.x, Player.y, videoScale); - HitResult intersection = new HitResult(new Point(0,0), null); + HitResult intersection = new HitResult(new Point(0, 0), null); if (GetIntersectionWithEnemies(newMissile, intersection)) { newMissile.hitResult = intersection; } @@ -159,8 +159,7 @@ class EntitiesManager { if (missile.hitResult.HitEnemy.isFull()) { reboundSound.play(); missile.rebound(); - } - else { + } else { missile.hitResult.HitEnemy.onHit(); hitSound.play(); toRemove.add(missile); @@ -193,4 +192,4 @@ class EntitiesManager { int offset = text.length() * 15; text(text, width / 2 - offset, height / 2); } -} \ No newline at end of file +} diff --git a/grid_video/enemy.pde b/grid_video/enemy.pde index 3568cfe..5612e27 100644 --- a/grid_video/enemy.pde +++ b/grid_video/enemy.pde @@ -1,5 +1,5 @@ class Enemy { - private float x1, y1, w; + private float startX, x1, y1, w; private float level = 0; private float h = 200; @@ -12,8 +12,8 @@ class Enemy { public Enemy(float x1, float y1, float w) { this.x1 = x1; this.y1 = y1; - this.w = w; - + this.w = w; + topLeft = new Point(x1, y1); topRight = new Point(x1 + w, y1); bottomLeft = new Point(x1 - w, y1 + h); @@ -73,4 +73,4 @@ class Enemy { boolean isHittingEnemy(Point point) { return (this.topRight.X >= point.X && this.bottomLeft.X <= point.X && this.bottomRight.Y >= point.Y); } -} \ No newline at end of file +} diff --git a/grid_video/grid_video.pde b/grid_video/grid_video.pde index 17c188f..576174a 100644 --- a/grid_video/grid_video.pde +++ b/grid_video/grid_video.pde @@ -5,7 +5,7 @@ import processing.sound.*; // Size of each cell in the grid, ratio of window size to video size // 80 * 8 = 640 // 60 * 8 = 480 -int videoScale = 8; +int videoScale = 1; // Number of columns and rows in our system int cols, rows; @@ -30,7 +30,15 @@ void setup() { cols = width/videoScale; rows = height/videoScale; - video = new Capture(this, 160, 120); + game = new EntitiesManager( + new SoundFile(this, "end-game.mp3"), + new SoundFile(this, "explosion.mp3"), + new SoundFile(this, "hit.mp3"), + new SoundFile(this, "rebound.mp3")); + game.setup(); + +//video = new Capture(this, 160, 120); + video = new Capture(this, 1280, 960); video.start(); // Create an empty image the same size as the video @@ -38,21 +46,14 @@ void setup() { prevFrame = createImage(video.width, video.height, RGB); leftRegion = new MotionRegion( - 10, 110, 10, 10, + 100, 850, 100, 100, video.pixels.length, videoScale); rightRegion = new MotionRegion( - 150, 110, 10, 10, + 1180, 850, 10, 10, video.pixels.length, videoScale); - - game = new EntitiesManager( - new SoundFile(this, "end-game.mp3"), - new SoundFile(this, "explosion.mp3"), - new SoundFile(this, "hit.mp3"), - new SoundFile(this, "rebound.mp3")); - game.setup(); } void captureEvent(Capture video) { @@ -69,9 +70,9 @@ void captureEvent(Capture video) { leftRegion.motionBetween(videoMirror, prevFrame); if (rightRegion.hasMoved()) { - game.Player.moveRight(2); + game.Player.moveRight(15); } else if (leftRegion.hasMoved()) { - game.Player.moveLeft(2); + game.Player.moveLeft(15); } game.checkEndGame(); } @@ -94,7 +95,8 @@ void keyPressed() { } void draw() { - drawAllCells(); + image(videoMirror, 0, 0); + //drawAllCells(); drawBackground(); rightRegion.draw(); @@ -125,4 +127,4 @@ void drawCell(int i, int j) { fill(c); stroke(1); rect(x, y, videoScale, videoScale); -} \ No newline at end of file +} diff --git a/grid_video/missile.pde b/grid_video/missile.pde index 30305d0..26b261b 100644 --- a/grid_video/missile.pde +++ b/grid_video/missile.pde @@ -5,7 +5,7 @@ class Missile{ public Point Right; public Point Bottom; public Point Left; - private float YspeedFactor = 4; + private float YspeedFactor = 10; private float XspeedFactor; private int _videoScale; private boolean _hasRebounded; @@ -22,8 +22,8 @@ class Missile{ void rebound() { _hasRebounded = true; - XspeedFactor = random(-4,4); - YspeedFactor = random(2,4); + XspeedFactor = random(-4,10); + YspeedFactor = random(2,10); } void move() { @@ -60,4 +60,4 @@ class Missile{ fill(0, 138, 253); quad(Top.X, Top.Y, Right.X, Right.Y, Bottom.X, Bottom.Y, Left.X, Left.Y); } -} \ No newline at end of file +} diff --git a/grid_video/player.pde b/grid_video/player.pde index de7058b..b423374 100644 --- a/grid_video/player.pde +++ b/grid_video/player.pde @@ -26,8 +26,8 @@ class Player { private void loadPlane(){ plane=loadShape("warplane.svg"); - this.shapeWidth=20*videoScale; - this.shapeHeight=20*videoScale; + this.shapeWidth=200*videoScale; + this.shapeHeight=200*videoScale; this.maxx=this.maxx + this.shapeWidth/(2*videoScale); } @@ -51,4 +51,4 @@ class Player { shape(plane,xHead,y*videoScale-20,this.shapeWidth,this.shapeHeight); } -} \ No newline at end of file +}