Jonathan Hager 5 years ago
commit 306ac4421a

@ -14,16 +14,16 @@ public class MainMenuScreen extends Screen {
public MainMenuScreen(int GAME_WORLD_WIDTH, int GAME_WORLD_HEIGHT){
super(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, 0);
buttons.add(new Button(-1,0,0,200,80,"MainMenuScreen", Color.BLACK,Color.WHITE));
buttons.add(new Button(0,0,800,200,100, "MainMenu", Color.BLACK,Color.WHITE));
buttons.add(new Button(1,200,800,200,100, "GameScreen", Color.DARK_GRAY,Color.WHITE));
buttons.add(new Button(2,400,800,200,100, "EndScreen", Color.BLACK,Color.WHITE));
texts.add(new Text(GAME_WORLD_WIDTH/2, GAME_WORLD_HEIGHT/2, "Protect the Monster", Color.BLACK, 3, GAME_WORLD_HEIGHT/2 - 50,GAME_WORLD_HEIGHT/2 + 50));
}
@Override
public void timer() {
for(Text text : texts){
text.timer();
}
}
@Override
@ -46,7 +46,7 @@ public class MainMenuScreen extends Screen {
return button.getId();
}
}
return -1;
return 1;
}
@Override

@ -2,6 +2,7 @@ package com.trs.game.view;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class Text {
@ -10,19 +11,90 @@ public class Text {
int yPos;
String text;
Color color;
double scale;
int y1;
int y2;
boolean movement = false;
boolean moving = true;
public Text(int xPos, int yPos, String text, Color color){
public Text(int xPos, int yPos, String text, Color color, double scale, int y1, int y2){
this.xPos = xPos;
this.yPos = yPos;
this.text = text;
this.color = color;
this.scale = scale;
this.y1 = y1;
this.y2 = y2;
if(y1 == 0 && y2 == 0)moving = false;
}
public void render(SpriteBatch batch, BitmapFont font){
if(batch.isDrawing()) batch.end();
batch.begin();
font.setColor(color);
font.draw(batch,text,xPos,yPos);
font.getData().setScale((float)scale);
font.draw(batch, text, ((xPos) - (getTextWidth(font,text)/2)), ((yPos) + (getTextHeight(font,text)/2)));
font.getData().setScale(1);
batch.end();
}
public void timer(){
if(moving){
if(movement){
setyPos(getyPos()+3);
if(getyPos() >= y2){
movement = false;
}
}
else if(!movement){
setyPos(getyPos()-3);
if(getyPos() <= y1){
movement = true;
}
}
}
}
public float getTextWidth(BitmapFont font, String text){
GlyphLayout glyphLayout = new GlyphLayout();
glyphLayout.setText(font,text);
return glyphLayout.width;
}
public float getTextHeight(BitmapFont font, String text){
GlyphLayout glyphLayout = new GlyphLayout();
glyphLayout.setText(font,text);
return glyphLayout.height;
}
public int getxPos() {
return xPos;
}
public void setxPos(int xPos) {
this.xPos = xPos;
}
public int getyPos() {
return yPos;
}
public void setyPos(int yPos) {
this.yPos = yPos;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
}

Loading…
Cancel
Save