#include <SFML/Graphics.hpp>
#include <time.h>
using namespace sf;
const int M = 20;
const int N = 10;
int field[M][N] = { 0 };
struct Point
{
int x, y;
} a[4], b[4];
int figures[7][4] =
{
1,3,5,7, // I
2,4,5,7, // Z
3,5,4,6, // S
3,5,4,7, // T
2,3,5,7, // L
3,5,7,6, // J
2,3,4,5, // O
};
bool check()
{
for (int i = 0; i < 4; i++)
if (a[i].x < 0 || a[i].x >= N || a[i].y >= M) return 0;
else if (field[a[i].y][a[i].x]) return 0;
return 1;
};
int main()
{
srand(time(0));
RenderWindow window(VideoMode(320, 480), "The Game!");
Texture t1, t2, t3;
t1.loadFromFile("images/tiles.png");
t2.loadFromFile("images/background.png");
t3.loadFromFile("images/frame.png");
Sprite s(t1), background(t2), frame(t3);
int dx = 0; bool rotate = 0; int colorNum = 1;
float timer = 0, delay = 0.3;
Clock clock;
while (window.isOpen())
{
float time = clock.getElapsedTime().asSeconds();
clock.restart();
timer += time;
Event e;
while (window.pollEvent(e))
{
if (e.type == Event::Closed)
window.close();
if (e.type == Event::KeyPressed)
if (e.key.code == Keyboard::Up) rotate = true;
else if (e.key.code == Keyboard::Left) dx = -1;
else if (e.key.code == Keyboard::Right) dx = 1;
}
if (Keyboard::isKeyPressed(Keyboard::Down)) delay = 0.05;
//// <- Move -> ///
for (int i = 0; i < 4; i++) { b[i] = a[i]; a[i].x += dx; }
if (!check()) for (int i = 0; i < 4; i++) a[i] = b[i];
//////Rotate//////
if (rotate)
{
Point p = a[1]; //center of rotation
for (int i = 0; i < 4; i++)
{
int x = a[i].y - p.y;
int y = a[i].x - p.x;
a[i].x = p.x - x;
a[i].y = p.y + y;
}
if (!check()) for (int i = 0; i < 4; i++) a[i] = b[i];
}
///////Tick//////
if (timer > delay)
{
for (int i = 0; i < 4; i++) { b[i] = a[i]; a[i].y += 1; }
if (!check())
{
for (int i = 0; i < 4; i++) field[b[i].y][b[i].x] = colorNum;
colorNum = 1 + rand() % 7;
int n = rand() % 7;
for (int i = 0; i < 4; i++)
{
a[i].x = figures[n][i] % 2;
a[i].y = figures[n][i] / 2;
}
}
timer = 0;
}
///////check lines//////////
int k = M - 1;
for (int i = M - 1; i > 0; i--)
{
int count = 0;
for (int j = 0; j < N; j++)
{
if (field[i][j]) count++;
field[k][j] = field[i][j];
}
if (count < N) k--;
}
dx = 0; rotate = 0; delay = 0.3;
/////////draw//////////
window.clear(Color::White);
window.draw(background);
for (int i = 0; i < M; i++)
for (int j = 0; j < N; j++)
{
if (field[i][j] == 0) continue;
s.setTextureRect(IntRect(field[i][j] * 18, 0, 18, 18));
s.setPosition(j * 18, i * 18);
s.move(28, 31); //offset
window.draw(s);
}
for (int i = 0; i < 4; i++)
{
s.setTextureRect(IntRect(colorNum * 18, 0, 18, 18));
s.setPosition(a[i].x * 18, a[i].y * 18);
s.move(28, 31); //offset
window.draw(s);
}
window.draw(frame);
window.display();
}
return 0;
}
Hi,
I'm having some issues with the SFML Tetris tutorial with the Release version.
I tried using Debug mode and it works (see image 1).
However, the Release -s version is most confusing. (see image 2)
These are the Additional Dependencies for the Linker.
freetype.lib;gdi32.lib;opengl32.lib;winmm.lib;sfml-system-s.lib;sfml-window-s.lib;sfml-graphics-s.lib;sfml-network-s.lib;sfml-audio-s.lib;%(AdditionalDependencies)
Does the order of .lib entry have a major impact? ie the errror message seem to be dependent on the order I set the .lib files
What am I missing?
References
https://www.sfml-dev.org/tutorials/2.5/start-vc.phpBuild started...
1>------ Build started: Project: smflTetris, Configuration: Release Win32 ------
1>LINK : fatal error LNK1181: cannot open input file 'sfml-system-s.lib'
1>Done building project "smflTetris.vcxproj" -- FAILED.
1>
1>Project Performance Summary:
1> 154 ms C:\Users\user\source\repos\smflTetris\smflTetris\smflTetris.vcxproj 1 calls
1>
1>Target Performance Summary:
1> 0 ms _CheckForInvalidConfigurationAndPlatform 1 calls
1> 0 ms _ResourceCompile 1 calls
1> 0 ms AfterResourceCompile 1 calls
1> 0 ms MakeDirsForResourceCompile 1 calls
1> 0 ms BeforeResourceCompile 1 calls
1> 0 ms _ClCompile 1 calls
1> 0 ms AfterClCompile 1 calls
1> 0 ms SelectClCompile 1 calls
1> 0 ms MakeDirsForCl 1 calls
1> 0 ms FixupCLCompileOptions 1 calls
1> 0 ms WarnCompileDuplicatedFilename 1 calls
1> 0 ms ComputeReferenceCLInput 1 calls
1> 0 ms GetReferencedVCProjectsInfo 1 calls
1> 0 ms FindReferenceAssembliesForReferences 1 calls
1> 0 ms ComputeCLInputPDBName 1 calls
1> 0 ms BeforeClCompile 1 calls
1> 0 ms AfterBuildCompileEvent 1 calls
1> 0 ms _BuildCompileAction 1 calls
1> 0 ms BuildCompile 1 calls
1> 0 ms BuildLinkTraverse 1 calls
1> 0 ms PreLinkEvent 1 calls
1> 0 ms DoLinkOutputFilesMatch 1 calls
1> 0 ms MakeDirsForLink 1 calls
1> 0 ms PrepareResourceNames 1 calls
1> 0 ms CreateCustomManifestResourceNames 1 calls
1> 0 ms SplitResourcesByCulture 1 calls
1> 0 ms AssignTargetPaths 1 calls
1> 0 ms BuildCompileTraverse 1 calls
1> 0 ms ComputeManifestInputsTargets 1 calls
1> 0 ms ComputeCLGeneratedLinkInputs 1 calls
1> 0 ms ComputeCLOutputs 1 calls
1> 0 ms ComputeManifestGeneratedLinkerInputs 1 calls
1> 0 ms ComputeRCGeneratedLinkInputs 1 calls
1> 0 ms ComputeRCOutputs 1 calls
1> 0 ms BeforeLink 1 calls
1> 0 ms ComputeLegacyManifestEmbedding 1 calls
1> 0 ms ComputeLinkInputsFromProject 1 calls
1> 0 ms ComputeLinkSwitches 1 calls
1> 0 ms BuildGenerateSources 1 calls
1> 0 ms AfterBuildGenerateSourcesEvent 1 calls
1> 0 ms PrepareForBuild 1 calls
1> 0 ms SetCABuildNativeEnvironmentVariables 1 calls
1> 0 ms _CheckWindowsSDKInstalled 1 calls
1> 0 ms GetResolvedWinMD 1 calls
1> 0 ms SetBuildDefaultEnvironmentVariables 1 calls
1> 0 ms GetReferenceAssemblyPaths 1 calls
1> 0 ms GetFrameworkPaths 1 calls
1> 0 ms ResolveSDKReferences 1 calls
1> 0 ms ResolveProjectReferences 1 calls
1> 0 ms _GetProjectReferenceTargetFrameworkProperties 1 calls
1> 0 ms _SplitProjectReferencesByFileExistence 1 calls
1> 0 ms AssignProjectConfiguration 1 calls
1> 0 ms BeforeResolveReferences 1 calls
1> 0 ms _PrepareForReferenceResolution 1 calls
1> 0 ms _PrepareForBuild 1 calls
1> 0 ms SetTelemetryEnvironmentVariables 1 calls
1> 0 ms PrepareProjectReferences 1 calls
1> 0 ms ExpandSDKReferences 1 calls
1> 0 ms ResolveAssemblyReferences 1 calls
1> 0 ms AfterResolveReferences 1 calls
1> 0 ms AfterMidl 1 calls
1> 0 ms ComputeMIDLGeneratedCompileInputs 1 calls
1> 0 ms MakeDirsForMidl 1 calls
1> 0 ms _Xsd 1 calls
1> 0 ms CopyFileToFolders 1 calls
1> 0 ms CustomBuild 1 calls
1> 0 ms _BuildGenerateSourcesAction 1 calls
1> 0 ms SelectCustomBuild 1 calls
1> 0 ms _SelectedFiles 1 calls
1> 0 ms PreBuildEvent 1 calls
1> 0 ms BeforeBuildGenerateSources 1 calls
1> 0 ms BuildGenerateSourcesTraverse 1 calls
1> 0 ms InitializeBuildStatus 1 calls
1> 0 ms ResolveReferences 1 calls
1> 0 ms _Midl 1 calls
1> 0 ms AfterBuildGenerateSources 1 calls
1> 7 ms ClCompile 1 calls
1> 16 ms ComputeCustomBuildOutput 1 calls
1> 132 ms Link 1 calls
1>
1>Task Performance Summary:
1> 0 ms Message 2 calls
1> 0 ms SetEnv 8 calls
1> 0 ms AssignProjectConfiguration 1 calls
1> 0 ms MSBuild 1 calls
1> 0 ms MakeDir 7 calls
1> 0 ms CheckVCToolsetVersion 1 calls
1> 0 ms ReadLinesFromFile 1 calls
1> 0 ms WriteLinesToFile 1 calls
1> 0 ms Touch 1 calls
1> 0 ms GetOutOfDateItems 3 calls
1> 0 ms AssignTargetPath 4 calls
1> 0 ms AssignCulture 1 calls
1> 7 ms CL 1 calls
1> 132 ms Link 1 calls
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========