fucbillgates
Member
WIP GAMES, WIP FOREVER! Learning C++
I have been trying to focus and make something complete, Other projects I made fell into obscurity.
I have never taken classes on programming so my code is probable weird, Made more artwork then code
so most of my projects are testing how to get things working using some lib or another.
NEWER SFML PROJECT :: TICTAKTOE INTERFACE.
I was getting the hang of making things in sfml, decided to make a small part of a game as fast as possible.
This project just has a start button that then displays the board and when you click it it changes to the opposing
tile type on next click. This project took almost no time to make since I had to only make the tiles using a existing
blank tile and then a quick and dirty hashing out the game mechanics. This does not even have a winning case
it's just a board that displays one tile type then the other. This was one of a few under 1 hour dev projects I was
making a few months back.
Getting into the older stuff!
Here is another SFML project that does next to nothing, This one moves little guys around the screen changing the direction the object
moves depending on what part of the image your hovering over with the mouse. I ended up spending more time drawing the funny little
character then I did coding it. This one also has the issue that the mouse hover event only fires 1 time and does not recheck unless you
move the mouse again so you have to keep the mouse moving all the time to keep the little guy moving. I could fix it but I was just doing
a little practice and was trying to restrict my self to taking less then 1 hour in total to make it. And looking at the code for a second
I did not even bother to remove all of the tic tak toe code that I used as a base.
Super early project.
This next one is a full on 2d game engine that I started trying to make and was also one of the first things I ever
coded, I was shooting too high. I set this one up so that you could open different windows that would run splash screens on a timer
and the landscape is a manual sinusoidal wave generator that populates a tile map system that can be expanded to any size and has
any possible number of waves able to be generated over the first wave so you could have the landscape be not too wave like.
It also has a sound system setup so music plays in the background. I also started getting into doing collision detection for the moving
objects but realized that I needed more self training on how physics engines work and how to do aabb collision ect.
This one has too much code to post here, and It's super messy crap code since I had no idea what I was doing for the most part.
I have more projects to throw on here but this is a good start to the topic, I will update in a bit.
I have been trying to focus and make something complete, Other projects I made fell into obscurity.
I have never taken classes on programming so my code is probable weird, Made more artwork then code
so most of my projects are testing how to get things working using some lib or another.
NEWER SFML PROJECT :: TICTAKTOE INTERFACE.
I was getting the hang of making things in sfml, decided to make a small part of a game as fast as possible.
This project just has a start button that then displays the board and when you click it it changes to the opposing
tile type on next click. This project took almost no time to make since I had to only make the tiles using a existing
blank tile and then a quick and dirty hashing out the game mechanics. This does not even have a winning case
it's just a board that displays one tile type then the other. This was one of a few under 1 hour dev projects I was
making a few months back.
Code:
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
int FlatMenu(int Recsize1,int Recsize2,int Recposx,int Recposy,sf::Font Font,sf::Texture BackGround,sf::Sprite SpriteNode,sf::RenderWindow* Pwindow,int ImgSizex,int ImgSizey)
{
//THE START MENU BOX
sf::RectangleShape Rectangle(sf::Vector2f(Recsize1, Recsize2));
Rectangle.setFillColor(sf::Color(200, 200, 200));
Rectangle.setOutlineThickness(1);
Rectangle.setOutlineColor(sf::Color(100, 100, 100));
Rectangle.setPosition(Recposx,Recposy);
//SETUP A TEXTURE TO PUT ONTO THE SHAPE
Rectangle.setTexture(&BackGround);
Rectangle.setTextureRect(sf::IntRect(1, 1, ImgSizex, ImgSizey));
SpriteNode.setTexture(BackGround);
Pwindow->draw(Rectangle);
return 1;
}
int main()
{
//CREATE THE WINDOW
sf::RenderWindow Window(sf::VideoMode(800, 600), "My window");
sf::RenderWindow* Pwindow;
Window.setVerticalSyncEnabled(true);
Window.setFramerateLimit(60);
//SETUP A FONT
sf::Sprite SpriteNode;
sf::Texture BackGround;
sf::Texture TileX;
sf::Texture TileO;
sf::Texture Board;
sf::Font Font;
//TRIGGERS NEED TO PROPAGATE THREW MORE THEN ONE FRAME SO THEY ARE MADE HERE
int TurnTrigger=1;
int TriggerArray[9] = {3,3,3,3,3,3,3,3,3};
int *Trigger=TriggerArray;
if (!Font.loadFromFile("arial.ttf"))
{
//Error...
}
//LOAD A IMAGE
if (!BackGround.loadFromFile("../../Media/WindowBG.png"))
{
//Error...
}
if (!TileX.loadFromFile("../../Media/TileX.png"))
{
//Error...
}
if (!TileO.loadFromFile("../../Media/TileO.png"))
{
//Error...
}
if (!Board.loadFromFile("../../Media/Board.png"))
{
//Error...
}
//CREATE THE SCENE VARIABLE
int Scene=1;
// WHILE THE WINDOW IS OPEN RUN THE FOLLOWING CODE
while (Window.isOpen())
{
// CHECK ALL THE EVENTS TRIGGERED SINCE THE LAST ITTERATION OF THIS LOOP
sf::Event event;
while (Window.pollEvent(event))
{
//CLEAR LAST SCENE
Window.clear(sf::Color::Black);
//USE THE SCENE VAR TO INDICATE WHAT SCENE TO DISPLAY
if (Scene==1)
{
sf::Text Text;
Text.setFont(Font); // font is a sf::Font
Text.setString("TickTacToe Board Using GUI Elements");
Text.setCharacterSize(24); // in pixels, not points!
Window.draw(Text);
//RUN THE FLATMENU FUNCTION
int SizeX=226;
int SizeY=174;
int PosX=275;
int PosY=200;
Pwindow=&Window;
FlatMenu(SizeX,SizeY,PosX,PosY,Font,BackGround,SpriteNode,Pwindow,SizeX,SizeY);
//ON LEFT MOUSE CLICK
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
//GET MOUSE POSITION
sf::Vector2i localPosition = sf::Mouse::getPosition(Window);
//IF THE MOUSE IS WITHIN THE BOX BEING DISPLAYED
if (localPosition.x>PosX&&localPosition.x<PosX+SizeX)
{
if (localPosition.y>PosY&&localPosition.y<PosY+SizeY)
{
//KILL THE BOX TO SHOW IT WORKS
Scene++;
}
}
}
}
//SECOND SCENE IS THE GAMEBOARD
else if (Scene==2)
{
//RUN THE FLATMENU FUNCTION PLACING EACH TILE OF THE BOARD
int PosXOffset=50;
int PosYOffset=50;
int PosX=PosXOffset;
int PosY=PosYOffset;
int SizeX=138;
int SizeY=138;
//GET MOUSE POSITION
sf::Vector2i localPosition = sf::Mouse::getPosition(Window);
//RUN A FOR X FOR Y LOOP
for (int i=0;i<3;i++)
{
for (int h=0;h<3;h++)
{
Pwindow=&Window;
//USE AS BINDINGS FOR THE CORDS OF TILES
if (TriggerArray[i*3+h]==1){FlatMenu(SizeX,SizeY,PosX+(SizeX*h),PosY+(SizeY*i),Font,TileO,SpriteNode,Pwindow,SizeX,SizeY);}
else if (TriggerArray[i*3+h]==2){FlatMenu(SizeX,SizeY,PosX+(SizeX*h),PosY+(SizeY*i),Font,TileX,SpriteNode,Pwindow,SizeX,SizeY);}
else {FlatMenu(SizeX,SizeY,PosX+(SizeX*h),PosY+(SizeY*i),Font,Board,SpriteNode,Pwindow,SizeX,SizeY);}
//ON LEFT MOUSE CLICK CHANGE THE TILE TO THE TYPE FOR THE CURRENT PLAYER
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
//IF THE MOUSE X IS > THE (CURRENT TILE'S X)+OFFSETX AND THE MOUSE X IS < THE (CURRENT TILE'S X)+138
if (localPosition.x>(h*138)+PosXOffset && localPosition.x<(h*138)+PosXOffset+SizeX)
{
if (localPosition.y>(i*138)+PosYOffset && localPosition.y<(i*138)+PosYOffset+SizeY)
{
if (TurnTrigger==1)
{
//I*H=Y +h=X TO GET POSITION IN TRIGGER ARRAY THATS A 1D REPERSENTATION OF THE SAME BOARD
TriggerArray[i*3+h]=2;
TurnTrigger=2;
}
else if (TurnTrigger==2)
{
TriggerArray[i*3+h]=1;
TurnTrigger=1;
}
}
}
}
}
}
}
//IF A WINDOW CLOSE EVENT FIRES THEN KILL THE WINDOW
if (event.type == sf::Event::Closed)
{
Window.close();
}
//DISPLAY THIS FRAME
Window.display();
}
}
return 0;
}
Getting into the older stuff!
Here is another SFML project that does next to nothing, This one moves little guys around the screen changing the direction the object
moves depending on what part of the image your hovering over with the mouse. I ended up spending more time drawing the funny little
character then I did coding it. This one also has the issue that the mouse hover event only fires 1 time and does not recheck unless you
move the mouse again so you have to keep the mouse moving all the time to keep the little guy moving. I could fix it but I was just doing
a little practice and was trying to restrict my self to taking less then 1 hour in total to make it. And looking at the code for a second
I did not even bother to remove all of the tic tak toe code that I used as a base.
Code:
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
sf::RectangleShape FlatMenu(int Recsize1,int Recsize2,int Recposx,int Recposy,sf::Font Font,sf::Texture BackGround,sf::Sprite SpriteNode,sf::RenderWindow* Pwindow,int ImgSizex,int ImgSizey)
{
//THE START MENU BOX
sf::RectangleShape Rectangle(sf::Vector2f(Recsize1, Recsize2));
Rectangle.setFillColor(sf::Color(200, 200, 200));
Rectangle.setOutlineThickness(0);
Rectangle.setOutlineColor(sf::Color(100, 100, 100));
Rectangle.setPosition(Recposx,Recposy);
//SETUP A TEXTURE TO PUT ONTO THE SHAPE
Rectangle.setTexture(&BackGround);
Rectangle.setTextureRect(sf::IntRect(1, 1, ImgSizex, ImgSizey));
SpriteNode.setTexture(BackGround);
return Rectangle;
}
int main()
{
//CREATE THE WINDOW
sf::RenderWindow Window(sf::VideoMode(800, 600), "My window");
sf::RenderWindow* Pwindow;
Window.setVerticalSyncEnabled(true);
Window.setFramerateLimit(60);
//SETUP A FONT
sf::Sprite SpriteNode;
sf::Sprite SpriteNode2;
sf::Texture BackGround;
sf::Texture TileX;
sf::Texture TileO;
sf::Texture Board;
sf::Texture Character;
sf::Font Font;
int ShapeX=100;
int ShapeY=100;
int ShapeX2=100;
int ShapeY2=100;
int S=100;
//TRIGGERS NEED TO PROPAGATE THREW MORE THEN ONE FRAME SO THEY ARE MADE HERE
int TriggerArray[9] = {3,3,3,3,3,3,3,3,3};
int *Trigger=TriggerArray;
//LOAD RECOURCE FILES
if (!Font.loadFromFile("arial.ttf"))
{
//Error...
}
//LOAD A IMAGE
if (!BackGround.loadFromFile("../../Media/WindowBG.png"))
{
//Error...
}
if (!TileX.loadFromFile("../../Media/TileX.png"))
{
//Error...
}
if (!TileO.loadFromFile("../../Media/TileO.png"))
{
//Error...
}
if (!Board.loadFromFile("../../Media/Board.png"))
{
//Error...
}
if (!Character.loadFromFile("../../Media/Character.png"))
{
//Error...
}
//CREATE THE SCENE VARIABLE
int Scene=1;
// WHILE THE WINDOW IS OPEN RUN THE FOLLOWING CODE
while (Window.isOpen())
{
// CHECK ALL THE EVENTS TRIGGERED SINCE THE LAST ITTERATION OF THIS LOOP
sf::Event event;
while (Window.pollEvent(event))
{
//CLEAR LAST SCENE
Window.clear(sf::Color::Black);
//USE THE SCENE VAR TO INDICATE WHAT SCENE TO DISPLAY
if (Scene==1)
{
sf::Text Text;
Text.setFont(Font); // font is a sf::Font
Text.setString("Hover Movement on GUI Elements");
Text.setCharacterSize(24); // in pixels, not points!
Window.draw(Text);
//RUN THE FLATMENU FUNCTION
int SizeX=226;
int SizeY=174;
int PosX=275;
int PosY=200;
Window.draw(FlatMenu(SizeX,SizeY,PosX,PosY,Font,BackGround,SpriteNode,Pwindow,SizeX,SizeY));
//ON LEFT MOUSE CLICK
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
//GET MOUSE POSITION
sf::Vector2i localPosition = sf::Mouse::getPosition(Window);
//IF THE MOUSE IS WITHIN THE BOX BEING DISPLAYED
if (localPosition.x>PosX&&localPosition.x<PosX+SizeX)
{
if (localPosition.y>PosY&&localPosition.y<PosY+SizeY)
{
//KILL THE BOX TO SHOW IT WORKS
Scene++;
}
}
}
}
//SECOND SCENE IS THE GAMEBOARD
else if (Scene==2)
{
int SizeX=100;
int SizeY=100;
ShapeX2++;
ShapeY2++;
Window.draw(FlatMenu(SizeX,SizeY,ShapeX2,ShapeY2,Font,Character,SpriteNode2,Pwindow,SizeX,SizeY));
Window.draw(FlatMenu(SizeX,SizeY,ShapeX,ShapeY,Font,Character,SpriteNode,Pwindow,SizeX,SizeY));
//GET MOUSE POSITION
sf::Vector2i localPosition = sf::Mouse::getPosition(Window);
//IF IN THE TOP RIGHT CORNER
if (localPosition.x>ShapeX+(SizeX/2)&&localPosition.x<ShapeX+SizeX)
{
if (localPosition.y>ShapeY+(SizeY/2)&&localPosition.y<ShapeY+SizeY)
{
ShapeX++;
ShapeY++;
}
}
//IF IN THE BOTTOM LEFT
if (localPosition.x>ShapeX&&localPosition.x<ShapeX+(SizeX/2))
{
if (localPosition.y>ShapeY&&localPosition.y<ShapeY+(SizeY/2))
{
ShapeX--;
ShapeY--;
}
}
//IF IN THE TOP LEFT
if (localPosition.x>ShapeX&&localPosition.x<ShapeX+(SizeX/2))
{
if (localPosition.y>ShapeY+(SizeY/2)&&localPosition.y<ShapeY+ShapeY)
{
ShapeX--;
ShapeY++;
}
}
//IF IN THE BOTTOM RIGHT
if (localPosition.x>ShapeX+(SizeX/2)&&localPosition.x<ShapeX+SizeX)
{
if (localPosition.y>ShapeY&&localPosition.y<ShapeY+(SizeY/2))
{
ShapeX++;
ShapeY--;
}
}
}
//IF A WINDOW CLOSE EVENT FIRES THEN KILL THE WINDOW
if (event.type == sf::Event::Closed)
{
Window.close();
}
//DISPLAY THIS FRAME
Window.display();
}
}
return 0;
}
Super early project.
This next one is a full on 2d game engine that I started trying to make and was also one of the first things I ever
coded, I was shooting too high. I set this one up so that you could open different windows that would run splash screens on a timer
and the landscape is a manual sinusoidal wave generator that populates a tile map system that can be expanded to any size and has
any possible number of waves able to be generated over the first wave so you could have the landscape be not too wave like.
It also has a sound system setup so music plays in the background. I also started getting into doing collision detection for the moving
objects but realized that I needed more self training on how physics engines work and how to do aabb collision ect.
This one has too much code to post here, and It's super messy crap code since I had no idea what I was doing for the most part.
I have more projects to throw on here but this is a good start to the topic, I will update in a bit.