Skip to content

Commit

Permalink
Rebuilt the project to take the examples into account.
Browse files Browse the repository at this point in the history
  • Loading branch information
zedseven committed Dec 10, 2018
1 parent 929dbc8 commit 379488e
Show file tree
Hide file tree
Showing 56 changed files with 1,026 additions and 45 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ This was done for a school project, so it will likely _not_ be maintained.

## Installation
First, go to the Releases tab and download the .zip file, and unzip it to wherever you want to keep the library.
To install the library, simply put the .jar file in your Processing libraries folder.
To install the library, simply open `Green-<version>.zip\library\` and put `Green.jar` in your Processing libraries folder.
Processing's `libraries` folder is located in `<sketchbookLocation>\libraries`, and it's sketchbook location can be found in the editor under `File > Preferences...`.

## Reference
To see the Javadoc reference, please visit [https://zedseven.github.io/Green/](https://zedseven.github.io/Green/).
From there, select `Sketch > Import Library...` in the editor, and Green should show up for selection.

From there, select `Sketch > Import Library...` in the editor, and Green should show up for selection.
## Reference
To see the Javadoc reference, please visit [https://zedseven.github.io/Green/](https://zedseven.github.io/Green/).
239 changes: 239 additions & 0 deletions distribution/Green-1.0/examples/ArenaShoot/Arena.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
import java.util.*;

class Arena extends World
{
//Configuration variables
int topOffset = 40; //TopBar height
int textColour = color(255, 255, 255);
int gameOverColour = color(50, 50, 50);
//Enemy1
int enemy1SpawnTimeBase = 1000;
int enemy1SpawnTimeRange = 1000;
int enemy1GlobalMoveTime = 500;
int enemy1MoveDurationBase = 1000;
int enemy1MoveDurationRange = 4000;
int enemy1ShootTimeBase = 1500;
int enemy1ShootTimeRange = 250;
//Enemy2
int enemy2SpawnTimeBase = 7000;
int enemy2SpawnTimeRange = 8000;
int enemy2GlobalMoveTime = 500;
//Enemy3
int enemy3SpawnTimeBase = 1000;
int enemy3SpawnTimeRange = 1000;
int enemy3GlobalMoveTime = 500;
int enemy3ShootTimeBase = 1500;
int enemy3ShootTimeRange = 250;
//Spawn caps
int enemy1Cap = 6;
int enemy2Cap = 1;
int enemy3Cap = 2;
//Powerups
//Laser powerup
int lPowerSpawnTimeBase = 10000;
int lPowerSpawnTimeRange = 20000;
//Shield powerup
int sPowerSpawnTimeBase = 10000;
int sPowerSpawnTimeRange = 20000;
//Health powerup
int hPowerSpawnTimeBase = 10000;
int hPowerSpawnTimeRange = 20000;

//Runtime variables
long enemy1NextSpawnTime = enemy1SpawnTimeBase + round(enemy1SpawnTimeRange * random(-1f, 1f));
long enemy2NextSpawnTime = enemy2SpawnTimeBase + round(enemy2SpawnTimeRange * random(-1f, 1f));
long enemy3NextSpawnTime = enemy3SpawnTimeBase + round(enemy3SpawnTimeRange * random(-1f, 1f));
long enemy1NextShootTime = enemy1ShootTimeBase + round(enemy1ShootTimeRange * random(-1f, 1f));
long enemy3NextShootTime = enemy3ShootTimeBase + round(enemy3ShootTimeRange * random(-1f, 1f));
int enemy1Count = 0;
int enemy2Count = 0;
int enemy3Count = 0;
long lastEnemy1Move = 0;
long lastEnemy2Move = 0;
long lastEnemy3Move = 0;
boolean lPowerExists = false;
boolean sPowerExists = false;
boolean hPowerExists = false;
long lPowerNextSpawnTime = lPowerSpawnTimeBase + round(lPowerSpawnTimeRange * random(0f, 1f));
long sPowerNextSpawnTime = sPowerSpawnTimeBase + round(sPowerSpawnTimeRange * random(0f, 1f));
long hPowerNextSpawnTime = hPowerSpawnTimeBase + round(hPowerSpawnTimeRange * random(0f, 1f));

//Construct the world at the start of the program
public Arena(int w, int h)
{
super(w, h, loadImage("ground.png"));
}
//Run once when the world is loaded
public void prepare()
{
TankBase player = new TankBase(getWidth() / 2f, getHeight() / 2f);
addObject(player);
TankTurret playerTurret = new TankTurret();
addObject(playerTurret);
TopBar topBar = new TopBar();
addObject(topBar);
}
//Run every frame
public void act(float deltaTime)
{
handleEnemy1s();
handleEnemy2s();
handleEnemy3s();
handlePowerups();
}
//Final 'Game Over' screen
public void gameOver(int finalScore)
{
println("Game over! Final score: " + finalScore);
exit();
}
private void handleEnemy1s()
{
//Spawn
if(enemy1Count < enemy1Cap && millis() >= enemy1NextSpawnTime)
{
EnemySide side = EnemySide.Top;
switch(floor(random(0, 4f)))
{
case 0:
side = EnemySide.Top;
break;
case 1:
side = EnemySide.Bottom;
break;
case 2:
side = EnemySide.Left;
break;
case 3:
side = EnemySide.Right;
break;
}
Enemy1 newEnemy = new Enemy1(side, this);
addObject(newEnemy);
enemy1Count++;
enemy1NextSpawnTime = millis() + enemy1SpawnTimeBase + round(enemy1SpawnTimeRange * random(-1f, 1f));
}
//Shoot
List<Enemy1> enemy1s = getObjects(Enemy1.class); //Note that this file imports 'java.util.*';
if(millis() >= enemy1NextShootTime && enemy1s.size() > 0)
{
enemy1NextShootTime = millis() + enemy1ShootTimeBase + round(enemy1ShootTimeRange * random(-1f, 1f));
enemy1s.get(floor(random(0f, enemy1s.size()))).shoot();
}
//Move
if(millis() >= lastEnemy1Move + enemy1GlobalMoveTime)
{
lastEnemy1Move = millis();
for(Enemy1 enemy : enemy1s)
{
if(random(0f, 1f) < 0.25f)
{
enemy.moveUntilTime = millis() + enemy1MoveDurationBase + round(enemy1MoveDurationRange * random(0f, 1f));
if(random(0f, 1f) < 0.5f)
enemy.moveSpeed = -enemy.moveSpeed;
}
}
}
}
private void handleEnemy2s()
{
//Spawn
if(enemy2Count < enemy2Cap && millis() >= enemy2NextSpawnTime)
{
Enemy2 newEnemy = new Enemy2(getWidth() * random(0f, 1f), topOffset + ((getHeight() - topOffset) * random(0f, 1f)));
addObject(newEnemy);
enemy2Count++;
enemy2NextSpawnTime = millis() + enemy2SpawnTimeBase + round(enemy2SpawnTimeRange * random(-1f, 1f));
}
//Move
if(millis() >= lastEnemy2Move + enemy2GlobalMoveTime)
{
lastEnemy2Move = millis();
List<Enemy2> enemy2s = getObjects(Enemy2.class);
for(Enemy2 enemy : enemy2s)
enemy.updateMovement();
}
}
private void handleEnemy3s()
{
//Spawn
if(enemy3Count < enemy3Cap && millis() >= enemy3NextSpawnTime)
{
Enemy3 newEnemy = new Enemy3(getWidth() * random(0f, 1f), topOffset + ((getHeight() - topOffset) * random(0f, 1f)));
addObject(newEnemy);
enemy3Count++;
enemy3NextSpawnTime = millis() + enemy3SpawnTimeBase + round(enemy3SpawnTimeRange * random(-1f, 1f));
}
//Shoot
List<Enemy3> enemy3s = getObjects(Enemy3.class);
if(millis() >= enemy3NextShootTime && enemy3s.size() > 0)
{
enemy3NextShootTime = millis() + enemy3ShootTimeBase + round(enemy3ShootTimeRange * random(-1f, 1f));
enemy3s.get(floor(random(0f, enemy3s.size()))).shoot();
}
//Move
if(millis() >= lastEnemy3Move + enemy3GlobalMoveTime)
{
lastEnemy3Move = millis();
for(Enemy3 enemy : enemy3s)
if(random(0f, 1f) < 0.25f)
enemy.moveDirection = random(0f, 360f);
}
}
private void handlePowerups()
{
if(!lPowerExists && millis() >= lPowerNextSpawnTime)
{
LaserPowerup powerup = new LaserPowerup(getWidth() * random(0f, 1f), topOffset + ((getHeight() - topOffset) * random(0f, 1f)));
addObject(powerup);
lPowerExists = true;
}
if(!sPowerExists && millis() >= sPowerNextSpawnTime)
{
ShieldPowerup powerup = new ShieldPowerup(getWidth() * random(0f, 1f), topOffset + ((getHeight() - topOffset) * random(0f, 1f)));
addObject(powerup);
sPowerExists = true;
}
if(!hPowerExists && millis() >= hPowerNextSpawnTime)
{
HealthPowerup powerup = new HealthPowerup(getWidth() * random(0f, 1f), topOffset + ((getHeight() - topOffset) * random(0f, 1f)));
addObject(powerup);
hPowerExists = true;
}
}
//Remove an enemy from the world - this is a separate method so we can keep track of enemy counts
public void removeEnemy1(Enemy1 enemy)
{
enemy1Count--;
removeObject(enemy);
}
public void removeEnemy2(Enemy2 enemy)
{
enemy2Count--;
removeObject(enemy);
}
public void removeEnemy3(Enemy3 enemy)
{
enemy3Count--;
removeObject(enemy);
}
//Removes a powerup and prepares the next one to spawn
public void removeLaserPowerup(LaserPowerup powerup)
{
lPowerNextSpawnTime = millis() + lPowerSpawnTimeBase + round(lPowerSpawnTimeRange * random(0f, 1f));
lPowerExists = false;
removeObject(powerup);
}
public void removeShieldPowerup(ShieldPowerup powerup)
{
sPowerNextSpawnTime = millis() + sPowerSpawnTimeBase + round(sPowerSpawnTimeRange * random(0f, 1f));
sPowerExists = false;
removeObject(powerup);
}
public void removeHealthPowerup(HealthPowerup powerup)
{
hPowerNextSpawnTime = millis() + hPowerSpawnTimeBase + round(hPowerSpawnTimeRange * random(0f, 1f));
hPowerExists = false;
removeObject(powerup);
}
}
48 changes: 48 additions & 0 deletions distribution/Green-1.0/examples/ArenaShoot/ArenaShoot.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Green.*;

/*
Name: Zacchary Dempsey-Plante
Date: 2018-12-09
Description: A driving arena shooter. This is a port of a game I originally made for school that was finished 2016-01-28. This is definitely not my cleanest code.
*/

Green green;
Arena world;

//Run at the start of the program, used to set everything up for the session
void setup()
{
size(800, 640);
green = new Green(this);
world = new Arena(width, height);
green.loadWorld(world);
}
//Run every frame
void draw()
{
green.handleAct();
green.handleDraw();
green.handleMousePosition(pmouseX, pmouseY, mouseX, mouseY);
green.handleInput();
}
//Allows for easy input-checking
void mousePressed()
{
green.handleMouseDown(mouseButton);
}
void mouseReleased()
{
green.handleMouseUp(mouseButton);
}
void mouseWheel(MouseEvent event)
{
green.handleMouseWheel(event.getCount());
}
void keyPressed()
{
green.handleKeyDown(key, keyCode);
}
void keyReleased()
{
green.handleKeyUp(key, keyCode);
}
67 changes: 67 additions & 0 deletions distribution/Green-1.0/examples/ArenaShoot/Enemy1.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
enum EnemySide
{
Top,
Bottom,
Left,
Right
}
class Enemy1 extends Actor
{
//Configuration variables
int topOffset = 40; //TopBar height
int scoreValue = 1;
float edgeOffset = 10f; //The distance from the edge to place it
float moveSpeed = 3f;
//Runtime variables
Green green;
EnemySide anchorSide;
long moveUntilTime = 0;

//Construct the actor at the start of the program
public Enemy1(EnemySide side, World world)
{
super(0, 0, loadImage("enemy1L.png"), 2f);
green = Green.getInstance();
anchorSide = side;
float randomMultiplier = random(0f, 1f);
switch(side)
{
case Top:
setLocation(world.getWidth() * randomMultiplier, edgeOffset + topOffset);
turn(90f);
break;
case Bottom:
setLocation(world.getWidth() * randomMultiplier, world.getHeight() - edgeOffset);
turn(-90f);
break;
case Left:
setLocation(edgeOffset, world.getHeight() * randomMultiplier);
//turn(0f); //Since it wouldn't do anything anyways
break;
case Right:
setLocation(world.getWidth() - edgeOffset, world.getHeight() * randomMultiplier);
turn(180f);
break;
}
}
//Run every frame
public void act(float deltaTime)
{
if(millis() <= moveUntilTime)
{
if(anchorSide == EnemySide.Top || anchorSide == EnemySide.Bottom)
moveGlobal(moveSpeed, 0f);
else //if(anchorSide == EnemySide.Left || anchorSide == EnemySide.Right)
moveGlobal(0f, moveSpeed);
if(isAtEdge())
moveSpeed = -moveSpeed;
}
}
public void shoot()
{
Enemy1Laser laser = new Enemy1Laser(getX(), getY());
world.addObject(laser);
laser.setRotation(this.getRotation());
laser.move(25f);
}
}
Loading

0 comments on commit 379488e

Please sign in to comment.