Skip to content

Commit 64140fc

Browse files
committed
changed delay speed and added fps counter
1 parent b77cc0c commit 64140fc

File tree

9 files changed

+18
-20
lines changed

9 files changed

+18
-20
lines changed

.idea/artifacts/JavaGameEngine_jar2.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/JavaGameEngine/Backend/GameWorld.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class GameWorld extends JPanel{
2020
This is where the main game world where we draw everything
2121
we also gets all the inpus from here
2222
*/
23+
public static String fps = "0";
2324
public GameWorld() {
2425
/*
2526
Key keyboard inputs
@@ -119,6 +120,7 @@ private void drawUi(Graphics g){
119120
private void drawComponents(Graphics g){
120121
for(Component c : ComponentHandler.getObjects()){
121122
(c).draw(g);
123+
g.drawString(fps,0,10);
122124
}
123125
}
124126
}

src/JavaGameEngine/Backend/UpdateThread.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,8 @@ private LinkedList<Component> UpdateObjects()
2828
{
2929

3030
for (Component component : ComponentHandler.getObjects()) {
31-
if((component).getTag()!="player"){
32-
component.setCameraPosition(UpdateThread.camera.getPosition());
33-
}
34-
else{
35-
component.setCameraPosition(UpdateThread.camera.getPosition().devide(4));
36-
}
3731

32+
//component.setCameraPosition(UpdateThread.camera.getPosition().devide(4));
3833
component.update();
3934
}
4035
return ComponentHandler.getObjects();

src/JavaGameEngine/Components/GameObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class GameObject extends Component{
1515
* this is the method that draws the GameObject
1616
*/
1717

18-
private Color color;
18+
private Color color = Color.darkGray;
1919

2020
public void setColor(Color color) {
2121
this.color = color;

src/JavaGameEngine/Components/Physics/PhysicsBody.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package JavaGameEngine.Components.Physics;
22

33
import JavaGameEngine.Components.Component;
4+
import JavaGameEngine.JavaGameEngine;
45
import JavaGameEngine.msc.Vector2;
56

67
public class PhysicsBody extends Component {

src/JavaGameEngine/Components/Physics/PhysicsWorld.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package JavaGameEngine.Components.Physics;
22

3+
import JavaGameEngine.JavaGameEngine;
34
import JavaGameEngine.msc.Vector2;
45

56
public class PhysicsWorld {
67

7-
public static Vector2 gravityAcceleration=new Vector2(0,0.0982f);
8+
public static Vector2 gravityAcceleration=new Vector2(0,9.82f*JavaGameEngine.DELAY/10000);
89

910

1011
public static Vector2 getGravityAcceleration() {

src/JavaGameEngine/JavaGameEngine.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
public class JavaGameEngine {
1313

14-
public static final int DELAY = 16;
14+
public static int DELAY = 3;
1515
public static GameWorld GAMEWORLD = new GameWorld();
1616
static JFrame frame;
1717
private static float start;
@@ -61,11 +61,7 @@ private static void startGame(){
6161
timer.schedule(new TimerTask() {
6262
@Override
6363
public void run() {
64-
65-
6664
calcThread.Update();
67-
68-
6965
}
7066
}, DELAY,DELAY);
7167
Timer timer1 = new Timer();
@@ -77,9 +73,11 @@ public void run() {
7773
previous = current;
7874
// Debug.log(totalElapsed);
7975
GAMEWORLD.repaint();
80-
Toolkit.getDefaultToolkit().sync(); // so it does not lag on linuxddddd
76+
Toolkit.getDefaultToolkit().sync(); // so it does not lag on linux
8177
totalElapsed += deltaTime;
78+
8279
if((totalElapsed/1000000000)>1){
80+
GameWorld.fps = String.valueOf(fps);
8381
totalElapsed = 0;
8482
fps = 0;
8583
}

src/Testing/Coin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public Coin() {
2020
paths[i] = ("/Free Platform Game Assets/Platform Game Assets/Coin Animation/png/2x/image "+(i+1)+".png");
2121
}
2222
sprite.loadAnimation(paths);
23-
sprite.setTimer(4);
23+
sprite.setTimer(20);
2424

2525
setScale(new Vector2(16,16));
2626
addChild(sprite);
@@ -47,7 +47,7 @@ public void update() {
4747
if(getPosition().getY()>mindown){
4848
setRotation(Vector2.up);
4949
}
50-
setPosition(getPosition().add(getRotation().multiply(1)));
50+
setPosition(getPosition().add(getRotation().multiply(0.2f)));
5151

5252
}
5353
}

src/Testing/Player.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,17 @@ public void update() {
5151
super.update();
5252

5353
if(Input.isKeyDown((Keys.D))){
54-
movePosition(getPosition().add(Vector2.right.multiply(2)));
54+
movePosition(getPosition().add(Vector2.right.multiply(1.2f)));
5555
//UpdateThread.camera.setX(UpdateThread.camera.getX()+2);
5656
}
5757
if(Input.isKeyDown((Keys.A))){
58-
movePosition(getPosition().add(Vector2.left.multiply(2)));
58+
movePosition(getPosition().add(Vector2.left.multiply(1.2f)));
5959

6060
//UpdateThread.camera.setX(UpdateThread.camera.getX()-2);
6161
}
6262
if(Input.isKeyPressed(Keys.SPACE)){
63-
physicsBody.addForce(Vector2.up,300);
63+
64+
physicsBody.addForce(Vector2.up,60);
6465
}
6566
//UpdateThread.camera = this.getPosition();
6667
}

0 commit comments

Comments
 (0)