Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rustproject
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
safarik
rustproject
Commits
3c21d6d6
Commit
3c21d6d6
authored
Jul 3, 2021
by
radow
Browse files
Options
Downloads
Patches
Plain Diff
ui stuff on old setup
parent
d3653bb7
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
resources/corbel.ttf
+0
-0
0 additions, 0 deletions
resources/corbel.ttf
src/main.rs
+61
-4
61 additions, 4 deletions
src/main.rs
with
61 additions
and
4 deletions
resources/corbel.ttf
0 → 100644
+
0
−
0
View file @
3c21d6d6
File added
This diff is collapsed.
Click to expand it.
src/main.rs
+
61
−
4
View file @
3c21d6d6
use
std
::
collections
::
HashMap
;
use
std
::
collections
::
HashMap
;
use
tetra
::
graphics
::
text
::{
Font
,
Text
,
VectorFontBuilder
};
use
tetra
::
graphics
::{
self
,
Color
,
DrawParams
,
Texture
};
use
tetra
::
graphics
::{
self
,
Color
,
DrawParams
,
Texture
};
use
tetra
::
input
::{
self
,
Key
};
use
tetra
::
input
::{
self
,
Key
};
use
tetra
::
math
::
Vec2
;
use
tetra
::
math
::
Vec2
;
...
@@ -7,10 +8,10 @@ use rand::{thread_rng, Rng};
...
@@ -7,10 +8,10 @@ use rand::{thread_rng, Rng};
//constants
//constants
const
WINDOW_WIDTH
:
f32
=
12
8
0.0
;
const
WINDOW_WIDTH
:
f32
=
1
9
20.0
;
const
WINDOW_HEIGHT
:
f32
=
72
0.0
;
const
WINDOW_HEIGHT
:
f32
=
108
0.0
;
const
BOARD_WIDTH
:
usize
=
39
;
const
BOARD_WIDTH
:
usize
=
58
;
const
BOARD_HEIGHT
:
usize
=
2
2
;
const
BOARD_HEIGHT
:
usize
=
2
8
;
fn
main
()
->
tetra
::
Result
{
fn
main
()
->
tetra
::
Result
{
ContextBuilder
::
new
(
"rusttest"
,
WINDOW_WIDTH
as
i32
,
WINDOW_HEIGHT
as
i32
)
ContextBuilder
::
new
(
"rusttest"
,
WINDOW_WIDTH
as
i32
,
WINDOW_HEIGHT
as
i32
)
...
@@ -24,6 +25,8 @@ player: Entity,
...
@@ -24,6 +25,8 @@ player: Entity,
foes
:
Foes
,
foes
:
Foes
,
tile
:
Texture
,
tile
:
Texture
,
world
:
World
,
world
:
World
,
ui
:
UI
,
stats
:
Stats
,
}
}
impl
GameState
{
impl
GameState
{
...
@@ -35,11 +38,17 @@ impl GameState {
...
@@ -35,11 +38,17 @@ impl GameState {
//set initial position
//set initial position
let
player_position
=
Vec2
::
new
(
5
,
7
);
let
player_position
=
Vec2
::
new
(
5
,
7
);
//UI
let
font
=
VectorFontBuilder
::
new
(
"./resources/corbel.ttf"
)
?
;
let
font2
=
font
.with_size
(
ctx
,
16.0
)
?
;
Ok
(
GameState
{
Ok
(
GameState
{
player
:
Entity
::
new_pos
(
player_texture
,
player_position
,
1
),
player
:
Entity
::
new_pos
(
player_texture
,
player_position
,
1
),
foes
:
Foes
::
generate
(
6
,
Texture
::
new
(
ctx
,
"./resources/spike.png"
)
?
),
foes
:
Foes
::
generate
(
6
,
Texture
::
new
(
ctx
,
"./resources/spike.png"
)
?
),
tile
:
tile_texture
,
tile
:
tile_texture
,
world
:
World
::
new
(),
world
:
World
::
new
(),
ui
:
UI
::
new
(
font2
),
stats
:
Stats
::
new
(),
})
})
}
}
}
}
...
@@ -72,6 +81,9 @@ impl State for GameState {
...
@@ -72,6 +81,9 @@ impl State for GameState {
for
id
in
&
ids
{
for
id
in
&
ids
{
self
.foes.list
[
id
]
.draw
(
ctx
);
self
.foes.list
[
id
]
.draw
(
ctx
);
}
}
self
.ui
.updateStats
(
ctx
,
self
.stats
);
self
.ui
.updateEvents
(
ctx
,
"Something happend."
);
Ok
(())
Ok
(())
}
}
...
@@ -256,3 +268,48 @@ impl Foes{
...
@@ -256,3 +268,48 @@ impl Foes{
Foes
{
list
:
entities
}
Foes
{
list
:
entities
}
}
}
}
}
struct
UI
{
font
:
Font
}
impl
UI
{
fn
new
(
font
:
Font
)
->
UI
{
UI
{
font
:
font
,
}
}
fn
updateStats
(
&
mut
self
,
ctx
:
&
mut
Context
,
stats
:
Stats
){
let
mut
health
=
Text
::
new
(
format!
(
"Health: {}"
,
stats
.health
),
self
.font
.clone
());
let
mut
attack
=
Text
::
new
(
format!
(
"Attack: {}"
,
stats
.attack
),
self
.font
.clone
());
let
mut
level
=
Text
::
new
(
format!
(
"Lvl: {}"
,
stats
.level
),
self
.font
.clone
());
let
mut
score
=
Text
::
new
(
format!
(
"Score: {}"
,
stats
.score
),
self
.font
.clone
());
health
.draw
(
ctx
,
Vec2
::
new
(
100.0
,
950.0
));
attack
.draw
(
ctx
,
Vec2
::
new
(
100.0
,
970.0
));
level
.draw
(
ctx
,
Vec2
::
new
(
100.0
,
990.0
));
score
.draw
(
ctx
,
Vec2
::
new
(
100.0
,
1010.0
));
}
fn
updateEvents
(
&
mut
self
,
ctx
:
&
mut
Context
,
event
:
&
str
){
let
mut
event1
=
Text
::
new
(
event
,
self
.font
.clone
());
event1
.draw
(
ctx
,
Vec2
::
new
(
500.0
,
950.0
));
}
}
#[derive(Copy,
Clone)]
struct
Stats
{
health
:
u32
,
attack
:
u32
,
level
:
u32
,
score
:
u32
,
}
impl
Stats
{
fn
new
()
->
Stats
{
Stats
{
health
:
100
,
attack
:
10
,
level
:
1
,
score
:
0
,
}
}
}
\ No newline at end of file
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