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
2bf71a52
Commit
2bf71a52
authored
4 years ago
by
Jonas Johan Solsvik
Browse files
Options
Downloads
Patches
Plain Diff
draw to players and ground
parent
98d6cb1b
No related branches found
No related tags found
1 merge request
!1
Fix #6, #7 and #8 - Open window, draw and move circle + collsion example
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
02-jumping-boxes/main.cpp
+74
-29
74 additions, 29 deletions
02-jumping-boxes/main.cpp
with
75 additions
and
29 deletions
.gitignore
+
1
−
0
View file @
2bf71a52
build/
build/
.vscode/
This diff is collapsed.
Click to expand it.
02-jumping-boxes/main.cpp
+
74
−
29
View file @
2bf71a52
...
@@ -3,31 +3,62 @@
...
@@ -3,31 +3,62 @@
#include
<SFML/Audio.hpp>
#include
<SFML/Audio.hpp>
#include
<SFML/Graphics.hpp>
#include
<SFML/Graphics.hpp>
int
main
()
auto
eventsUpdate
(
sf
::
RenderWindow
&
window
,
sf
::
View
&
camera
)
->
void
;
auto
renderUpdate
(
sf
::
RenderWindow
&
window
,
const
std
::
vector
<
sf
::
RectangleShape
>
&
players
,
const
sf
::
RectangleShape
&
ground
)
->
void
;
auto
main
()
->
int
{
{
// # Create the main window and camera
// # Create the main window and camera
//
const
int
WIDTH
=
600
;
// ## TODO
// - [ ] Make framerate limit adjustable
// - [ ] Make video and camera size the same as hardware window size
// - [ ] Resize video and camera size when user resizes window.
//
const
int
WIDTH
=
800
;
const
int
HEIGHT
=
600
;
const
int
HEIGHT
=
600
;
const
int
FRAMERATE_LIMIT
=
90
;
const
int
FRAMERATE_LIMIT
=
90
;
sf
::
RenderWindow
window
(
sf
::
VideoMode
(
WIDTH
,
HEIGHT
),
"Double trouble"
);
sf
::
RenderWindow
window
(
sf
::
VideoMode
(
WIDTH
,
HEIGHT
),
"Double trouble"
);
window
.
setFramerateLimit
(
FRAMERATE_LIMIT
);
window
.
setFramerateLimit
(
FRAMERATE_LIMIT
);
sf
::
View
camera
(
sf
::
FloatRect
(
0
,
0
,
WIDTH
,
HEIGHT
));
sf
::
View
camera
(
sf
::
FloatRect
(
0
,
0
,
WIDTH
,
HEIGHT
));
camera
.
setCenter
(
0
,
0
);
camera
.
setCenter
(
0
,
-
200
);
camera
.
setSize
(
WIDTH
,
HEIGHT
);
window
.
setView
(
camera
);
window
.
setView
(
camera
);
// # Create things
// # Create ground
sf
::
CircleShape
circle
;
sf
::
RectangleShape
ground
{
sf
::
Vector2f
{
4000
,
20
}};
circle
.
setPosition
(
0
,
0
);
ground
.
setPosition
(
-
2000
,
0
);
circle
.
setRadius
(
10
);
ground
.
setFillColor
(
sf
::
Color
::
White
);
circle
.
setFillColor
(
sf
::
Color
::
Red
);
// # Create players
std
::
vector
<
sf
::
Vector2f
>
playerPositions
{
sf
::
Vector2f
{
-
100
,
-
50
},
sf
::
Vector2f
{
100
,
-
50
},
};
std
::
vector
<
sf
::
Color
>
playerColors
{
sf
::
Color
::
Red
,
sf
::
Color
::
Blue
,
};
std
::
vector
<
sf
::
RectangleShape
>
players
(
2
);
for
(
auto
i
=
0
;
i
<
players
.
size
();
++
i
)
{
players
[
i
].
setFillColor
(
playerColors
[
i
]);
players
[
i
].
setSize
(
sf
::
Vector2f
{
50
,
50
});
players
[
i
].
setPosition
(
playerPositions
[
i
]);
}
while
(
window
.
isOpen
())
while
(
window
.
isOpen
())
{
eventsUpdate
(
window
,
camera
);
renderUpdate
(
window
,
players
,
ground
);
}
return
0
;
}
auto
eventsUpdate
(
sf
::
RenderWindow
&
window
,
sf
::
View
&
camera
)
->
void
{
{
// # Process events
// # Process events
sf
::
Event
event
;
sf
::
Event
event
;
...
@@ -40,12 +71,26 @@ int main()
...
@@ -40,12 +71,26 @@ int main()
{
{
window
.
close
();
window
.
close
();
}
}
if
(
event
.
type
==
sf
::
Event
::
Resized
)
{
sf
::
FloatRect
visibleArea
(
0
,
0
,
event
.
size
.
width
,
event
.
size
.
height
);
camera
.
setSize
(
event
.
size
.
width
,
event
.
size
.
height
);
window
.
setView
(
camera
);
}
}
}
}
auto
renderUpdate
(
sf
::
RenderWindow
&
window
,
const
std
::
vector
<
sf
::
RectangleShape
>
&
players
,
const
sf
::
RectangleShape
&
ground
)
->
void
{
// # Render video
// # Render video
window
.
clear
();
window
.
clear
();
window
.
draw
(
circle
);
for
(
auto
player
:
players
)
window
.
display
();
{
window
.
draw
(
player
);
}
}
return
0
;
window
.
draw
(
ground
);
window
.
display
();
}
}
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