Skip to content

Commit bfe0d33

Browse files
committed
jogo quase pronto
1 parent 4a72ee1 commit bfe0d33

File tree

13 files changed

+187
-38
lines changed

13 files changed

+187
-38
lines changed

src/main/java/com/gustavolr/Main.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import com.gustavolr.engine.GameEngine;
44
import com.gustavolr.game_scenes.MainScene;
55

6-
public final class Main
7-
{
6+
public final class Main {
87
public static void main( String[] args ) {
98
GameEngine gameEngine = new GameEngine();
109

src/main/java/com/gustavolr/engine/entity/Vector.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@ public Vector add(Vector v) {
2424
return tmp;
2525
}
2626

27+
public Vector clone() {
28+
return new Vector(x,y);
29+
}
30+
31+
@Override
32+
public String toString() {
33+
return "Vector(x:" + x + ", y:" + y + ");";
34+
}
35+
2736
}

src/main/java/com/gustavolr/engine/input/GameInput.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public void keyReleased(KeyEvent k) {
4040
@Override
4141
public void keyTyped(KeyEvent arg0) {
4242
// TODO Auto-generated method stub
43-
System.out.println(arg0);
4443
}
4544

4645
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.gustavolr.engine.ui.Text;
2+
3+
import java.awt.Color;
4+
import java.awt.Font;
5+
import java.awt.FontMetrics;
6+
import java.awt.Graphics;
7+
8+
import com.gustavolr.engine.entity.Entity;
9+
import com.gustavolr.engine.entity.Vector;
10+
11+
public class Text extends Entity {
12+
13+
String label;
14+
Color textColor;
15+
Font labelFont;
16+
byte fontSize;
17+
FontMetrics metrics;
18+
19+
public Text(Vector position, String label) {
20+
super(position, 0, 0);
21+
22+
this.label = label;
23+
this.fontSize = (byte)TextConstants.DEFAULT_FONT_SIZE;
24+
this.textColor = TextConstants.DEFAULT_TEXT_COLOR;
25+
this.labelFont = TextConstants.DEFAULT_TEXT_FONT;
26+
27+
}
28+
29+
public String getLabel() {
30+
return label;
31+
}
32+
33+
public void setLabel(String label) {
34+
this.label = label;
35+
}
36+
37+
public Color getTextColor() {
38+
return textColor;
39+
}
40+
41+
public void setTextColor(Color textColor) {
42+
this.textColor = textColor;
43+
}
44+
45+
public Font getLabelFont() {
46+
return labelFont;
47+
}
48+
49+
public void setLabelFont(Font labelFont) {
50+
this.labelFont = labelFont;
51+
}
52+
53+
public void render(Graphics g) {
54+
55+
g.setColor(this.textColor);
56+
g.setFont(labelFont);
57+
metrics = g.getFontMetrics(labelFont);
58+
59+
g.drawString(this.label, this.position.x, this.position.y );
60+
}
61+
62+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.gustavolr.engine.ui.Text;
2+
3+
import java.awt.Color;
4+
import java.awt.Font;
5+
6+
public final class TextConstants {
7+
public static final Color DEFAULT_TEXT_COLOR = Color.WHITE;
8+
public static final String DEFAULT_FONT = "Century";
9+
public static final int DEFAULT_FONT_SIZE = 20;
10+
public static final Font DEFAULT_TEXT_FONT = new Font(DEFAULT_FONT, Font.BOLD, DEFAULT_FONT_SIZE);
11+
}

src/main/java/com/gustavolr/engine/window/GameWindow.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.awt.Graphics;
55
import java.awt.Dimension;
66
import java.awt.image.BufferedImage;
7-
import java.awt.Color;
87
import java.awt.image.BufferStrategy;
98

109
import javax.swing.JFrame;
@@ -30,7 +29,6 @@ public GameWindow(String frameName) {
3029

3130
public GameWindow(int width, int height, int scale, String frameName) {
3231
GameWindow.width = (short)width;
33-
System.out.println(height);
3432
GameWindow.height = (short)height;
3533
GameWindow.scale = (byte)scale;
3634

@@ -99,7 +97,7 @@ public Graphics getWindowLayer() {
9997

10098
public void drawBackground(Graphics g) {
10199

102-
g.setColor(Color.BLACK);
100+
g.setColor(GameWindowConstants.BACKGROUND_COLOR);
103101
g.fillRect(0, 0, GameWindow.getWindowWidth(), GameWindow.getWindowHeight());
104102
}
105103

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.gustavolr.engine.window;
22

3+
import java.awt.Color;
4+
35
public final class GameWindowConstants {
46

57
public static final int DEFAULT_WINDOW_WIDTH = 260;
68
public static final int DEFAULT_WINDOW_HEIGHT = 140;
79
public static final int DEFAULT_WINDOW_SCALE = 4;
10+
11+
public static final Color BACKGROUND_COLOR = new Color(28, 28, 28);
812
}

src/main/java/com/gustavolr/game_entities/Ball.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
import com.gustavolr.engine.entity.Entity;
77
import com.gustavolr.engine.entity.Vector;
88
import com.gustavolr.engine.window.GameWindow;
9-
import com.gustavolr.listeners.BallMovedListener;
109

1110
public class Ball extends Entity {
1211

1312
private int speed;
14-
private Color color;
15-
private BallMovedListener listener;
13+
private Color color = Color.WHITE;
1614

1715
float dx = 1;
1816
float dy = 1;
@@ -22,11 +20,7 @@ public Ball(Vector position, int width, int height) {
2220
speed = 1;
2321
}
2422

25-
public void addListener(BallMovedListener b) {
26-
this.listener = b;
27-
}
28-
29-
public void ballCollidedWithPaddle() {
23+
public void invertDX() {
3024
dx *= -1;
3125
}
3226

@@ -38,10 +32,6 @@ public void update() {
3832

3933
if(position.y < 0 || position.y > GameWindow.getWindowHeight())
4034
dy *= -1;
41-
42-
if (listener != null) {
43-
this.listener.ballMoved(position);
44-
}
4535
}
4636

4737
@Override

src/main/java/com/gustavolr/game_entities/Enemy.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55

66
import com.gustavolr.engine.entity.Entity;
77
import com.gustavolr.engine.entity.Vector;
8-
import com.gustavolr.listeners.BallMovedListener;
98

10-
public class Enemy extends Entity implements BallMovedListener {
9+
public class Enemy extends Entity {
1110

1211
private int speed = 1;
13-
private Color color = Color.RED;
12+
private Color color = new Color(196,30,58);
1413

1514
public Enemy(Vector position, int width, int height) {
1615
super(position, width, height);
@@ -22,7 +21,6 @@ public void render(Graphics g) {
2221
g.fillRect(this.position.x, this.position.y, this.width, this.height);
2322
}
2423

25-
@Override
2624
public void ballMoved(Vector ballPosition) {
2725

2826
Vector direction = new Vector();

src/main/java/com/gustavolr/game_entities/Player.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class Player extends Entity {
1212

1313
private int speed = 1;
14-
private Color color = Color.WHITE;
14+
private Color color = new Color(65,105,225);
1515

1616
public Player(Vector position, int width, int height) {
1717
super(position, width, height);

0 commit comments

Comments
 (0)