Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Double Trouble
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
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
Jonas Johan Solsvik
Double Trouble
Commits
d60ac910
Commit
d60ac910
authored
4 years ago
by
Viktor Palmason
Browse files
Options
Downloads
Patches
Plain Diff
My code for the end credits section including a filler sprite
parent
a52d919a
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
vikto_dev/Textures/devil.png
+0
-0
0 additions, 0 deletions
vikto_dev/Textures/devil.png
vikto_dev/main.cpp
+111
-0
111 additions, 0 deletions
vikto_dev/main.cpp
with
111 additions
and
0 deletions
vikto_dev/Textures/devil.png
0 → 100644
+
0
−
0
View file @
d60ac910
228 KiB
This diff is collapsed.
Click to expand it.
vikto_dev/main.cpp
0 → 100644
+
111
−
0
View file @
d60ac910
#include
<SFML/Graphics.hpp>
#include
<vector>
#include
<iostream>
int
main
()
{
// VARIABLES
sf
::
Clock
movementClock
;
// delta Time for movement
sf
::
Clock
gameTime
;
// Total game run time
sf
::
Clock
spawnTime
;
// delta time for spawning objects
// WINDOW
sf
::
RenderWindow
window
(
sf
::
VideoMode
(
640
,
640
),
"SFML works!"
);
// TEXTURE AND SPRITE
sf
::
Texture
devTex
;
sf
::
Sprite
devSprite
;
if
(
!
devTex
.
loadFromFile
(
"Textures/devil.png"
))
{
std
::
cout
<<
"Image not found"
<<
std
::
endl
;
}
devSprite
.
setTexture
(
devTex
);
devSprite
.
setScale
(
0.4f
,
10.5f
);
// SHAPES
sf
::
RectangleShape
shape
(
sf
::
Vector2f
(
200.f
,
50.f
));
shape
.
setPosition
(
window
.
getSize
().
x
/
2
-
shape
.
getSize
().
x
/
2
,
window
.
getSize
().
y
+
shape
.
getSize
().
y
);
// A the center of the window
shape
.
setFillColor
(
sf
::
Color
::
Green
);
// Vector storing all the shapes
std
::
vector
<
sf
::
RectangleShape
>
shapes
;
shapes
.
push_back
(
sf
::
RectangleShape
(
shape
));
while
(
window
.
isOpen
())
{
sf
::
Event
event
;
while
(
window
.
pollEvent
(
event
))
{
if
(
event
.
type
==
sf
::
Event
::
Closed
)
window
.
close
();
}
// UPDATE
// moving the shapes
if
(
gameTime
.
getElapsedTime
().
asSeconds
()
<
3
)
{
if
(
movementClock
.
getElapsedTime
().
asMilliseconds
()
>
1.f
)
{
// FOR MOVING THE SHAPES INSIDE THE VECTOR OF SHAPES
/*for (size_t i = 0; i < shapes.size(); i++)
{
shapes[i].move(0.f, -0.4f * movementClock.getElapsedTime().asMilliseconds());
if (shapes[i].getPosition().y < 0 - shape.getSize().y) {
shapes.erase(shapes.begin() + i);
}
}*/
devSprite
.
move
(
0.f
,
-
0.4f
*
movementClock
.
getElapsedTime
().
asMilliseconds
());
movementClock
.
restart
();
}
}
else
{
if
(
movementClock
.
getElapsedTime
().
asMilliseconds
()
>
1.f
)
{
// FOR MOVING THE SHAPES INSIDE THE VECTOR OF SHAPES
/*for (size_t i = 0; i < shapes.size(); i++)
{
shapes[i].move(0.f, -0.1f * movementClock.getElapsedTime().asMilliseconds());
if (shapes[i].getPosition().y < 0 - shape.getSize().y) {
shapes.erase(shapes.begin() + i);
}
}*/
devSprite
.
move
(
0.f
,
-
0.1f
*
movementClock
.
getElapsedTime
().
asMilliseconds
());
movementClock
.
restart
();
}
}
// FOR SPAWNING SHAPES
/*if (gameTime.getElapsedTime().asSeconds() < 3)
{
if (spawnTime.getElapsedTime().asMilliseconds() > 300.f) {
shapes.push_back(sf::RectangleShape(shape));
spawnTime.restart();
}
}
else
{
if (spawnTime.getElapsedTime().asMilliseconds() > 1000.f) {
shapes.push_back(sf::RectangleShape(shape));
spawnTime.restart();
}
}*/
// DRAW
window
.
clear
();
// FOR DRAWING THE SHAPES INSIDE THE VECTOR OF SHAPES
/*for (size_t i = 0; i < shapes.size(); i++)
{
window.draw(shapes[i]);
}*/
window
.
draw
(
devSprite
);
window
.
display
();
}
return
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