Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProgArkProject
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sixten Müller
ProgArkProject
Commits
b6286a6b
Commit
b6286a6b
authored
1 year ago
by
marcus
Browse files
Options
Downloads
Patches
Plain Diff
Word are now scattered around. Dont go out of bounds unless there are waaaay to many letters
parent
c5e3de9d
Branches
Branches containing commit
No related tags found
1 merge request
!26
Word are now scattered around. Dont go out of bounds unless there are waaaay to many letters
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/src/com/wordbattle/game/view/GamePlayView.java
+79
-10
79 additions, 10 deletions
core/src/com/wordbattle/game/view/GamePlayView.java
with
79 additions
and
10 deletions
core/src/com/wordbattle/game/view/GamePlayView.java
+
79
−
10
View file @
b6286a6b
...
@@ -16,6 +16,7 @@ import com.badlogic.gdx.scenes.scene2d.Stage;
...
@@ -16,6 +16,7 @@ import com.badlogic.gdx.scenes.scene2d.Stage;
import
com.badlogic.gdx.scenes.scene2d.ui.TextField
;
import
com.badlogic.gdx.scenes.scene2d.ui.TextField
;
import
com.badlogic.gdx.utils.viewport.ScreenViewport
;
import
com.badlogic.gdx.utils.viewport.ScreenViewport
;
import
com.sun.org.apache.xerces.internal.util.SynchronizedSymbolTable
;
import
com.sun.org.apache.xerces.internal.util.SynchronizedSymbolTable
;
import
com.sun.tools.sjavac.Log
;
import
com.wordbattle.game.WordBattle
;
import
com.wordbattle.game.WordBattle
;
import
com.wordbattle.game.model.LetterPool
;
import
com.wordbattle.game.model.LetterPool
;
import
com.wordbattle.game.network.FirebaseInterface
;
import
com.wordbattle.game.network.FirebaseInterface
;
...
@@ -23,6 +24,7 @@ import com.wordbattle.game.network.FirebaseInterface;
...
@@ -23,6 +24,7 @@ import com.wordbattle.game.network.FirebaseInterface;
import
org.w3c.dom.ranges.Range
;
import
org.w3c.dom.ranges.Range
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Random
;
import
java.util.Stack
;
import
java.util.Stack
;
import
jdk.internal.org.jline.terminal.Size
;
import
jdk.internal.org.jline.terminal.Size
;
...
@@ -48,6 +50,8 @@ public class GamePlayView {
...
@@ -48,6 +50,8 @@ public class GamePlayView {
private
boolean
isTimerRunning
;
private
boolean
isTimerRunning
;
private
Rectangle
settingsBounds
;
private
Rectangle
settingsBounds
;
private
ArrayList
<
Integer
>
YOffsets
;
//used to make letters look scattered
...
@@ -59,6 +63,11 @@ public class GamePlayView {
...
@@ -59,6 +63,11 @@ public class GamePlayView {
Gdx
.
input
.
setInputProcessor
(
stage
);
Gdx
.
input
.
setInputProcessor
(
stage
);
System
.
out
.
println
(
"message from constructor"
);
settingsBounds
=
new
Rectangle
(
settingsBounds
=
new
Rectangle
(
WordBattle
.
WIDTH
-
100
,
WordBattle
.
WIDTH
-
100
,
WordBattle
.
HEIGHT
-
100
,
WordBattle
.
HEIGHT
-
100
,
...
@@ -92,6 +101,10 @@ public class GamePlayView {
...
@@ -92,6 +101,10 @@ public class GamePlayView {
}
}
public
Rectangle
getSettingsBounds
()
{
return
settingsBounds
;
}
public
Rectangle
getSettingsBounds
()
{
return
settingsBounds
;
}
...
@@ -105,6 +118,7 @@ public class GamePlayView {
...
@@ -105,6 +118,7 @@ public class GamePlayView {
isTimerRunning
=
false
;
// Stop the timer when it reaches 0
isTimerRunning
=
false
;
// Stop the timer when it reaches 0
// Handle time out logic
// Handle time out logic
}
}
}
}
}
}
...
@@ -114,8 +128,17 @@ public class GamePlayView {
...
@@ -114,8 +128,17 @@ public class GamePlayView {
letterPool
=
new
LetterPool
(
currentWord
,
5
,
pin
);
// Or however you decide the number of extra letters
letterPool
=
new
LetterPool
(
currentWord
,
5
,
pin
);
// Or however you decide the number of extra letters
letterBoxBounds
=
new
Rectangle
[
currentWord
.
length
()];
letterBoxBounds
=
new
Rectangle
[
currentWord
.
length
()];
filledBoxes
=
new
Character
[
currentWord
.
length
()];
filledBoxes
=
new
Character
[
currentWord
.
length
()];
Random
rand
=
new
Random
();
YOffsets
=
new
ArrayList
<>(
letterPool
.
getLetters
().
size
());
for
(
int
i
=
0
;
i
<
letterPool
.
getLetters
().
size
();
i
++){
YOffsets
.
add
(
rand
.
nextInt
(
200
)-
100
);
}
}
}
public
void
render
(
SpriteBatch
sb
)
{
public
void
render
(
SpriteBatch
sb
)
{
if
(
shapeRenderer
==
null
)
{
if
(
shapeRenderer
==
null
)
{
shapeRenderer
=
new
ShapeRenderer
();
shapeRenderer
=
new
ShapeRenderer
();
...
@@ -125,39 +148,79 @@ public class GamePlayView {
...
@@ -125,39 +148,79 @@ public class GamePlayView {
letters
=
letterPool
.
getLetters
();
letters
=
letterPool
.
getLetters
();
letterBounds
=
new
Rectangle
[
letters
.
size
()];
letterBounds
=
new
Rectangle
[
letters
.
size
()];
float
letterSpacing
=
100
;
float
letterSpacing
=
100
;
float
totalWidthLetter
=
((((
float
)
letters
.
size
()
*
letterSpacing
))
/
2
);
float
totalWidthLetter
=
((((
float
)
letters
.
size
()
*
letterSpacing
))
/
2
);
float
letterStartX
=
((
cam
.
viewportWidth
-
totalWidthLetter
)
-
2
*
letterSpacing
)
/
2
;
//float letterStartX = ((cam.viewportWidth - totalWidthLetter) - 2*letterSpacing) / 2;
float
letterStartX
=
100
;
float
letterStartY
=
cam
.
viewportHeight
/
2
;
float
letterStartY
=
cam
.
viewportHeight
/
2
;
sb
.
setProjectionMatrix
(
cam
.
combined
);
sb
.
setProjectionMatrix
(
cam
.
combined
);
sb
.
begin
();
// Begin the SpriteBatch for other rendering
sb
.
begin
();
// Begin the SpriteBatch for other rendering
sb
.
draw
(
backgroundTexture
,
0
,
0
,
cam
.
viewportWidth
,
cam
.
viewportHeight
);
sb
.
draw
(
backgroundTexture
,
0
,
0
,
cam
.
viewportWidth
,
cam
.
viewportHeight
);
float
letterStartYBaseEven
=
700
;
// Midpoint for range 500 to 900
float
letterStartYBaseEven
=
700
;
// Midpoint for range 500 to 900
float
letterStartYBaseOdd
=
-
550
;
// Midpoint for range 300 to 800
float
letterStartYBaseOdd
=
-
550
;
// Midpoint for range 300 to 800
int
num
=
0
;
float
yPos
=
0
;
for
(
int
i
=
0
;
i
<
letters
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
letters
.
size
();
i
++)
{
// Calculate the position for each letter
// Calculate the position for each letter
float
x
=
letterStartX
+
i
*
letterSpacing
;
float
x
Pos
=
(
float
)
(
letterStartX
+
i
*
letterSpacing
/
2
)
;
float
y
;
if
(
i
%
2
==
0
)
{
if
(
num
==
0
)
{
// For even indices, use the range 500 to 900
// For even indices, use the range 500 to 900
y
=
letterStartY
+
700
;
// Alternate within the range
yPos
=
letterStartY
+
750
+
YOffsets
.
get
(
i
);
// Alternate within the range
}
else
{
}
if
(
num
==
1
)
{
// For odd indices, use the range 300 to 800
// For odd indices, use the range 300 to 800
y
=
letterStartY
-
400
;
// Alternate within the range
yPos
=
letterStartY
+
400
+
YOffsets
.
get
(
i
);
// Alternate within the range
x
-=
letterSpacing
;
}
if
(
num
==
2
){
yPos
=
letterStartY
-
350
+
YOffsets
.
get
(
i
);
// Alternate within the range
}
if
(
num
==
3
){
yPos
=
letterStartY
-
750
+
YOffsets
.
get
(
i
);
// Alternate within the range
num
=-
1
;
}
}
// Draw each letter, here you might want to draw a background texture for the letter
// Draw each letter, here you might want to draw a background texture for the letter
font
.
setColor
(
Color
.
GREEN
);
font
.
setColor
(
Color
.
GREEN
);
font
.
draw
(
sb
,
letters
.
get
(
i
).
toString
(),
x
,
y
);
font
.
draw
(
sb
,
letters
.
get
(
i
).
toString
(),
xPos
,
yPos
);
letterBounds
[
i
]
=
new
Rectangle
(
x
,
y
-
120
,
120
,
120
);
letterBounds
[
i
]
=
new
Rectangle
(
xPos
,
yPos
-
120
,
120
,
120
);
System
.
out
.
println
(
"printed "
+
i
);
num
++;
}
}
// Draw time
// Draw time
font
.
draw
(
sb
,
"Time: "
+
String
.
format
(
"%o"
,
Math
.
round
(
timeLeft
)),
cam
.
viewportWidth
/
2
-
200
,
cam
.
viewportHeight
-
200
);
font
.
draw
(
sb
,
"Time: "
+
String
.
format
(
"%o"
,
Math
.
round
(
timeLeft
)),
cam
.
viewportWidth
/
2
-
200
,
cam
.
viewportHeight
-
200
);
...
@@ -193,6 +256,7 @@ public class GamePlayView {
...
@@ -193,6 +256,7 @@ public class GamePlayView {
}
}
shapeRenderer
.
end
();
shapeRenderer
.
end
();
sb
.
begin
();
// Begin SpriteBatch again
sb
.
begin
();
// Begin SpriteBatch again
...
@@ -244,6 +308,8 @@ public class GamePlayView {
...
@@ -244,6 +308,8 @@ public class GamePlayView {
this
.
filledBoxes
=
filledBoxes
;
this
.
filledBoxes
=
filledBoxes
;
}
}
public
void
dispose
()
{
public
void
dispose
()
{
shapeRenderer
.
dispose
();
shapeRenderer
.
dispose
();
}
}
...
@@ -271,3 +337,6 @@ public class GamePlayView {
...
@@ -271,3 +337,6 @@ public class GamePlayView {
return
maxTime
;
return
maxTime
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment