Skip to content
This repository has been archived by the owner on Sep 3, 2023. It is now read-only.

Commit

Permalink
Merge branch 'light'
Browse files Browse the repository at this point in the history
  • Loading branch information
sanj0 committed Nov 7, 2018
2 parents b2fe414 + 6c441a0 commit 1193228
Show file tree
Hide file tree
Showing 51 changed files with 1,401 additions and 518 deletions.
2 changes: 1 addition & 1 deletion Salty Engine.iml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: de.edgelord.sysDepFiles:systemDependentFiles:1.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.edgelord.sysDepFiles:systemDependentFiles:1.2-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: de.edgelord.stdf:stdf:1.0-SNAPSHOT" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
Expand Down
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# This software was published under the MIT License. #
# The full LICENSE file can be found here: https://github.com/edgelord314/salty-enigne/tree/master/LICENSE #
# #
# Copyright (c) since 2018 The Salty Engine Developer #
# Copyright (c) since 2018 by the Salty Engine developers, #
# maintained by Malte Dostal #
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy #
# of this software and associated documentation files (the "Software"), to deal #
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<groupId>de.edgelord.salty-engine</groupId>
<artifactId>salty-engine</artifactId>
<version>0.12.2-SNAPSHOT</version>
<version>0.12.4-SNAPSHOT</version>

<name>Salty Engine</name>
<url>https://github.com/edgelord314/salty-engine/</url>
Expand All @@ -47,7 +47,7 @@
<dependency>
<groupId>de.edgelord.sysDepFiles</groupId>
<artifactId>systemDependentFiles</artifactId>
<version>1.1-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>de.edgelord.stdf</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import de.edgelord.saltyengine.gameobject.GameObject;
import de.edgelord.saltyengine.graphics.SaltyGraphics;
import de.edgelord.saltyengine.transform.Transform;
import de.edgelord.saltyengine.utils.Directions;

