Shift from Game-Design
This commit is contained in:
commit
bb41a130ba
153 changed files with 4046 additions and 0 deletions
174
src/edu/utc/gamedev/Manager/AudioManager.java
Normal file
174
src/edu/utc/gamedev/Manager/AudioManager.java
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
package edu.utc.gamedev.Manager;
|
||||
|
||||
/**
|
||||
* @author Craig Tanis
|
||||
* <p>
|
||||
* Code obtained from https://github.com/ctanis/cpsc3520_fa17/blob/master/pongy/src/AudioManager.java
|
||||
*/
|
||||
|
||||
import edu.utc.gamedev.Game;
|
||||
import org.lwjgl.openal.AL;
|
||||
import org.newdawn.slick.openal.Audio;
|
||||
import org.newdawn.slick.openal.AudioLoader;
|
||||
import org.newdawn.slick.openal.SoundStore;
|
||||
import org.newdawn.slick.util.ResourceLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
/**
|
||||
* A utility class for caching sounds from files and enabling the
|
||||
* straightforward triggering of those sounds (samples and loops)
|
||||
*/
|
||||
public class AudioManager
|
||||
{
|
||||
private static AudioManager instance;
|
||||
private HashMap<String, AudioWrapper> sounds;
|
||||
|
||||
private AudioManager()
|
||||
{
|
||||
sounds = new HashMap<String, AudioWrapper>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the singleton AudioManager instance
|
||||
*/
|
||||
public static AudioManager getInstance()
|
||||
{
|
||||
if (instance == null) instance = new AudioManager();
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* load a one-shot sample
|
||||
*
|
||||
* @param name identifier for loaded sound
|
||||
* @param path path to file
|
||||
*/
|
||||
public void loadSample(String name, String path) throws IOException
|
||||
{
|
||||
// extract file extension
|
||||
String mode = path.substring(path.lastIndexOf('.') + 1).toUpperCase();
|
||||
|
||||
Audio tmp = AudioLoader.getAudio(mode, ResourceLoader.getResourceAsStream(path));
|
||||
sounds.put(name, new AudioWrapper(AudioType.SAMPLE, tmp));
|
||||
}
|
||||
|
||||
/**
|
||||
* load a looping music track
|
||||
*
|
||||
* @param name identifier for loaded sound
|
||||
* @param path path to file
|
||||
*/
|
||||
public void loadLoop(String name, String path) throws IOException
|
||||
{
|
||||
// extract file extension
|
||||
String mode = path.substring(path.lastIndexOf('.') + 1).toUpperCase();
|
||||
|
||||
Audio tmp = AudioLoader.getStreamingAudio(mode, ResourceLoader.getResource(path));
|
||||
sounds.put(name, new AudioWrapper(AudioType.LOOP, tmp));
|
||||
}
|
||||
|
||||
/**
|
||||
* get sound associated with name identifier
|
||||
*
|
||||
* @param name the loaded sound identifier
|
||||
*/
|
||||
public AudioWrapper get(String name)
|
||||
{
|
||||
return sounds.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* play sound associated with name identifier
|
||||
*
|
||||
* @param name the loaded sound identifier
|
||||
*/
|
||||
public void play(String name)
|
||||
{
|
||||
sounds.get(name).play();
|
||||
}
|
||||
|
||||
/**
|
||||
* play sound associated with name identifier
|
||||
*
|
||||
* @param name the loaded sound identifier
|
||||
* @param vol volume of sound (0.0 to 1.0)
|
||||
*/
|
||||
public void play(String name, float vol)
|
||||
{
|
||||
sounds.get(name).play(vol);
|
||||
}
|
||||
|
||||
/**
|
||||
* call this once per frame
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
SoundStore.get().poll(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* call this to clean up
|
||||
*/
|
||||
public void destroy()
|
||||
{
|
||||
AL.destroy();
|
||||
}
|
||||
|
||||
|
||||
private enum AudioType
|
||||
{
|
||||
LOOP, SAMPLE
|
||||
}
|
||||
|
||||
/**
|
||||
* A handle on a loaded audio object, to play the same sound repeatedly
|
||||
* without having to look it up
|
||||
*/
|
||||
public class AudioWrapper
|
||||
{
|
||||
private Audio sound;
|
||||
private AudioType type;
|
||||
|
||||
private AudioWrapper(AudioType t, Audio a)
|
||||
{
|
||||
type = t;
|
||||
sound = a;
|
||||
}
|
||||
|
||||
/**
|
||||
* play this sound at config's volume
|
||||
*/
|
||||
public void play()
|
||||
{
|
||||
play(Game.getInstance().config.volume);
|
||||
}
|
||||
|
||||
/**
|
||||
* Play this sound
|
||||
*
|
||||
* @param vol value between 0.0 and 1.0 to specify relative volume of sound
|
||||
* if volume is 0, sound is not played
|
||||
*/
|
||||
public void play(float vol)
|
||||
{
|
||||
// prevents the sound from being played if sound is "off"
|
||||
if (vol <= 0F)
|
||||
return;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case LOOP:
|
||||
sound.playAsMusic(1.0f, vol, true);
|
||||
break;
|
||||
|
||||
case SAMPLE:
|
||||
sound.playAsSoundEffect(1.0f, vol, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
72
src/edu/utc/gamedev/Manager/EntityManager.java
Normal file
72
src/edu/utc/gamedev/Manager/EntityManager.java
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
package edu.utc.gamedev.Manager;
|
||||
|
||||
import edu.utc.gamedev.Entity.Entity;
|
||||
import edu.utc.gamedev.Entity.Living.EntityLiving;
|
||||
import edu.utc.gamedev.Entity.Living.EntityMonster;
|
||||
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class EntityManager
|
||||
{
|
||||
private LinkedList<Entity> entities;
|
||||
|
||||
public EntityManager()
|
||||
{
|
||||
entities = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void drawAll()
|
||||
{
|
||||
for (Entity e : entities)
|
||||
{
|
||||
e.draw();
|
||||
if (e instanceof EntityLiving)
|
||||
{
|
||||
((EntityLiving) e).drawHealth();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAll(float delta)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (Entity e : entities)
|
||||
{
|
||||
e.update(delta);
|
||||
}
|
||||
}
|
||||
catch (ConcurrentModificationException e)
|
||||
{
|
||||
// We do nothing because nothing can be done ¯\_(ツ)_/¯
|
||||
}
|
||||
}
|
||||
|
||||
public void addEntity(Entity e)
|
||||
{
|
||||
entities.add(e);
|
||||
}
|
||||
|
||||
public void removeEntity(Entity e)
|
||||
{
|
||||
entities.remove(e);
|
||||
}
|
||||
|
||||
public LinkedList<Entity> getEntities()
|
||||
{
|
||||
return this.entities;
|
||||
}
|
||||
|
||||
public boolean allMonstersDead()
|
||||
{
|
||||
for (Entity e : entities)
|
||||
{
|
||||
if (e instanceof EntityMonster)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
54
src/edu/utc/gamedev/Manager/ProjectileManager.java
Normal file
54
src/edu/utc/gamedev/Manager/ProjectileManager.java
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package edu.utc.gamedev.Manager;
|
||||
|
||||
import edu.utc.gamedev.Entity.Projectile.EntityPotatoProjectile;
|
||||
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class ProjectileManager
|
||||
{
|
||||
private LinkedList<EntityPotatoProjectile> projectiles;
|
||||
|
||||
public ProjectileManager()
|
||||
{
|
||||
projectiles = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void drawAll()
|
||||
{
|
||||
for (EntityPotatoProjectile e : projectiles)
|
||||
{
|
||||
e.draw();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAll(float delta)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (EntityPotatoProjectile e : projectiles)
|
||||
{
|
||||
e.update(delta);
|
||||
}
|
||||
}
|
||||
catch (ConcurrentModificationException e)
|
||||
{
|
||||
// We do nothing because nothing can be done ¯\_(ツ)_/¯
|
||||
}
|
||||
}
|
||||
|
||||
public void addProjectile(EntityPotatoProjectile e)
|
||||
{
|
||||
projectiles.add(e);
|
||||
}
|
||||
|
||||
public void removeProjectile(EntityPotatoProjectile e)
|
||||
{
|
||||
projectiles.remove(e);
|
||||
}
|
||||
|
||||
public LinkedList<EntityPotatoProjectile> getProjectiles()
|
||||
{
|
||||
return this.projectiles;
|
||||
}
|
||||
}
|
||||
32
src/edu/utc/gamedev/Manager/SceneManager.java
Normal file
32
src/edu/utc/gamedev/Manager/SceneManager.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package edu.utc.gamedev.Manager;
|
||||
|
||||
|
||||
import edu.utc.gamedev.Scene.SceneLevel;
|
||||
|
||||
public class SceneManager
|
||||
{
|
||||
private static SceneManager instance;
|
||||
private SceneLevel currentSceneLevel;
|
||||
|
||||
public SceneManager()
|
||||
{
|
||||
this.currentSceneLevel = null;
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public static SceneManager getInstance()
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
public SceneLevel getScene()
|
||||
{
|
||||
return this.currentSceneLevel;
|
||||
}
|
||||
|
||||
public void setScene(SceneLevel s)
|
||||
{
|
||||
this.currentSceneLevel = s;
|
||||
}
|
||||
|
||||
}
|
||||
81
src/edu/utc/gamedev/Manager/ScreenshotManager.java
Normal file
81
src/edu/utc/gamedev/Manager/ScreenshotManager.java
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
package edu.utc.gamedev.Manager;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class ScreenshotManager
|
||||
{
|
||||
private File screenshotsFolder;
|
||||
|
||||
public ScreenshotManager()
|
||||
{
|
||||
screenshotsFolder = new File(System.getProperty("user.dir") + File.separator + "screenshots");
|
||||
}
|
||||
|
||||
|
||||
public File getScreenshotsFolder()
|
||||
{
|
||||
return this.screenshotsFolder;
|
||||
}
|
||||
|
||||
public void setScreenshotsFolder(File newFolder)
|
||||
{
|
||||
this.screenshotsFolder = newFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* SOURCE: http://wiki.lwjgl.org/wiki/Taking_Screen_Shots.html
|
||||
*/
|
||||
public void takeScreenshot()
|
||||
{
|
||||
GL11.glReadBuffer(GL11.GL_FRONT);
|
||||
int width = Display.getDisplayMode().getWidth();
|
||||
int height = Display.getDisplayMode().getHeight();
|
||||
int bpp = 4;
|
||||
ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp);
|
||||
GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
if (!this.screenshotsFolder.exists())
|
||||
{
|
||||
this.screenshotsFolder.mkdir();
|
||||
}
|
||||
|
||||
String format = "png";
|
||||
long timestamp = System.currentTimeMillis();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM-dd-yyyy HH mm ss");
|
||||
Date resultdate = new Date(timestamp);
|
||||
File file = new File(this.screenshotsFolder.getAbsolutePath() + File.separator + dateFormat.format(resultdate) + "." + format);
|
||||
System.out.println(file.getAbsolutePath());
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
int i = (x + (width * y)) * bpp;
|
||||
int r = buffer.get(i) & 0xFF;
|
||||
int g = buffer.get(i + 1) & 0xFF;
|
||||
int b = buffer.get(i + 2) & 0xFF;
|
||||
image.setRGB(x, height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ImageIO.write(image, format, file);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.println("Error capturing screenshot");
|
||||
}
|
||||
}
|
||||
}
|
||||
87
src/edu/utc/gamedev/Manager/TileManager.java
Normal file
87
src/edu/utc/gamedev/Manager/TileManager.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
package edu.utc.gamedev.Manager;
|
||||
|
||||
import edu.utc.gamedev.Tile.ITile;
|
||||
import edu.utc.gamedev.Tile.Dungeon.TileDecoration;
|
||||
import edu.utc.gamedev.Tile.Dungeon.TilePlatform;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class TileManager
|
||||
{
|
||||
private LinkedList<ITile> tiles;
|
||||
private LinkedList<TileDecoration> decorations;
|
||||
private LinkedList<TilePlatform> platforms;
|
||||
|
||||
public TileManager()
|
||||
{
|
||||
tiles = new LinkedList<>();
|
||||
decorations = new LinkedList<>();
|
||||
platforms = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void drawAll()
|
||||
{
|
||||
for (ITile t : tiles)
|
||||
{
|
||||
t.draw();
|
||||
}
|
||||
for (TileDecoration t : decorations)
|
||||
{
|
||||
t.draw();
|
||||
}
|
||||
for (TilePlatform t : platforms)
|
||||
{
|
||||
t.draw();
|
||||
t.update();
|
||||
}
|
||||
}
|
||||
|
||||
public void addTile(ITile t)
|
||||
{
|
||||
if (t instanceof TileDecoration)
|
||||
{
|
||||
this.decorations.add((TileDecoration) t);
|
||||
}
|
||||
else if (t instanceof TilePlatform)
|
||||
{
|
||||
this.platforms.add((TilePlatform) t);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tiles.add(t);
|
||||
}
|
||||
}
|
||||
|
||||
public void addAll(Iterable<ITile> tiles)
|
||||
{
|
||||
for (ITile t : tiles)
|
||||
{
|
||||
this.addTile(t);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeTile(ITile t)
|
||||
{
|
||||
this.tiles.remove(t);
|
||||
}
|
||||
|
||||
public void removeDecoration(TileDecoration t)
|
||||
{
|
||||
this.decorations.remove(t);
|
||||
}
|
||||
|
||||
public LinkedList<TileDecoration> getDecorations()
|
||||
{
|
||||
return (LinkedList<TileDecoration>) this.decorations.clone();
|
||||
}
|
||||
|
||||
public void clearDecorations()
|
||||
{
|
||||
this.decorations.clear();
|
||||
}
|
||||
|
||||
public LinkedList<TilePlatform> getPlatforms()
|
||||
{
|
||||
return (LinkedList<TilePlatform>) this.platforms.clone();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue