Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions grid_video/EntitiesManager.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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<Enemy>();
Enemies = new ArrayList<Enemy>();

timer = new Timer(new Point(width - 98, 5));
timer.start();
timer = new Timer(new Point(width - 98, 5));
timer.start();
}

public void setup() {
Expand All @@ -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<Missile>();

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;
Expand Down Expand Up @@ -122,7 +122,7 @@ class EntitiesManager {
ArrayList<HitResult> allInterectionPoints = new ArrayList<HitResult>();
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));
}
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -193,4 +192,4 @@ class EntitiesManager {
int offset = text.length() * 15;
text(text, width / 2 - offset, height / 2);
}
}
}
8 changes: 4 additions & 4 deletions grid_video/enemy.pde
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
32 changes: 17 additions & 15 deletions grid_video/grid_video.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,29 +30,30 @@ 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
videoMirror = createImage(video.width, video.height, RGB);
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) {
Expand All @@ -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();
}
Expand All @@ -94,7 +95,8 @@ void keyPressed() {
}

void draw() {
drawAllCells();
image(videoMirror, 0, 0);
//drawAllCells();
drawBackground();

rightRegion.draw();
Expand Down Expand Up @@ -125,4 +127,4 @@ void drawCell(int i, int j) {
fill(c);
stroke(1);
rect(x, y, videoScale, videoScale);
}
}
8 changes: 4 additions & 4 deletions grid_video/missile.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}
}
}
6 changes: 3 additions & 3 deletions grid_video/player.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -51,4 +51,4 @@ class Player {
shape(plane,xHead,y*videoScale-20,this.shapeWidth,this.shapeHeight);
}

}
}