id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
799a72f8-52a6-4ce1-8a12-1be6baf9f88c | public PlayState(int StateID) {
super();
GameStateID = StateID;
} |
49aba354-6401-4fed-a71b-3e81a4ecf4c1 | @Override
public int getID() {
return GameStateID;
} |
6c7889bf-033f-4235-8161-7c57e5c2c60b | @Override
public void enter(GameContainer container, StateBasedGame game)
throws SlickException {
super.enter(container, game);
if (!container.isMusicOn()) {
if (music != null) {
music.stop();
}
} else {
music = ResourceManager.getInstance().getMusic("horror_tale");
if (music != null) {
music.loop();
}
}
} |
430cb192-caeb-45a4-937c-38782e9617fc | @Override
public void leave(GameContainer container, StateBasedGame game)
throws SlickException {
super.leave(container, game);
if (container.isMusicOn()) {
if (music != null && music.playing())
music.stop();
}
} |
a017120c-14de-47a7-8222-c3a0ab9cf3a5 | public void init(GameContainer container, StateBasedGame game) throws SlickException {
container.setVSync(vsyncOn);
container.setShowFPS(!vsyncOn);
container.setIcons(ICON_REF_ARRAY);
// load tiled map
//map = new BlockMap("data/level01.tmx");
// map = new BlockMap("data/testKarte.tmx");
map = new BlockMap("data/map/Karte_proto.tmx");
// create background image
// background = new Image("data/area02_bkg0.jpg");
// create PlayerEntity
playerOne = new Player("./data/assets/spritesheets/teddy_anim.png", "./data/assets/spritesheets/hat_sheet.png", BlockMap.getPlayerStart());
// get an array of all visible map layers
camera = new Camera(container, BlockMap.tmap, BlockMap.getVisibleLayers());
} |
6d0f53c9-9b7e-476a-94ca-ebda32572c63 | @Override
public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException {
if (container.getInput().isKeyPressed(Input.KEY_ESCAPE))
{
container.exit();
}
/** DEBUG-MODE CHECK INPUT */
if (container.getInput().isKeyPressed(Input.KEY_F2))
{
disregardCollisions = !disregardCollisions;
}
if (container.getInput().isKeyPressed(Input.KEY_F3))
{
drawBoundingBoxes = !drawBoundingBoxes;
}
if (container.getInput().isKeyPressed(Input.KEY_F4))
{
vsyncOn = !vsyncOn;
container.setVSync(vsyncOn);
container.setShowFPS(!vsyncOn);
}
if (container.getInput().isKeyPressed(Input.KEY_F5))
{
playerOne.switchHat();
}
if (container.getInput().isKeyPressed(Input.KEY_C))
{
game.enterState(SideScrollerGame.CREDITS_SCREEN_STATEID,
new FadeOutTransition(Color.white, 1000),
new FadeInTransition(Color.black, 1000)
);
}
/** check if the player is within range to reach any ColorBucket or press any HotButton */
Polygon playerPoly = playerOne.getBoundingPolygon();
// check if there's a button within the players reach
playerOne.setWithinHotButtonReach(false);
for (HotButton button : BlockMap.hotButtonList)
{
if (playerPoly.intersects(button.getShape()) || playerPoly.contains(button.getShape()))
{
playerOne.setWithinHotButtonReach(true);
break;
}
}
// check if there's a button within the players reach
playerOne.setWithinColorBucketReach(false);
for (ColorBucket bucket : BlockMap.colorBucketList)
{
if (playerPoly.intersects(bucket.getShape()) || playerPoly.contains(bucket.getShape()))
{
playerOne.setWithinColorBucketReach(true);
break;
}
}
for (ColorBucket bucket : BlockMap.colorBucketList)
{
bucket.update(delta);
}
// rotate objects
for (RotatableObject rotO : BlockMap.rotatableObjectList)
{
rotO.startRotation();
rotO.update(delta);
}
// move objects
for (MoveableObject movO : BlockMap.moveableObjectList)
{
movO.update(delta);
}
// gravity simulation
final float buf = playerOne.getPosition().y;
final float tempY = buf + delta * grav;
playerPoly.setY(tempY);
grav += 0.00225f;
if (entityCollisionWith(playerPoly))
{
playerPoly.setY(buf);
grav = 0.0f;
} else {
playerOne.setY(tempY);
}
/* Input Handling */
if (handleInput(container.getInput(), delta))
{
playerOne.update(delta);
}
else
{
playerOne.restartAllAnimations();
}
//lock the camera on the player by default (player should be centered by the camera)
//after calculating the positions of all entities
camera.centerOn(playerPoly.getX(), playerPoly.getY());
} |
6287c4d9-1f2a-4b02-8bff-ea2dd333edb1 | private boolean handleInput(Input input, int delta) throws SlickException
{
boolean playerHasMoved = false;
playerOne.setStanding(true);
float playerX = playerOne.getPosition().x;
float playerY = playerOne.getPosition().y;
Polygon playerPoly = playerOne.getBoundingPolygon();
if (input.isKeyDown(Input.KEY_LEFT))
{
playerOne.setMoveDirection(false);
playerX -= 2;
playerPoly.setX(playerX);
if (entityCollisionWith(playerPoly) && !disregardCollisions){
playerX += 2;
playerPoly.setX(playerX);
} else {
playerHasMoved = true;
playerOne.setPosition(playerX, playerY);
}
}
if (input.isKeyDown(Input.KEY_RIGHT))
{
playerOne.setMoveDirection(true);
playerX += 2;
playerPoly.setX(playerX);
if (entityCollisionWith(playerPoly) && !disregardCollisions){
playerX -= 2;
playerPoly.setX(playerX);
} else {
playerHasMoved = true;
playerOne.setPosition(playerX, playerY);
}
}
if (input.isKeyDown(Input.KEY_UP))
{
playerY -= 2;
playerPoly.setY(playerY);
if (entityCollisionWith(playerPoly) && !disregardCollisions){
playerY += 2;
playerPoly.setY(playerY);
grav += 0.005f; // collision with ceiling, add gravity (and get a headache..)
} else {
playerHasMoved = true;
playerOne.setPosition(playerX, playerY);
}
}
if (input.isKeyDown(Input.KEY_DOWN))
{
playerOne.setStanding(false);
playerY += 2;
playerPoly.setY(playerY);
if (entityCollisionWith(playerPoly) && !disregardCollisions){
playerY -= 2;
playerPoly.setY(playerY);
} else {
playerHasMoved = true;
playerOne.setPosition(playerX, playerY);
}
}
if (input.isKeyDown(Input.KEY_RETURN) || input.isKeyDown(Input.KEY_ENTER))
{
if (playerOne.isWithinColorBucketReach())
{
for (ColorBucket bucket : BlockMap.colorBucketList)
{
if (playerPoly.intersects(bucket.getShape()) || playerPoly.contains(bucket.getShape()) )
{
playerOne.setColor(bucket.getColor());
}
}
}
}
playerOne.setPosition(playerX, playerY);
return playerHasMoved;
} |
512e3927-e110-4359-9e7d-f1f594817f4d | public boolean entityCollisionWith(Polygon polygon) throws SlickException {
for (Block entity : BlockMap.collisionBlockList)
{
if (polygon.intersects(entity.poly))
{
return true;
}
}
for (RotatableObject rotO : BlockMap.rotatableObjectList)
{
if(polygon.intersects(rotO.getShape()))
{
return true;
}
}
return false;
} |
2166aad7-e960-4b4d-a545-49fc6ddbb789 | @Override
public void render(GameContainer container, StateBasedGame game, Graphics g)
throws SlickException {
// draw background image
g.fillRect(0.0f, 0.0f, container.getWidth(), container.getHeight());
//background.draw(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
//in the render()-method
camera.drawMap();
// draw information overlay
if (playerOne.isWithinHotButtonReach())
{
final String str = new String("there's a button!");
g.drawString(str, ((container.getWidth() >> 1) - (g.getFont().getWidth(str) >> 1)), 10);
}
if (playerOne.isWithinColorBucketReach())
{
final String str = new String("there's a ColorBucket!!");
g.drawString(str, ((container.getWidth() >> 1) - (g.getFont().getWidth(str) >> 1)), 10);
}
/** --- DEBUG-MODE OVERLAY --- */
final int lineHeight = g.getFont().getLineHeight();
int heightMultiplier = 0;
final String creditStr = new String("press C for credits");
g.drawString(creditStr, ((container.getWidth()) - (g.getFont().getWidth(creditStr))), heightMultiplier * lineHeight);
++heightMultiplier;
if (disregardCollisions)
{
final String str = new String("NoClip mode");
g.drawString(str, ((container.getWidth()) - (g.getFont().getWidth(str))), heightMultiplier * lineHeight);
++heightMultiplier;
}
if (drawBoundingBoxes)
{
final String str = new String("draw BoundingBoxes");
g.drawString(str, ((container.getWidth()) - (g.getFont().getWidth(str))), heightMultiplier * lineHeight);
++heightMultiplier;
}
if (!vsyncOn)
{
final String str = new String("VSync off");
g.drawString(str, ((container.getWidth()) - (g.getFont().getWidth(str))), heightMultiplier * lineHeight);
++heightMultiplier;
}
// re-translate everything, so it will be in its real position
camera.translateGraphics();
/** --- DEBUG-MODE DRAW BOUNDING BOXES --- */
if (drawBoundingBoxes)
{
BlockMap.tmap.render(0, 0, BlockMap.tmap.getLayerIndex("Collision"));
g.setColor(Color.orange);
g.draw(playerOne.getBoundingPolygon());
}
// g.setColor(Color.orange);
// g.setLineWidth(1.0f);
// g.draw(playerOne.getBoundingPolygon());
for (StaticSprite spr : BlockMap.staticSpriteList)
{
spr.draw(g);
}
for (HotButton button : BlockMap.hotButtonList)
{
button.draw(g);
if (drawBoundingBoxes) { g.draw(button.getShape()); }
}
for (ColorBucket bucket : BlockMap.colorBucketList)
{
bucket.draw(g);
if (drawBoundingBoxes) { g.draw(bucket.getShape()); }
}
for (RotatableObject rotO : BlockMap.rotatableObjectList)
{
rotO.draw(g);
if (drawBoundingBoxes) { g.draw(rotO.getShape()); }
}
for (MoveableObject movO : BlockMap.moveableObjectList)
{
movO.draw(g);
if (drawBoundingBoxes) { g.draw(movO.getShape()); }
}
// render player animation
playerOne.drawAnimation();
/** minimap - not functional... */
//
// g.setColor(Color.pink);
// g.fillRect(miniMapRect.getMinX(), miniMapRect.getMinY(), miniMapRect.getMaxX(), miniMapRect.getMaxY());
//
// camera.untranslateGraphics();
// g.pushTransform();
//
// float scaleX = (float)(container.getWidth() >> 2) / (float)(container.getWidth());
// float scaleY = (float)(container.getHeight() >> 2) / (float)container.getHeight();
// int miniMapPosX = (int)(container.getWidth() - (container.getWidth() * scaleX));
// g.scale(scaleX, scaleY);
// camera.centerOn(miniMapRect);
// camera.drawMap();
// camera.centerOn(playerOne.getBoundingPolygon());
//
// g.popTransform();
// camera.translateGraphics();
// reset graphics device
g.setColor(Color.white);
g.resetLineWidth();
g.resetTransform();
g.resetFont();
} |
d61d3856-ff6f-42ee-9bb8-57df71940bf2 | public ArrayList<String>[] getCustomizablesListArray() {
return customizablesListArray;
} |
ed4ed25c-6224-4eb6-ba37-75183b333fc0 | private ResourceManager(){
soundMap = new HashMap<String, Sound>();
musicMap = new HashMap<String, Music>();
imageMap = new HashMap<String, Image>();
textMap = new HashMap<String, String>();
animationMap = new HashMap<String, Animation>();
for (int i=0; i<6; ++i) {
customizablesListArray[i] = new ArrayList<String>();
}
} |
140ca9d0-3e71-416a-92a2-bd1109623598 | public final static ResourceManager getInstance(){
return _instance;
} |
40685591-4827-4983-9e37-cd2a11fa1f9a | public void loadResources(InputStream is) throws SlickException {
loadResources(is, false);
} |
8c5587f2-2b5e-4f9e-9068-2270b3ad66b8 | public void loadResources(InputStream is, boolean deferred) throws SlickException {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = null;
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new SlickException("Could not load resources", e);
}
Document doc = null;
try {
doc = docBuilder.parse (is);
} catch (SAXException e) {
throw new SlickException("Could not load resources", e);
} catch (IOException e) {
throw new SlickException("Could not load resources", e);
}
// normalize text representation
doc.getDocumentElement().normalize();
NodeList listResources = doc.getElementsByTagName("resource");
int totalResources = listResources.getLength();
if(deferred){
LoadingList.setDeferredLoading(true);
}
for(int resourceIdx = 0; resourceIdx < totalResources; resourceIdx++){
Node resourceNode = listResources.item(resourceIdx);
if(resourceNode.getNodeType() == Node.ELEMENT_NODE){
Element resourceElement = (Element)resourceNode;
String type = resourceElement.getAttribute("type");
if(type.startsWith("image")){
addElementAsImage(resourceElement, type);
}else if(type.startsWith("animation")){
addElementAsAnimation(resourceElement, type);
}else if(type.equals("sound")){
addElementAsSound(resourceElement);
}else if(type.equals("music")){
addElementAsMusic(resourceElement);
}else if(type.equals("text")){
addElementAsText(resourceElement);
}else if(type.equals("font")){
//fonts can only be loaded directly, not deferred
}
}
}
} |
95248c1c-617a-4fba-a524-746fbf0dbecb | private void addElementAsText(Element resourceElement) throws SlickException{
loadText(resourceElement.getAttribute("id"), resourceElement.getTextContent());
} |
f67f1873-39d8-4a2d-8ebe-58a2586f806f | public String loadText(String id, String value) throws SlickException{
if(value == null)
throw new SlickException("Text resource [" + id + "] has invalid value");
textMap.put(id, value);
return value;
} |
5f385bbb-9d2f-441d-a85c-df028e72d81f | public String getText(String ID) {
return textMap.get(ID);
} |
7b64fec3-c5fc-4e18-a22f-e13784af8824 | private void addElementAsSound(Element resourceElement) throws SlickException {
loadSound(resourceElement.getAttribute("id"), resourceElement.getTextContent());
} |
db8f232e-cc66-4dba-b5c1-668e732118c3 | public Sound loadSound(String id, String path) throws SlickException{
if(path == null || path.length() == 0)
throw new SlickException("Sound resource [" + id + "] has invalid path");
Sound sound = null;
try {
sound = new Sound(path);
} catch (SlickException e) {
throw new SlickException("Could not load sound", e);
}
this.soundMap.put(id, sound);
return sound;
} |
67b6fbd0-fe88-449c-83df-674c64330fec | public final Sound getSound(String ID){
return soundMap.get(ID);
} |
fa8e13eb-5d81-4ed7-b551-d040ba1b7299 | private void addElementAsMusic(Element resourceElement) throws SlickException {
loadMusic(resourceElement.getAttribute("id"), resourceElement.getTextContent());
} |
2c92e895-903d-448e-a826-b917336a8280 | public Music loadMusic(String id, String path) throws SlickException{
if(path == null || path.length() == 0)
throw new SlickException("Music resource [" + id + "] has invalid path");
Music music = null;
try {
music = new Music(path);
} catch (SlickException e) {
throw new SlickException("Could not load music", e);
}
this.musicMap.put(id, music);
customizablesListArray[5].add(id);
return music;
} |
3ae215c1-4435-41ee-8f73-42f43fc7a0a1 | public final Music getMusic(String ID){
return musicMap.get(ID);
} |
2a8fbcd8-6b7e-477c-aa22-20c9afadbf5f | private void addElementAsAnimation(Element resourceElement, String type) throws SlickException{
loadAnimation(resourceElement.getAttribute("id"), resourceElement.getTextContent(),
Integer.valueOf(resourceElement.getAttribute("tw")),
Integer.valueOf(resourceElement.getAttribute("th")),
Integer.valueOf(resourceElement.getAttribute("duration")),
Boolean.valueOf(resourceElement.getAttribute("flipped")),
type);
} |
de405a12-f98c-4378-a0af-a1a888e286e9 | private void loadAnimation(String id, String spriteSheetPath, int tw, int th, int duration, boolean flipped, String type) throws SlickException{
// type is declared after the slash "/" within resources.xml
if(spriteSheetPath == null || spriteSheetPath.length() == 0)
throw new SlickException("Image resource [" + id + "] has invalid path");
final SpriteSheet animationSheet = new SpriteSheet(spriteSheetPath, tw, th);
Animation anim = new Animation();
for (int frame = 0; frame < animationSheet.getHorizontalCount(); ++frame)
{
if (flipped)
{
anim.addFrame(animationSheet.getSprite(frame, 0).getFlippedCopy(true, false), duration);
}
else
{
anim.addFrame(animationSheet.getSprite(frame, 0), duration);
}
}
animationMap.put(id, anim);
} |
5f348410-b1e7-4892-8572-e05464eec0be | private final void addElementAsImage(Element resourceElement, String type) throws SlickException {
loadImage(resourceElement.getAttribute("id"), resourceElement.getTextContent(), type);
} |
167908f5-7bcd-4f00-acff-346380c079f1 | public Image loadImage(String id, String path, String type) throws SlickException{
if(path == null || path.length() == 0)
throw new SlickException("Image resource [" + id + "] has invalid path");
Image image = null;
try{
image = new Image(path);
} catch (SlickException e) {
throw new SlickException("Could not load image", e);
}
this.imageMap.put(id, image);
insertImageIdIntoCorrespondingList(id, type);
return image;
} |
ddafd95d-bfaa-44f0-bb43-4ced85fa40ee | public final Image getImage(String ID){
return imageMap.get(ID);
} |
1c64c5ff-2d93-49d3-9c1e-573849f92845 | private final void insertImageIdIntoCorrespondingList(String id, String type) {
if(type.endsWith("bg")){
customizablesListArray[0].add(id);
}else if(type.endsWith("border")){
customizablesListArray[1].add(id);
}else if(type.endsWith("brick")){
customizablesListArray[2].add(id);
}else if(type.endsWith("paddle")){
customizablesListArray[3].add(id);
}else if(type.endsWith("ball")){
customizablesListArray[4].add(id);
}
} |
467fb82c-ef71-4b25-b968-7619283d40f1 | public SideScrollerGame(String title) {
super(title);
this.addState(new LoadingScreenState(LOADING_SCREEN_STATEID));
this.addState(new CreditsScreenState(CREDITS_SCREEN_STATEID));
this.addState(new PlayState(PLAY_STATEID));
this.enterState(LOADING_SCREEN_STATEID);
} |
186e305f-48c1-4c57-9a40-31d15b807371 | @Override
public void initStatesList(GameContainer container) throws SlickException {
this.getState(LOADING_SCREEN_STATEID).init(container, this);
this.getState(CREDITS_SCREEN_STATEID).init(container, this);
this.getState(PLAY_STATEID).init(container, this);
} |
1f6cc816-20b8-4f90-a0d9-711a3cbb8058 | public static void main(String[] args) throws SlickException {
AppGameContainer app = new AppGameContainer(new SideScrollerGame(GAME_TITLE));
app.setVSync(WAIT_FOR_VSYNC);
app.setSmoothDeltas(true);
app.setTargetFrameRate(60);
app.setShowFPS(false);
app.setUpdateOnlyWhenVisible(true);
app.setMusicOn(MUSIC_ON_OFF);
app.setSoundOn(SOUND_ON_OFF);
if (app.supportsMultiSample())
app.setMultiSample(2);
app.setDisplayMode(800, 600, FULLSCREEN);
app.start();
} |
23d7f4ff-efe7-4a8a-a92c-9e07d9ffb8dd | public Game() {
super(GAME_TITLE);
} |
81423bfa-f41a-43c5-8786-454f4a223ded | public void init(GameContainer container) throws SlickException {
container.setVSync(vsyncOn);
container.setShowFPS(!vsyncOn);
container.setIcons(ICON_REF_ARRAY);
// load tiled map
//map = new BlockMap("data/level01.tmx");
// map = new BlockMap("data/testKarte.tmx");
map = new BlockMap("data/map/Karte_proto.tmx");
// create background image
// background = new Image("data/area02_bkg0.jpg");
// create PlayerEntity
playerOne = new Player("./data/assets/spritesheets/teddy_anim.png", "./data/assets/spritesheets/hat_sheet.png", BlockMap.getPlayerStart());
// get an array of all visible map layers
camera = new Camera(container, BlockMap.tmap, BlockMap.getVisibleLayers());
} |
1e731398-eef4-4b1e-ab7d-ef9fc2bbe6b0 | public void update(GameContainer container, int delta) throws SlickException {
if (container.getInput().isKeyPressed(Input.KEY_ESCAPE))
{
container.exit();
}
/** DEBUG-MODE CHECK INPUT */
if (container.getInput().isKeyPressed(Input.KEY_F2))
{
disregardCollisions = !disregardCollisions;
}
if (container.getInput().isKeyPressed(Input.KEY_F3))
{
drawBoundingBoxes = !drawBoundingBoxes;
}
if (container.getInput().isKeyPressed(Input.KEY_F4))
{
vsyncOn = !vsyncOn;
container.setVSync(vsyncOn);
container.setShowFPS(!vsyncOn);
}
if (container.getInput().isKeyPressed(Input.KEY_F5))
{
playerOne.switchHat();
}
/** check if the player is within range to reach any ColorBucket or press any HotButton */
Polygon playerPoly = playerOne.getBoundingPolygon();
// check if there's a button within the players reach
playerOne.setWithinHotButtonReach(false);
for (HotButton button : BlockMap.hotButtonList)
{
if (playerPoly.intersects(button.getShape()) || playerPoly.contains(button.getShape()))
{
playerOne.setWithinHotButtonReach(true);
break;
}
}
// check if there's a button within the players reach
playerOne.setWithinColorBucketReach(false);
for (ColorBucket bucket : BlockMap.colorBucketList)
{
if (playerPoly.intersects(bucket.getShape()) || playerPoly.contains(bucket.getShape()))
{
playerOne.setWithinColorBucketReach(true);
break;
}
}
for (ColorBucket bucket : BlockMap.colorBucketList)
{
bucket.update(delta);
}
// rotate objects
for (RotatableObject rotO : BlockMap.rotatableObjectList)
{
rotO.startRotation();
rotO.update(delta);
}
// move objects
for (MoveableObject movO : BlockMap.moveableObjectList)
{
movO.update(delta);
}
// gravity simulation
final float buf = playerOne.getPosition().y;
final float tempY = buf + delta * grav;
playerPoly.setY(tempY);
grav += 0.00225f;
if (entityCollisionWith(playerPoly))
{
playerPoly.setY(buf);
grav = 0.0f;
} else {
playerOne.setY(tempY);
}
/* Input Handling */
if (handleInput(container.getInput(), delta))
{
playerOne.update(delta);
}
else
{
playerOne.restartAllAnimations();
}
//lock the camera on the player by default (player should be centered by the camera)
//after calculating the positions of all entities
camera.centerOn(playerPoly.getX(), playerPoly.getY());
} |
20f0b83b-a849-4d9f-a03f-6b947a1946af | private boolean handleInput(Input input, int delta) throws SlickException
{
boolean playerHasMoved = false;
playerOne.setStanding(true);
float playerX = playerOne.getPosition().x;
float playerY = playerOne.getPosition().y;
Polygon playerPoly = playerOne.getBoundingPolygon();
if (input.isKeyDown(Input.KEY_LEFT))
{
playerOne.setMoveDirection(false);
playerX -= 2;
playerPoly.setX(playerX);
if (entityCollisionWith(playerPoly) && !disregardCollisions){
playerX += 2;
playerPoly.setX(playerX);
} else {
playerHasMoved = true;
playerOne.setPosition(playerX, playerY);
}
}
if (input.isKeyDown(Input.KEY_RIGHT))
{
playerOne.setMoveDirection(true);
playerX += 2;
playerPoly.setX(playerX);
if (entityCollisionWith(playerPoly) && !disregardCollisions){
playerX -= 2;
playerPoly.setX(playerX);
} else {
playerHasMoved = true;
playerOne.setPosition(playerX, playerY);
}
}
if (input.isKeyDown(Input.KEY_UP))
{
playerY -= 2;
playerPoly.setY(playerY);
if (entityCollisionWith(playerPoly) && !disregardCollisions){
playerY += 2;
playerPoly.setY(playerY);
grav += 0.005f; // collision with ceiling, add gravity (and get a headache..)
} else {
playerHasMoved = true;
playerOne.setPosition(playerX, playerY);
}
}
if (input.isKeyDown(Input.KEY_DOWN))
{
playerOne.setStanding(false);
playerY += 2;
playerPoly.setY(playerY);
if (entityCollisionWith(playerPoly) && !disregardCollisions){
playerY -= 2;
playerPoly.setY(playerY);
} else {
playerHasMoved = true;
playerOne.setPosition(playerX, playerY);
}
}
if (input.isKeyDown(Input.KEY_RETURN) || input.isKeyDown(Input.KEY_ENTER))
{
if (playerOne.isWithinColorBucketReach())
{
for (ColorBucket bucket : BlockMap.colorBucketList)
{
if (playerPoly.intersects(bucket.getShape()) || playerPoly.contains(bucket.getShape()) )
{
playerOne.setColor(bucket.getColor());
}
}
}
}
playerOne.setPosition(playerX, playerY);
return playerHasMoved;
} |
839259bc-8f65-4b91-92cf-009d6c378ee3 | public boolean entityCollisionWith(Polygon polygon) throws SlickException {
for (Block entity : BlockMap.collisionBlockList)
{
if (polygon.intersects(entity.poly))
{
return true;
}
}
for (RotatableObject rotO : BlockMap.rotatableObjectList)
{
if(polygon.intersects(rotO.getShape()))
{
return true;
}
}
return false;
} |
36a363c3-5ded-4de9-a405-5564cd3073cf | public void render(GameContainer container, Graphics g) {
// draw background image
g.fillRect(0.0f, 0.0f, container.getWidth(), container.getHeight());
//background.draw(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
//in the render()-method
camera.drawMap();
// draw information overlay
if (playerOne.isWithinHotButtonReach())
{
final String str = new String("there's a button!");
g.drawString(str, ((container.getWidth() >> 1) - (g.getFont().getWidth(str) >> 1)), 10);
}
if (playerOne.isWithinColorBucketReach())
{
final String str = new String("there's a ColorBucket!!");
g.drawString(str, ((container.getWidth() >> 1) - (g.getFont().getWidth(str) >> 1)), 10);
}
/** --- DEBUG-MODE OVERLAY --- */
final int lineHeight = g.getFont().getLineHeight();
int heightMultiplier = 0;
if (disregardCollisions)
{
final String str = new String("NoClip mode");
g.drawString(str, ((container.getWidth()) - (g.getFont().getWidth(str))), heightMultiplier * lineHeight);
++heightMultiplier;
}
if (drawBoundingBoxes)
{
final String str = new String("draw BoundingBoxes");
g.drawString(str, ((container.getWidth()) - (g.getFont().getWidth(str))), heightMultiplier * lineHeight);
++heightMultiplier;
}
if (!vsyncOn)
{
final String str = new String("VSync off");
g.drawString(str, ((container.getWidth()) - (g.getFont().getWidth(str))), heightMultiplier * lineHeight);
++heightMultiplier;
}
// re-translate everything, so it will be in its real position
camera.translateGraphics();
/** --- DEBUG-MODE DRAW BOUNDING BOXES --- */
if (drawBoundingBoxes)
{
BlockMap.tmap.render(0, 0, BlockMap.tmap.getLayerIndex("Collision"));
g.setColor(Color.orange);
g.draw(playerOne.getBoundingPolygon());
}
// g.setColor(Color.orange);
// g.setLineWidth(1.0f);
// g.draw(playerOne.getBoundingPolygon());
for (StaticSprite spr : BlockMap.staticSpriteList)
{
spr.draw(g);
}
for (HotButton button : BlockMap.hotButtonList)
{
button.draw(g);
if (drawBoundingBoxes) { g.draw(button.getShape()); }
}
for (ColorBucket bucket : BlockMap.colorBucketList)
{
bucket.draw(g);
if (drawBoundingBoxes) { g.draw(bucket.getShape()); }
}
for (RotatableObject rotO : BlockMap.rotatableObjectList)
{
rotO.draw(g);
if (drawBoundingBoxes) { g.draw(rotO.getShape()); }
}
for (MoveableObject movO : BlockMap.moveableObjectList)
{
movO.draw(g);
if (drawBoundingBoxes) { g.draw(movO.getShape()); }
}
// render player animation
playerOne.drawAnimation();
/** minimap - not functional... */
//
// g.setColor(Color.pink);
// g.fillRect(miniMapRect.getMinX(), miniMapRect.getMinY(), miniMapRect.getMaxX(), miniMapRect.getMaxY());
//
// camera.untranslateGraphics();
// g.pushTransform();
//
// float scaleX = (float)(container.getWidth() >> 2) / (float)(container.getWidth());
// float scaleY = (float)(container.getHeight() >> 2) / (float)container.getHeight();
// int miniMapPosX = (int)(container.getWidth() - (container.getWidth() * scaleX));
// g.scale(scaleX, scaleY);
// camera.centerOn(miniMapRect);
// camera.drawMap();
// camera.centerOn(playerOne.getBoundingPolygon());
//
// g.popTransform();
// camera.translateGraphics();
// reset graphics device
g.setColor(Color.white);
g.resetLineWidth();
g.resetTransform();
g.resetFont();
} |
10caafa4-b8e9-4e31-94d9-504482aa10ae | public static void main(String[] argv) throws SlickException {
AppGameContainer container =
new AppGameContainer(new Game(), SCREEN_WIDTH, SCREEN_HEIGHT, false);
container.start();
} |
e33da940-33ca-4135-ae3e-318b2195b3f1 | public ColorBucket(String sheetRef, String overlaySheetRef, int[] cycles, int tileWidth, int tileHeigth, boolean flipped, Vector2f position, Color color) {
super(null, color);
this.position = position;
this.color = color;
// initialize Animation array
for (int i = 0; i < bucket.length; ++i)
{
bucket[i] = new Animation();
bucket[i].setAutoUpdate(false);
}
try {
if ( (sheetRef != null ) && overlaySheetRef != null)
{
final SpriteSheet spritesheet = new SpriteSheet(sheetRef, tileWidth, tileHeigth);
final SpriteSheet overlaySheet = new SpriteSheet(overlaySheetRef, tileWidth, tileHeigth);
for (int frame = 0; frame < spritesheet.getHorizontalCount(); ++frame)
{
if (flipped)
{
bucket[0].addFrame(spritesheet.getSprite(frame, 0).getFlippedCopy(true, false), 150);
bucket[1].addFrame(overlaySheet.getSprite(frame, 0).getFlippedCopy(true, false), 150);
}
else
{
bucket[0].addFrame(spritesheet.getSprite(frame, 0), 150);
bucket[1].addFrame(overlaySheet.getSprite(frame, 0), 150);
}
}
}
else
{
final Image defaultImage = new Image(PlayState.DEFAULT_IMAGE_PATH);
bucket[0].addFrame(defaultImage, 1);
bucket[1].addFrame(defaultImage, 1);
}
// collision geometry
this.shape = new Rectangle(this.position.x, this.position.y, bucket[0].getWidth(), bucket[0].getHeight());
}
catch (SlickException e)
{
e.printStackTrace();
for (int i = 0; i < bucket.length; ++i)
{
bucket[i] = null;
}
this.shape = new Rectangle(this.position.x, this.position.y, 10, 10);
}
} |
1cd5dcce-9f44-45e4-8604-cae6d983837d | @Override
public void update(long delta)
{
bucket[0].update(delta);
bucket[1].update(delta);
} |
ab7c1714-7064-4d98-8356-ea3e9a4433d0 | @Override
public void draw(Graphics g)
{
bucket[0].draw(this.position.x, this.position.y);
bucket[1].draw(this.position.x, this.position.y, color);
} |
88d6023d-222c-47b4-ac33-53cd94dbb053 | public Color getColor() { return color; } |
6af7046f-2579-4d59-a86c-13a3dd527a66 | public HotButton(String baseImageRef, String overlayImageRef, Vector2f position, Color color, String triggeredEntity)
{
super(null, color);
isPressed = false;
this.position = position;
try {
if (triggeredEntity != null)
{
this.triggeredEntity = triggeredEntity;
}
else
{
throw new SlickException("Dieser Schalter triggert keine Entity!");
}
button[0] = new Image(baseImageRef);
button[1] = new Image(overlayImageRef);
shape = new Rectangle(this.position.x, this.position.y, button[0].getWidth(), button[0].getHeight());
} catch (SlickException e) {
e.printStackTrace();
button[0] = null;
button[1] = null;
shape = new Rectangle(this.position.x, this.position.y, 10, 10);
}
} |
3b19040d-daf0-4a1a-85ca-9ef1f32940ba | @Override
public void update(long delta) {
// TODO Auto-generated method stub
} |
6cf7e3ac-0c6c-4ce5-85f2-ce3a90c5c2f4 | @Override
public void draw(Graphics g)
{
if ((button[0] != null) && (button[1] != null))
{
g.drawImage(button[0], position.x, position.y);
g.drawImage(button[1], position.x, position.y, color);
}
else
{
g.draw(shape);
}
} |
6938c8bc-96e0-4222-b9f6-1e6b12f926f0 | public boolean isPressed() { return this.isPressed; } |
603ceb80-d02e-41cd-836f-22aefe1800c7 | public void press()
{
if (!isPressed)
{
isPressed = true;
//search for triggered Entity....
}
} |
f63f5c91-07c9-4bfd-8273-4fe2316f9108 | public StaticSprite(String imageRef, Vector2f position, Color color) {
super(null, color);
this.position = position;
this.color = color;
try {
this.image = new Image(imageRef);
this.shape = new Rectangle(this.position.x, this.position.y, this.image.getWidth(), this.image.getHeight());
} catch (SlickException e) {
e.printStackTrace();
this.image = null;
this.shape = new Rectangle(this.position.x, this.position.y, 10, 10);
}
} |
b382b9c4-9e7a-4539-b3de-01e643441de2 | @Override
public void update(long delta) { } |
33de9939-07ef-4e32-88a1-67c39c52d334 | @Override
public void draw(Graphics g)
{
if (image != null)
{
g.drawImage(image, position.x, position.y);
}
else
{
g.draw(shape);
}
} |
00f2cc6c-3a6f-4292-953d-7f0613737469 | public RotatableObject(Shape s, Color color, float pivotX, float pivotY, float acceleration, MovementDirection direction, String triggeredBy) {
super(s, color);
isRotating = false;
angle = 0.0f;
this.acceleration = acceleration;
this.direction = direction;
this.triggeredBy = triggeredBy;
if ((pivotX >= 0.0f) && (pivotY >= 0.0f)
&& (pivotX <= 1.0f) && (pivotY <= 1.0f))
{
pivotPoint = new Vector2f(s.getMinX() + pivotX * s.getWidth(), s.getMinY() + pivotY * s.getHeight());
}
else
{
pivotPoint = new Vector2f(s.getMinX(), s.getMinY());
}
} |
5400b03c-825f-43aa-ad4c-3c62298819fb | @Override
public void update(long delta) {
if (isRotating)
{
angle = (angle + delta * acceleration) / 360.0f;
if (direction.equals(MovementDirection.RIGHT))
{
shape = shape.transform(Transform.createRotateTransform(-angle, pivotPoint.x, pivotPoint.y));
}
else if(direction.equals(MovementDirection.LEFT))
{
shape = shape.transform(Transform.createRotateTransform(angle, pivotPoint.x, pivotPoint.y));
}
}
} |
0c62c2c1-4fd8-423a-8a3b-14b7b4eede0a | public void startRotation() { isRotating = true; } |
61b6667a-da3a-4afe-9bdb-d07388c79ac2 | public void stopRotation() { isRotating = false; } |
e9ed6a69-026e-45c7-bc18-9dc722a856e1 | public Enemy(Shape s) {
super(s, new Color(0xAA, 0x00, 0x7F));
} |
4a56c8e2-515d-46aa-aeb6-d4221cf35b9b | public Enemy(float[] points) {
this(new Polygon(points));
} |
3e69711b-f9c8-4426-93ad-abbb9d8dc3af | @Override
public void update(long delta) {
// TODO Auto-generated method stub
} |
a9b1a401-de89-44e4-b328-09b2429cc397 | public MoveableObject(Shape s, Vector2f minPosition, Vector2f maxPosition, float acceleration, MovementDirection initialDirection)
{
super(s, new Color(0xFF, 0x00, 0x00));
this.minPosition = new Vector2f(minPosition);
this.maxPosition = new Vector2f(maxPosition);
this.acceleration = acceleration;
direction = initialDirection;
} |
a1d12a15-344b-487d-8107-37fe2220f6bd | @Override
public void update(long delta)
{
if (direction.equals(MovementDirection.RIGHT))
{
shape.setX(shape.getX() + acceleration * delta);
if (shape.getX() > maxPosition.x)
{
shape.setX(maxPosition.x);
direction = MovementDirection.LEFT;
}
}
else if (direction.equals(MovementDirection.LEFT))
{
shape.setX(shape.getX() - acceleration * delta);
if (shape.getX() < minPosition.x)
{
shape.setX(minPosition.x);
direction = MovementDirection.RIGHT;
}
}
if (direction.equals(MovementDirection.UP))
{
shape.setY(shape.getY() + acceleration * delta);
if (shape.getY() >= maxPosition.y)
{
shape.setY(maxPosition.y);
direction = MovementDirection.DOWN;
}
}
else if (direction.equals(MovementDirection.DOWN))
{
shape.setY(shape.getY() - acceleration * delta);
if (shape.getY() <= minPosition.y)
{
shape.setY(minPosition.y);
direction = MovementDirection.UP;
}
}
} |
beb51a77-0161-4c3a-9674-b1286d80ca20 | public GameObject(Shape s, Color color)
{
super();
this.shape = s;
this.color = color;
if (this.shape != null)
{
this.shapeFill =
new GradientFill( s.getX(), s.getY(), Color.lightGray,
s.getMaxX(), s.getMaxY(), color);
}
}; |
a03ad538-0e01-44d1-a3cc-77053bd9666a | public abstract void update (long delta); |
6a9bf541-d918-458b-b56b-b1ec196913f2 | public void draw(Graphics g)
{
if (this.shape != null)
{
g.fill(shape, shapeFill);
g.draw(shape, shapeFill);
}
} |
815336fa-0b02-4a04-9f20-4fa1d785f64b | public Color getColor() { return color; } |
3d5f0712-6799-49c6-b4b3-115f95fabdd8 | public Shape getShape() { return shape; } |
8f1a2fa1-8b1b-44a7-9e25-5fdcc858107c | public Block(int x, int y, int test[], String type) {
poly = new Polygon(new float[]{
x+test[0], y+test[1],
x+test[2], y+test[3],
x+test[4], y+test[5],
x+test[6], y+test[7],
});
} |
f92f4233-f3d5-4c78-9c75-8b26af6b8d2b | public void update(int delta) {
} |
05a08a2c-e1e7-455a-bc66-59f55b057d94 | public void translate(float cameraX, float cameraY)
{
poly.setLocation(poly.getX() + cameraX, poly.getY() + cameraY);
} |
83ef3342-c095-49ea-afde-87bfa0c3fd2f | public void draw(Graphics g) {
g.draw(poly);
} |
5a7c75fc-abf8-4e27-af21-ed41b1c1153e | public static Vector2f getPlayerStart()
{
return playerStartVector;
} |
5e5495c0-5b97-447d-9ee2-3a4ba9faac21 | public static Integer[] getVisibleLayers()
{
return visibleLayers.clone();
} |
2999b0b1-c66e-4658-b6a0-78ecb449b595 | public BlockMap(String ref) throws SlickException {
// ArrayList initializations
collisionBlockList = new ArrayList<Block>();
hotButtonList = new ArrayList<HotButton>();
colorBucketList = new ArrayList<ColorBucket>();
rotatableObjectList = new ArrayList<RotatableObject>();
moveableObjectList = new ArrayList<MoveableObject>();
staticSpriteList = new ArrayList<StaticSprite>();
tmap = new TiledMap(ref, "data/map");
mapWidth = tmap.getWidth() * tmap.getTileWidth();
mapHeight = tmap.getHeight() * tmap.getTileHeight();
// create an ArrayList of all visible layers
ArrayList<Integer> tempList = new ArrayList<Integer>();
for (int i = 0; i < tmap.getLayerCount(); ++i)
{
if ("false".equals(tmap.getLayerProperty(i, "invisible", "false")))
{
tempList.add(i);
}
}
// cast this ArrayList to an Array of Integer
tempList.trimToSize();
visibleLayers = new Integer[tempList.size()];
tempList.toArray(visibleLayers);
tempList.clear();
// check for the layer named "Collision" (case-sensitive) and create collision geometry
final int layerIndex = tmap.getLayerIndex("Collision");
for (int x = 0; x < tmap.getWidth(); ++x) {
for (int y = 0; y < tmap.getHeight(); ++y) {
int tileID = tmap.getTileId(x, y, layerIndex); // layerIndex == collision layer
if (tileID == 1) {
collisionBlockList.add( new Block(x * 16, y * 16, square, "square") );
}
}
}
for (int groupID = 0; groupID < tmap.getObjectGroupCount(); ++groupID)
{
for (int objectID = 0; objectID < tmap.getObjectCount(groupID); ++objectID)
{
final String type = tmap.getObjectType(groupID, objectID);
// if/else für alle Objekttypen
if (type.equals("PlayerStart"))
{
playerStartVector = new Vector2f(
tmap.getObjectX(groupID, objectID),
tmap.getObjectY(groupID, objectID) //+ tmap.getObjectHeight(groups, count)
);
}
else if (type.equals("HotButton"))
{
final Vector2f position = new Vector2f(tmap.getObjectX(groupID, objectID), tmap.getObjectY(groupID, objectID));
final Color color = new Color(Color.decode(tmap.getObjectProperty(groupID, objectID, "color", "0x00000")));
final String entityRef = tmap.getObjectProperty(groupID, objectID, "Switch.targetEntity", null);
final String baseImageRef = tmap.getObjectProperty(groupID, objectID, "OverlayedAnimatedSprite.baseSpritesheet", null);
final String overlayImageRef = tmap.getObjectProperty(groupID, objectID, "OverlayedAnimatedSprite.overlaySpritesheet1", null);
hotButtonList.add(new HotButton(baseImageRef, overlayImageRef, position, color, entityRef));
}
else if (type.equals("ColorBucket"))
{
final Vector2f position = new Vector2f(tmap.getObjectX(groupID, objectID), tmap.getObjectY(groupID, objectID));
final String sheetRef = tmap.getObjectProperty(groupID, objectID, "OverlayedAnimatedSprite.baseSpritesheet", null);
final String overlaySheetRef = tmap.getObjectProperty(groupID, objectID, "OverlayedAnimatedSprite.overlaySpritesheet1", null);
final boolean flipped = "true".equals(tmap.getObjectProperty(groupID, objectID, "OverlayedAnimatedSprite.flipped", "false"));
final int[] cycles = new int[]
{
Integer.parseInt(tmap.getObjectProperty(groupID, objectID, "OverlayedAnimatedSprite.cycleLength", "1").substring(0, 1)),
Integer.parseInt(tmap.getObjectProperty(groupID, objectID, "OverlayedAnimatedSprite.cycleLength", "1").substring(2, 3))
};
final int tileWidth = Integer.parseInt(tmap.getObjectProperty(groupID, objectID, "OverlayedAnimatedSprite.tileWidth", "1"));
final int tileHeight = Integer.parseInt(tmap.getObjectProperty(groupID, objectID, "OverlayedAnimatedSprite.tileHeight", "1"));
final Color color = new Color(Color.decode(tmap.getObjectProperty(groupID, objectID, "color", "0xCCCCCC")));
colorBucketList.add(new ColorBucket(sheetRef, overlaySheetRef, cycles, tileWidth, tileHeight, flipped, position, color));
}
else if (type.equals("MoveableObject"))
{
final int x = tmap.getObjectX(groupID, objectID)+1;
final int y = tmap.getObjectY(groupID, objectID)+1;
final int x_max = x + tmap.getObjectWidth(groupID, objectID)-1;
final int y_max = y + tmap.getObjectHeight(groupID, objectID)-1;
final float box[] = {x,y, x_max,y, x_max,y_max, x,y_max};
final Polygon p = new Polygon(box);
final Vector2f minPosition = new Vector2f(16 * Float.parseFloat(tmap.getObjectProperty(groupID, objectID, "minPositionX", "0")),
16 * Float.parseFloat(tmap.getObjectProperty(groupID, objectID, "minPositionY", "0")));
final Vector2f maxPosition = new Vector2f(16 * Float.parseFloat(tmap.getObjectProperty(groupID, objectID, "maxPositionX", "0")),
16 * Float.parseFloat(tmap.getObjectProperty(groupID, objectID, "maxPositionY", "0")));
final float acceleration = Float.parseFloat(tmap.getObjectProperty(groupID, objectID, "acceleration", "0"));
final MovementDirection initialDirection = MovementDirection.valueOf(tmap.getObjectProperty(groupID, objectID, "initialDirection", "NONE"));
moveableObjectList.add(new MoveableObject(p, minPosition, maxPosition, acceleration, initialDirection));
}
else if (type.equals("RotatableObject"))
{
final int x = tmap.getObjectX(groupID, objectID)+1;
final int y = tmap.getObjectY(groupID, objectID)+1;
final int x_max = x + tmap.getObjectWidth(groupID, objectID)-1;
final int y_max = y + tmap.getObjectHeight(groupID, objectID)-1;
final float box[] = {x,y, x_max,y, x_max,y_max, x,y_max};
final Polygon p = new Polygon(box);
final Color color = new Color(Color.decode(tmap.getObjectProperty(groupID, objectID, "color", "0x00000")));
//final float pivotX = x_max * Float.parseFloat(tmap.getObjectProperty(groups, count, "pivotX", "0"));
//final float pivotY = y_max * Float.parseFloat(tmap.getObjectProperty(groups, count, "pivotY", "0"));
final float pivotX = Float.parseFloat(tmap.getObjectProperty(groupID, objectID, "pivotX", "0"));
final float pivotY = Float.parseFloat(tmap.getObjectProperty(groupID, objectID, "pivotY", "0"));
final float acceleration = Float.parseFloat(tmap.getObjectProperty(groupID, objectID, "acceleration", "0"));
final MovementDirection direction = MovementDirection.valueOf(tmap.getObjectProperty(groupID, objectID, "direction", "NONE"));
final String entityRef = tmap.getObjectProperty(groupID, objectID, "triggeredBy", "");
rotatableObjectList.add(new RotatableObject(p, color, pivotX, pivotY, acceleration, direction, entityRef));
}
else if (type.equals("StaticSprite"))
{
final String imageRef = tmap.getObjectProperty(groupID, objectID, "StaticSprite.image", PlayState.DEFAULT_IMAGE_PATH);
final Vector2f position = new Vector2f(tmap.getObjectX(groupID, objectID)-1, tmap.getObjectY(groupID, objectID)-1);
staticSpriteList.add(new StaticSprite(imageRef, position, Color.white));
}
else if (true)
{
}
}
}
} |
7051e2b4-037e-44d5-9900-9938eba9c922 | public Raytracer(int width, int height) {
this.height = height;
this.width = width;
} |
36ee0c73-d03d-470b-97e6-c863ff7a2954 | public void raytrace(Camera camera, Scene scene, String path) {
String filename = path + "/Documents/BHfT/Computergrafik II/Uebung 1/"
+ "RaytracerImage.png";
new ImageGenerator(new RaytracerImage(camera, scene), width, height,
filename, "png");
ImageGenerator.showImage(filename);
} |
109a6e0d-672d-4386-a57f-488331e669b7 | public RaytracerImage(Camera camera, Scene scene) {
this.camera = camera;
this.scene = scene;
} |
95edb326-d10d-425c-93ba-425c31674045 | @Override
public Color pixelColorAt(int x, int y, int resolutionX, int resolutionY) {
Ray generateRay = camera.generateRay(x, y, resolutionX, resolutionY);
Hit intersect = scene.intersect(generateRay);
if (intersect == null) {
// Hintergrundfarbe - schwarz
return new Color(0, 0, 0);
} else {
return intersect.getColor();
}
} |
451b306c-1c1b-46b3-bb5a-2b17cf8f5ad2 | public Hit(Vector hitPoint, Color color) {
this.hitPoint = hitPoint;
this.color = color;
} |
28ec86bc-8db1-49ad-ae62-56a309ec4893 | public Vector getHitPoint() {
return hitPoint;
} |
f59ea303-be82-4e35-9bb0-a72d52e93179 | public Color getColor() {
return color;
} |
ff043d85-c5d4-4aea-a0f6-68448192397b | public Ray(Vector origin, Vector direction) {
this.origin = origin;
this.direction = direction;
} |
4fcc26bf-2f1c-4312-8d80-e3f48831941e | public Vector getOrigin() {
return origin;
} |
0dc210a6-7da8-4777-bec0-3b3095a5df22 | public Vector getNormalizedDirection() {
return direction.normalize();
} |
0c087208-5038-434f-9eb1-23ecae5741ab | public Vector getPoint(float t) {
return origin.add(direction.mult(t));
} |
f7b91aea-4c7f-47a8-b038-9672eda3ad8f | public Scene() {
this.shapeList = new ArrayList<AbstractShape>();
} |
171cf4b7-88cc-4933-b01c-c37dabd98927 | public void addShape(AbstractShape shape) {
shapeList.add(shape);
} |
04e20d4c-fc78-47fc-9dd6-74921f8d08a2 | public Hit intersect(Ray ray) {
ArrayList<AbstractShape> sortedList = new ArrayList<AbstractShape>();
for (AbstractShape shapes : sortedList) {
if (shapes.intersect(ray) != null) {
return shapes.intersect(ray);
}
}
return null;
} |
5f068bd9-92c3-4823-9430-fbbf01b41dbf | public Sphere(Vector center, float radius, Color color) {
this.center = center;
this.radius = radius;
this.color = color;
} |
588a4c6d-8d90-4bbf-8990-4bfa7d86f0a2 | @Override
public Hit intersect(Ray ray) {
Vector x0 = ray.getOrigin().sub(center);
Vector d = ray.getNormalizedDirection();
float t1 = 0.0f;
float t2 = 0.0f;
if ((x0.dot(d) * x0.dot(d)) * ((x0.dot(x0)) - (radius * radius)) < 0) {
return null;
}
if ((x0.dot(d) * x0.dot(d)) * ((x0.dot(x0)) - (radius * radius)) == 0) {
t1 = -(x0.dot(d));
return new Hit(ray.getPoint(t1), color);
} else {
t1 = (float) (-(x0.dot(d)) + Math.sqrt((x0.dot(d) * x0.dot(d))
* ((x0.dot(x0)) - (radius * radius))));
t2 = (float) (-(x0.dot(d)) - Math.sqrt((x0.dot(d) * x0.dot(d))
* ((x0.dot(x0)) - (radius * radius))));
if (t1 < t2) {
return new Hit(ray.getPoint(t1), color);
} else {
return new Hit(ray.getPoint(t2), color);
}
}
} |
19d57c1f-37d6-48ae-b509-a4d6e8a7cd3c | public Plane(Vector normal, float distance, Color color) {
this.normal = normal;
this.distance = distance;
this.color = color;
} |
a296f1a5-3df3-40e0-b2a7-75ea8288ff1f | @Override
public Hit intersect(Ray ray) {
// AnkerPunkt auf der Ebene
Vector anchorPoint = ray.getOrigin();
Vector direction = ray.getNormalizedDirection();
float t = 0.0f;
// ray parallel zur plane?
if (normal.dot(direction) == 0) {
return null;
} else {
t = ((distance - normal.dot(anchorPoint)) / normal.dot(direction));
return new Hit(ray.getPoint(t), color);
}
} |
5e001f24-fe72-4cd5-b920-36fc31b28432 | public abstract Hit intersect(Ray ray); |
32564bbc-7d9f-4972-904d-b30d0625df20 | public Color(float r, float g, float b) {
this.r = r;
this.g = g;
this.b = b;
} |
cdd3aafc-3f25-44af-91ee-750b0dcd9b3d | public Color(Vector v) {
r = v.x;
g = v.y;
b = v.z;
} |
ef895e0f-39b0-438c-8d35-2986a6627423 | public Color(float r, float g, float b, float a) {
this.r = r;
this.g = g;
this.b = b;
} |
0b6fb7c4-990e-4d00-b9be-219b48c325ab | public boolean isBlack() {
return r == 0.0 && g == 0.0 && b == 0.0;
} |
3c674f55-8868-4a2e-8bbc-95b08e0a7e58 | public Color add(Color c) {
return new Color(r + c.r, g + c.g, b + c.b);
} |
348995c3-878a-498a-ae88-dd77350aeb2b | public Color modulate(float s) {
return new Color(r * s, g * s, b * s);
} |
190c87d7-9088-4c30-b53d-34c880c7ae80 | public Color modulate(Color c) {
return new Color(r * c.r, g * c.g, b * c.b);
} |
87e66e55-30d8-4a6d-baf2-c1c5d6dff565 | public Color clip() {
Color c = new Color(Math.min(r, 1), Math.min(g, 1), Math.min(b, 1));
return new Color(Math.max(c.r, 0), Math.max(c.g, 0), Math.max(c.b, 0));
} |
4f7ca846-bc35-4541-9b8a-8369ad8f424c | public float[] asArray() {
float[] v = { r, g, b };
return v;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.