/**
* This implementation of {@link Component} makes the {@link de.edgelord.saltyengine.camera.Camera}
Expand All @@ -46,12 +45,12 @@
* This can also be a floating-point number, the floating-points will stack and eventually turn into an integer.
* <p>
* By default, {@link #whiteZone} is twice as wide and high as the {@link #parent} of this Components
* and in the middle of the screen. It can be changed/edited at any time.
* and in the centre of the screen. It can be changed/edited at any time.
*/
public class CameraFollow extends Component<GameObject> {

private Transform whiteZone;
private float speed = 1f;
private float speed = 0.75f;

public CameraFollow(GameObject parent, String name) {
super(parent, name, Components.CAMERA_COMPONENT);
Expand All @@ -75,8 +74,8 @@ public void onFixedTick() {
getParent().getWidth(), getParent().getHeight());

if (!whiteZone.intersects(getParent().getTransform())) {
Game.camera.move(Directions.getFreeRelationX(whiteZone, renderedPlayerTransform), speed);
Game.camera.move(Directions.getFreeRelationY(whiteZone, renderedPlayerTransform), speed);
Game.camera.move(whiteZone.getFreeRelationX(renderedPlayerTransform), speed);
Game.camera.move(whiteZone.getFreeRelationY(renderedPlayerTransform), speed);
}
}

Expand Down
27 changes: 25 additions & 2 deletions src/main/java/de/edgelord/saltyengine/components/LockToBounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,23 @@
import de.edgelord.saltyengine.graphics.SaltyGraphics;
import de.edgelord.saltyengine.transform.Transform;

import java.awt.*;

/**
* Locks its parent to the given {@link Transform} by using whether its {@link de.edgelord.saltyengine.hitbox.Hitbox} or its {@link Transform}.
* What to use is defined in {@link #mode}. The default is {@link #MODE_TRANSFORM}
*/
public class LockToBounds extends Component<GameObject> {
/**
* The rectangular bounds to which the {@link #parent} is locked
*/
private Transform bounds;

private int mode = MODE_TRANSFORM;

public static final int MODE_HITBOX = 0;
public static final int MODE_TRANSFORM = 1;

public LockToBounds(GameObject parent, Transform bounds, String name) {
super(parent, name, Components.GAME_COMPONENTS);

Expand All @@ -48,13 +59,25 @@ public LockToBounds(GameObject parent, Transform bounds, String name) {

@Override
public void draw(SaltyGraphics saltyGraphics) {

}

@Override
public void onFixedTick() {

// Calculate difference and move
switch (mode) {

case MODE_TRANSFORM:
if (!bounds.contains(getParent().getTransform())) {
getParent().getLockedDirections().setDirection(bounds.getRelation(getParent().getTransform()));
}
break;

case MODE_HITBOX:
if (!bounds.contains(getParent().getHitbox().getTransform())) {
getParent().getLockedDirections().setDirection(bounds.getRelation(getParent().getHitbox().getTransform()));
}
break;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ public class SimplePhysicsComponent extends Component<GameObject> {
* getting manipulated internally.
*/
public static final String DEFAULT_LEFTWARDS_FORCE = "de.edgelord.saltyengine.core.physics.defaultLeftwardsForce";

/**
* This is the String constant for the default upwards velocity force. It is not recommended to use these because they're
* getting manipulated internally.
*/
public static final String DEFAULT_UPWARDS_VELOCITY_FORCE = "de.edgelord.saltyengine.core.physics.defaultUpwardsVelocityForce";

/**
* This is the String constant for the default downwards velocity force. It is not recommended to use these because they're
* getting manipulated internally.
*/
public static final String DEFAULT_DOWNWARDS_VELOCITY_FORCE = "de.edgelord.saltyengine.core.physics.defaultDownwardsVelocityForce";

/**
* This is the String constant for the default rightwards velocity force. It is not recommended to use these because they're
* getting manipulated internally.
*/
public static final String DEFAULT_RIGHTWARDS_VELOCITY_FORCE = "de.edgelord.saltyengine.core.physics.defaultRightwardsVelocityForce";

/**
* This is the String constant for the default leftwards velocity force. It is not recommended to use these because they're
* getting manipulated internally.
*/
public static final String DEFAULT_LEFTWARDS_VELOCITY_FORCE = "de.edgelord.saltyengine.core.physics.defaultLeftwardsVelocityForce";
private final List<Force> forces = new LinkedList<>();

public SimplePhysicsComponent(final GameObject parent, final String name) {
Expand All @@ -89,6 +113,11 @@ private void addDefaultForces() {
addForce(SimplePhysicsComponent.DEFAULT_DOWNWARDS_FORCE, Directions.Direction.DOWN);
addForce(SimplePhysicsComponent.DEFAULT_RIGHTWARDS_FORCE, Directions.Direction.RIGHT);
addForce(SimplePhysicsComponent.DEFAULT_LEFTWARDS_FORCE, Directions.Direction.LEFT);

addForce(SimplePhysicsComponent.DEFAULT_UPWARDS_VELOCITY_FORCE, Directions.Direction.UP);
addForce(SimplePhysicsComponent.DEFAULT_DOWNWARDS_VELOCITY_FORCE, Directions.Direction.DOWN);
addForce(SimplePhysicsComponent.DEFAULT_RIGHTWARDS_VELOCITY_FORCE, Directions.Direction.RIGHT);
addForce(SimplePhysicsComponent.DEFAULT_LEFTWARDS_VELOCITY_FORCE, Directions.Direction.LEFT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
import de.edgelord.saltyengine.gameobject.GameObject;
import de.edgelord.saltyengine.graphics.SaltyGraphics;

/**
* Animates the basic state of its {@link #parent}.
* That includes rotation, width, height, x position and y position.
* <p>
* NOTE: Take care of the hitbox of the {@link #parent}, these animation won't change it, you have to do that manually
* if necessary!
*/
public class BasicGameObjectAnimation extends Component<GameObject> {

private boolean recalculateOnNextStep = true;
Expand Down Expand Up @@ -83,11 +90,9 @@ public void onFixedTick() {

case WIDTH:
getParent().setWidth(getParent().getWidth() + delta);
getParent().getHitbox().getTransform().setWidth(getParent().getHitbox().getTransform().getWidth() + delta);
break;
case HEIGHT:
getParent().setHeight(getParent().getHeight() + delta);
getParent().getHitbox().getTransform().setHeight(getParent().getHitbox().getTransform().getHeight() + delta);
break;
case X_POS:
getParent().moveX(delta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,25 @@
*
*/

package de.edgelord.saltyengine.components;
package de.edgelord.saltyengine.components.collider;

import de.edgelord.saltyengine.core.Component;
import de.edgelord.saltyengine.core.event.CollisionEvent;
import de.edgelord.saltyengine.gameobject.Components;
import de.edgelord.saltyengine.gameobject.GameObject;
import de.edgelord.saltyengine.graphics.SaltyGraphics;
import de.edgelord.saltyengine.utils.Directions;

/**
* Note: It is obviously planned to make more complicated Collision detection with complex Shapes possible.
*/
public class ColliderComponent extends Component<GameObject> {
public abstract class ColliderComponent extends Component<GameObject> {

private Type type;
private String type;

public enum Type {
HITBOX
}
public static final String TYPE_HITBOX_COLLIDER = "de.edgelord.saltyengine.collider.hitboxCollider";

public ColliderComponent(GameObject parent, String name, Type type) {
public ColliderComponent(GameObject parent, String name, String type) {
super(parent, name, Components.COLLIDER_COMPONENT);

this.type = type;
Expand All @@ -62,20 +61,15 @@ public void draw(SaltyGraphics saltyGraphics) {
public void onCollision(CollisionEvent e) {
}

public boolean requestCollision(GameObject other) {

ColliderComponent otherCollider = other.requestCollider();

switch (otherCollider.type) {
public abstract boolean requestCollision(GameObject other);

case HITBOX:
public abstract Directions.Direction getCollisionDirection(GameObject other);

if (type == Type.HITBOX) {
return getParent().getHitbox().collides(other);
}
break;
}
public String getType() {
return type;
}

return false;
public void setType(String type) {
this.type = type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,33 @@
*
*/

package de.edgelord.saltyengine.cosmetic.lighting;
package de.edgelord.saltyengine.components.collider;

import de.edgelord.saltyengine.utils.StaticSystem;
import de.edgelord.saltyengine.gameobject.GameObject;
import de.edgelord.saltyengine.utils.Directions;

import java.awt.*;
import java.awt.image.BufferedImage;
public class HitboxCollider extends ColliderComponent {

public class Light {

private BufferedImage image;
private Shape shape;

public Light(BufferedImage lightSource) {
this.image = lightSource;

shape = Shape.CUSTOM;
public HitboxCollider(GameObject parent, String name) {
super(parent, name, TYPE_HITBOX_COLLIDER);
}

public Light(Shape shape) {
this.shape = shape;
@Override
public boolean requestCollision(GameObject other) {

switch (shape) {
ColliderComponent otherCollider = other.requestCollider();

case ROUND:
this.image = StaticSystem.defaultImageFactory.getOptimizedImageResource("res/pictures/light/default_light_round.png");
break;
case CUSTOM:
System.err.println("ERROR: CAN'T SET SHAPE OF LIGHT TO CUSTOM WITHOUT HAVING A CUSTOM IMAGE!");
break;
}
}
switch (otherCollider.getType()) {

public void draw(Graphics2D graphics) {
case TYPE_HITBOX_COLLIDER:
return getParent().getHitbox().collides(other);
}

return false;
}

public enum Shape {ROUND, CUSTOM}
@Override
public Directions.Direction getCollisionDirection(GameObject other) {
return getParent().getHitbox().getTransform().getRelation(other.getHitbox().getTransform());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package de.edgelord.saltyengine.components.gfx;

import de.edgelord.saltyengine.core.stereotypes.ComponentParent;
import de.edgelord.saltyengine.cosmetic.light.Light;
import de.edgelord.saltyengine.cosmetic.light.LightSystem;
import de.edgelord.saltyengine.cosmetic.light.PointLight;
import de.edgelord.saltyengine.graphics.SaltyGraphics;
import de.edgelord.saltyengine.scene.SceneManager;
import de.edgelord.saltyengine.transform.RelationMode;
import de.edgelord.saltyengine.utils.TransformRelationUtils;

/**
* This {@link de.edgelord.saltyengine.core.Component} makes a {@link Light} follow its parent using the rule
* described in {@link #relationToParent} and {@link TransformRelationUtils}.
* The light and the mode can be set in one of the constructors, if not the defaults are:
* {@code RelationMode.CENTRE}
* and
* {@code new PointLight(parent.getTransform())}
*/
public class LightComponent extends GFXComponent {

private RelationMode relationToParent;
private Light light;

public LightComponent(ComponentParent parent, String name, RelationMode relationToParent, Light light) {
super(parent, name);

this.light = light;
this.relationToParent = relationToParent;

addToLightSystem();
}

public LightComponent(ComponentParent parent, String name, Light light) {
this(parent, name, RelationMode.CENTRE, light);
}

public LightComponent(ComponentParent parent, String name, RelationMode relationToParent) {
this(parent, name, relationToParent, new PointLight(parent.getTransform()));
}

public LightComponent(ComponentParent parent, String name) {
this(parent, name, RelationMode.CENTRE, new PointLight(parent.getTransform()));
}

@Override
public void draw(SaltyGraphics saltyGraphics) {
}

@Override
public void onFixedTick() {
TransformRelationUtils.positionRelativeTo(relationToParent, getParent().getTransform(), light.getTransform());
}

public void addToLightSystem() {
LightSystem currentLightSystem = SceneManager.getCurrentScene().getLightSystem();

if (currentLightSystem == null) {
throw new NullPointerException("Can't add a LightComponent when the current scene has no LightSystem! Set one by using Scene#setLightSystem!");
}

currentLightSystem.addLight(light);
}
}
Loading

0 comments on commit 1193228

Please sign in to comment.