Skip to content
Merged
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
2 changes: 1 addition & 1 deletion JavaGameEngineDocumentation
Submodule JavaGameEngineDocumentation updated from d6014e to 6233d6
Binary file added filename
Binary file not shown.
18 changes: 16 additions & 2 deletions src/com/javagamemaker/javagameengine/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void destroy(Component c) {
}

public boolean inside(Component component) {
return screen.contains(component.getShape().getBounds());
return true;//screen.contains(component.getShape().getBounds()) || component.getShape().contains(screen);
}
public static void playSound(String path){
playSound(path,1);
Expand Down Expand Up @@ -285,12 +285,26 @@ public int compare(Component o1, Component o2){
});

try{
//center graphics
if(camera.parallax) graphics2D.translate(JavaGameEngine.getWindowSize().getX()/2, JavaGameEngine.getWindowSize().getY()/2);

int lsize = components.size();
for(int i = 0; i < lsize;i++){
Component c = renderList.get(i);
if(inside(c) || true) {
int layer = c.getLayer()==0?1:c.getLayer();
//int layer = c.getLayer()==0?1:c.getLayer();
float layer = c.getPosition().getZ()==0?1:c.getPosition().getZ();
Camera camera = JavaGameEngine.getSelectedScene().getCamera();
if(camera.parallax){
Debug.log(camera.getPosition().getY());
float parx = camera.getPosition().getX()*layer/100;
float pary = camera.getPosition().getY()*layer/100;
graphics2D.translate(parx,pary);
}
(c).render(graphics2D);
if(camera.parallax){
graphics2D.translate(-camera.getPosition().getX()*layer/100,-camera.getPosition().getY()*layer/100);
}
//if(!c.isVisible()){
// c.setVisible(true);
// c.onCameraEnter();
Expand Down
2 changes: 2 additions & 0 deletions src/com/javagamemaker/javagameengine/components/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* and its position controls the graphics position
*/
public class Camera extends Component {

public boolean parallax = false;
@Override
public void start() {
super.start();
Expand Down
8 changes: 8 additions & 0 deletions src/com/javagamemaker/javagameengine/components/Collider.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,20 @@ public Point collision(Collider c){
for (Vector2 vertex : vertices){
Point p = new Point((int) vertex.getX(), (int) vertex.getY());
if(c.getShape().contains(p)){
try{
//parent.setPosition(parent.getPosition().subtract(new Vector2(0,1)));
}
catch (Exception e){}
return p;
}
}
for (Vector2 vertex : c.vertices){
Point p = new Point((int) vertex.getX(), (int) vertex.getY());
if(getShape().contains(p)){
try{
//parent.setPosition(parent.getPosition().subtract(new Vector2(0,1)));
}
catch (Exception e){}
return p;
}
}
Expand Down
19 changes: 11 additions & 8 deletions src/com/javagamemaker/javagameengine/components/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
public class Component {

protected int layer = 100;
protected int layer = 0;
protected String tag = "";
protected float angle = 0;
protected boolean visible = true;
Expand Down Expand Up @@ -196,18 +196,20 @@ public void translate(Vector2 towards){
if(collider!=null){
Collider addedX = new Collider();
addedX.localVertices = collider.getLocalVertices();
addedX.setPosition(getPosition().add(towards.removeY()));
addedX.setPosition(collider.getPosition().add(towards.removeY()));
addedX.setScale(addedX.getScale().subtract(1));
addedX.updateVertices();

Collider addedY = new Collider();
addedY.localVertices = collider.getLocalVertices();
addedY.setPosition(getPosition().add(towards.removeX()));
addedY.setPosition(collider.getPosition().add(towards.removeX()));
addedY.setScale(addedY.getScale().subtract(1));
addedY.updateVertices();

// all components in the scene
for ( Component c : JavaGameEngine.getSelectedScene().getComponents1() ){
if(c.getPosition().getZ() != getPosition().getZ()) continue;

if(c != this && JavaGameEngine.getSelectedScene().inside(c)){ // don't check us
for ( Component cc : c.getChildren(new Collider()) ){
Collider otherCollider = (Collider) cc;
Expand Down Expand Up @@ -242,9 +244,9 @@ else if(otherCollider.isTrigger()){
try{
Vector2 vel = ((PhysicsBody) getChild(new PhysicsBody())).velocity;
((PhysicsBody) getChild(new PhysicsBody())).response(event);
if(((PhysicsBody) getChild(new PhysicsBody())).velocity.getX() == vel.getX()){
if(this.<PhysicsBody>getChild().velocity.getX() == vel.getX()){
//Debug.log("zeor");
((PhysicsBody) getChild(new PhysicsBody())).velocity.setX(0);
this.<PhysicsBody>getChild().velocity.setX(0);
}
}catch (Exception e){}
}
Expand Down Expand Up @@ -294,7 +296,7 @@ else if(otherCollider.isTrigger()){
public void setPosition(Vector2 position) {
//this.lastPosition = this.position;

if(getParent()!=null){
if(getParent() != null){
this.position = position.add(parentOffset).add(rotOffset);

}else{
Expand Down Expand Up @@ -463,13 +465,14 @@ public LinkedList<Component> getAllChildren(Component type){
}

public <T>T getChild(){
T t = null;
for (Component child : this.children){
try{
return ((T)child);
t = ((T)child);
}
catch (Exception e){}
}
return null;
return t;
}
/**
* @param type the specified type of the children to be returned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public void setColor(Color color) {
public void render(Graphics2D g) {
if(visible){
Camera camera = JavaGameEngine.getSelectedScene().getCamera();
//g.translate(camera.getPosition().getX()*layer/100,camera.getPosition().getY()*layer/100);
Color prev = g.getColor();
if(getChild(new Sprite())==null){
g.setColor(color);
g.fill(getShape());
g.setColor(prev);
}
renderChildren(g);
//g.translate(camera.getPosition().getX()*layer/100,camera.getPosition().getY()*layer/100);
//g.translate(-camera.getPosition().getX()*layer/100,-camera.getPosition().getY()*layer/100);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/com/javagamemaker/javagameengine/components/Grabber.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public Grabber(Component parent){
public void update() {
super.update();
if (Input.isMouseDown(1) && parent.isMouseInside()) {
Debug.log("asd");
PhysicsBody b;
if ((b = ((PhysicsBody)parent.getChild(new PhysicsBody()))) != null){
b.velocity = Vector2.zero;
}
if (this.offset == null) {
this.offset = parent.getPosition().subtract(Input.getMousePosition());
}
Expand Down
25 changes: 20 additions & 5 deletions src/com/javagamemaker/javagameengine/msc/Vector2.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@ public class Vector2 {
public static Vector2 right = new Vector2(1,0);
public static Vector2 left = new Vector2(-1,0);
public static Vector2 zero = new Vector2(0,0);
private float x,y;
private float x,y,z;

public Vector2(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
public Vector2(float x, float y) {
this.x = x;
this.y = y;
this.z = 0;
}
public Vector2(Vector2 vector2) {
this.x = vector2.x;
this.y = vector2.y;
this.z = vector2.z;
}
public float getX() {
return x;
Expand All @@ -35,6 +42,14 @@ public void setY(float y) {
this.y = y;
}

public float getZ() {
return z;
}

public void setZ(float z) {
this.z = z;
}

public String toString()
{
return ("{x:{"+x+"} y:{"+y+"}}");
Expand All @@ -44,10 +59,10 @@ public Vector2 multiply(float multiple) {
return new Vector2(x*multiple,y*multiple);
}
public Vector2 multiply(double multiple) {
return new Vector2((float) (x*multiple), (float) (y*multiple));
return new Vector2((float) (x*multiple), (float) (y*multiple),(float) (z*multiple));
}
public Vector2 multiply(Vector2 vector2) {
return new Vector2(x*vector2.x,y*vector2.y);
return new Vector2(x*vector2.x,y*vector2.y,z*vector2.z);
}

public float getMagnitude (){
Expand All @@ -63,10 +78,10 @@ public Vector2 getOpposite(){
}

public Vector2 divide(float a){
return new Vector2(x/a,y/a);
return new Vector2(x/a,y/a, z/a);
}
public Vector2 divide(Vector2 a){
return new Vector2(x/a.getX(),y/a.getY());
return new Vector2(x/a.getX(),y/a.getY(), z/a.getZ());
}
public Vector2 add(Vector2 vector2) {
return new Vector2(x+ vector2.x,y+ vector2.y);
Expand Down