Skip to content

Commit a74083d

Browse files
committed
update
1 parent 227890f commit a74083d

File tree

6 files changed

+23
-31
lines changed

6 files changed

+23
-31
lines changed

.attach_pid7832

Whitespace-only changes.
113 Bytes
Binary file not shown.

src/JavaGameEngine/Backend/GameWorld.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
import java.awt.event.MouseEvent;
1414
import java.util.Collections;
1515
import java.util.Comparator;
16+
import java.util.LinkedList;
1617
import java.util.List;
1718

1819
public class GameWorld extends JPanel{
1920
/*
2021
This is where the main game world where we draw everything
2122
we also gets all the inpus from here
2223
*/
24+
public static LinkedList<Component> layerList = new LinkedList<>();
2325
public static String fps = "0";
2426
public GameWorld() {
2527
/*

src/JavaGameEngine/Backend/UpdateThread.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public UpdateThread(LinkedList<Component> o) {
2727
private LinkedList<Component> UpdateObjects()
2828
{
2929
for (Component component : ComponentHandler.getObjects()) {
30-
3130
component.setCameraPosition(UpdateThread.camera.getPosition());
3231
component.update();
3332

src/JavaGameEngine/Components/Component.java

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
package JavaGameEngine.Components;
22

3-
import JavaGameEngine.Backend.ComponentHandler;
3+
import JavaGameEngine.Backend.GameWorld;
44
import JavaGameEngine.Backend.Input.Input;
55
import JavaGameEngine.Backend.UpdateThread;
6-
import JavaGameEngine.Components.Collider.Collider;
7-
import JavaGameEngine.Components.Collider.SquareCollider;
8-
import JavaGameEngine.Components.Physics.PhysicsBody;
9-
import JavaGameEngine.msc.Debug;
106
import JavaGameEngine.msc.Vector2;
117

128
import java.awt.*;
139
import java.util.LinkedList;
10+
import java.util.Objects;
1411

1512
public class Component {
1613

17-
Vector2 position=Vector2.zero; // world position
14+
Vector2 position; // world position
1815
Vector2 localPosition=Vector2.zero; // local position this is that children to a parent should change to change position
1916
Vector2 cameraPosition = Vector2.zero; // camera offset
2017

21-
Vector2 scale = Vector2.zero; // scale with,height
18+
Vector2 scale; // scale with,height
2219
Vector2 localScale=Vector2.zero; // local scale with,height
2320

2421
Vector2 rotation=Vector2.zero; // rotation
@@ -34,6 +31,7 @@ public int getLayer() {
3431
}
3532

3633
public void setLayer(int layer) {
34+
GameWorld.layerList.add(this);
3735
this.layer = layer;
3836
}
3937

@@ -90,7 +88,7 @@ public Vector2 getPosition() {
9088
return position;
9189
}
9290
public void setPosition(Vector2 position) {
93-
if(this.tag != "player"){
91+
if(!Objects.equals(this.tag, "player")){
9492
this.position = position;
9593
}
9694
else{
@@ -225,22 +223,20 @@ public void destroy(){
225223
* this is the update function. It will be called on every game update
226224
*/
227225
public void update() {
228-
229-
if(insideComp()&&isEnabled()){
230-
if(!isMouseInside()){
231-
onMouseEntered();
232-
setMouseInside(true);
226+
if (insideComp() && isEnabled()) {
227+
if (!isMouseInside()) {
228+
onMouseEntered();
229+
setMouseInside(true);
230+
}
231+
232+
} else if (isMouseInside() && isEnabled()) {
233+
onMouseExit();
234+
setMouseInside(false);
235+
}
236+
if (isMouseInside() && Input.isMousePressed() && isEnabled()) {
237+
onMousePressed();
238+
if (getParent() != null) getParent().onMousePressed();
233239
}
234-
235-
}
236-
else if (isMouseInside()&&isEnabled()){
237-
onMouseExit();
238-
setMouseInside(false);
239-
}
240-
if(isMouseInside()&&Input.isMousePressed()&&isEnabled()){
241-
onMousePressed();
242-
if(getParent()!=null) getParent().onMousePressed();
243-
}
244240

245241
if(parent!=null) {
246242
float x = (parent.getPosition().getX()-((getScale().getX()/2)));
@@ -272,10 +268,7 @@ private boolean insideComp(){
272268
float mx = Input.getMousePosition().getX();
273269
float my = Input.getMousePosition().getY();
274270

275-
if(mx>xMin&&mx<xMax&&my>yMin&&my<yMax){
276-
return true;
277-
}
278-
return false;
271+
return mx > xMin && mx < xMax && my > yMin && my < yMax;
279272
}
280273
public void updateChildren(){
281274
LinkedList<Component> s = getChildren();

src/JavaGameEngine/UI/Button.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ public void onMousePressed() {
3535
onPress();
3636
}
3737

38-
public void onPress(){
39-
40-
}
38+
public void onPress(){}
4139

4240
@Override
4341
public void draw(Graphics g) {

0 commit comments

Comments
 (0)