Skip to content

Commit

Permalink
Bad Game Loop Created with the FPS counter Check
Browse files Browse the repository at this point in the history
  • Loading branch information
IamRishavDas committed Feb 19, 2024
1 parent 110af6e commit caef506
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions NewGame/GamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class GamePanel extends JPanel {
private int posX = 100;
private int posY = 100;

//fps counter
private int frames = 0;
private long lastCheck = 0;

public GamePanel() {
addKeyListener(new KeyController(this));
addMouseListener(new MouseController(this));
Expand All @@ -36,6 +40,14 @@ public void paintComponent(Graphics g) {
super.paintComponent(g);

g.fillOval(posX, posY, 100, 100);

frames++;
if((System.currentTimeMillis() - lastCheck) >= 1000){
lastCheck = System.currentTimeMillis();
System.out.println("FPS: " + frames);
frames = 0;
}

repaint();
}
}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# PinBall
A simple Pin Ball game using java

1. First Simple JFrame And JPanel for the game
2. Draw basic components using the paintComponent defined in JPanel
public void paintCompoent(Graphics g){
super.paintComponent(g);
...// drawing methods ...
}
Also, update the paintComponet() using the repaint() method.
3. Game Loop --->
Every Game must contain a game Loop
1. repaint() game loop
2. make a fps counter
3. visuals

0 comments on commit caef506

Please sign in to comment.