Sure.. but my project is more complex and use many files and classes.
I don't put in forum only because I need a example guide for OOP.
globals.h:
static sf::RenderWindow rwin;
static sf::String sfs;
Trasporter.cpp:
#include <SFML/Graphics.hpp>
#include <cmath>
#include <sstream>
#include "globals.h"
#include "impianto.h"
int main() {
rwin.Create( sf::VideoMode( 1024, 768, 32 ), "Trasporter" ); //globalVar
sfs.SetSize( 24.f ); //globalVar with font setup
sfs.SetColor( sf::Color( 0, 0, 200) );
Impianto impianto;
sf::Image BackgroundIm, ImpiantoIm, CarroIm, PinzaIm, VascaIm, FornoIm, TelaioSpIm, TelaioUsIm, TelaioPlIm, LineaIm;
if (
!ImpiantoIm.LoadFromFile("datas/trasporter/Impianto.png") ||
.............................................
return EXIT_FAILURE;
}
sprBackground.SetImage(BackgroundIm);
sprImpianto.SetImage(ImpiantoIm);
............................................
// Ciclo programma
bool IsRunning = true;
while (IsRunning) { // Programma simulazione in funzione
sf::Event Event;
while (rwin.GetEvent(Event)) { // Controllo eventi finestra applicazione compresi tasti premuti
if (Event.Type == sf::Event::Closed) IsRunning = false;
if (Event.Type == sf::Event::KeyPressed) {
switch (Event.Key.Code) {
case sf::Key::Escape:
IsRunning = false;
break;
default:
break;
}
}
}
dtFrame = rwin.GetFrameTime() * dtFrameVel/100.f;
Stazioni_Gest();
// Draw all ///////////////
rwin.Draw(sprImpianto); // OK
impianto.draw(rwin); // Fail: no error / not drawed
rwin.Display(); // Display things on screen
} // while IsRunning
return EXIT_SUCCESS;
}
impianto.h
#ifndef IMPIANTO_H_INCLUDED
#define IMPIANTO_H_INCLUDED
#include <SFML/Graphics.hpp>
#include "stazione.h"
#include "carro.h"
using namespace std;
class Impianto {
public:
Impianto();
~Impianto();
float get_nstazioni() { return stazioni.size(); }
void set_aut(int m);
void set_ciclo(int m);
void gest(float dt);
void draw(sf::RenderWindow &); // <<<<<<<
void drawInfo();
bool aut; // man / aut(Semia|Ciclo)
bool ciclo; // Ciclo Automatico in esecuzione
bool VaCoppie; // Vasche operanti a coppie
int dxEngage; // dx Aggancio: se 0 usa metodo a Pinzatura Verticale
int iProgr; // Programma Ciclo Aut
int tSgocc; // Tempo di sgocciolamento sulle vasche
Telai telai;
Stazioni stazioni;
Carro carroSx, carroDx;
};
impianto.cpp:
#include <cmath>
#include <string>
#include <SFML/Graphics.hpp>
#include "impianto.h"
#include "globals.h"
#include "futy.h"
using namespace std;
Impianto::Impianto() //Impianto crea lui Telai e Stazioni e Carri
:telai()
,stazioni()
,carroSx( telai, stazioni )
,carroDx( telai, stazioni ) {
aut = true;
ciclo = true;
iProgr = 1;
VaCoppie = false;
tSgocc = 2;
dxEngage = 6; // dxAggancio Telaio
int i;
std::stringstream ss, ssLog, ssKey;
// Define the stations
float dxst = stazioni.dxStazioni;
int ist = 0;
//Stazione& st = stazioni[0];
//st = stazioni[ist];
Stazione st;
st.set_tipo( Stazione::CARICO );
st.set_tOn( 1 );
st.set_termoSet( 0 );
for ( i=0; i<stazioni.nCarScar; i++ ) { // Carico
st.set_name( "St" + tostring(i) + "\n" + "Ca" );
st.set_pos( rifx + ((i-7)*dxst)-27 );
stazioni.push_back(st);
}
st.set_tipo( Stazione::VASCA );
st.set_tOn( 60 );
for ( i=0; i<stazioni.nVasche; i++ ) { // Vasche
st.set_name( "St" + tostring(i) + "\n" + "V" + tostring(i+1) );
st.set_pos( rifx + ((i-7)*dxst)-27 );
st.set_termoSet( 90-i*6 );
stazioni.push_back(st);
}
st.set_tipo( Stazione::FORNO );
st.set_tOn( 120 );
st.set_termoSet( 120 );
for ( i=0; i<stazioni.nCarScar; i++ ) { // Forno
st.set_name( "St" + tostring(i) + "\n" + "F" + tostring(i+1) );
st.set_pos( rifx + ((i-7)*dxst)-27 );
stazioni.push_back(st);
}
st.set_tipo( Stazione::SCARICO );
st.set_tOn( 1 );
st.set_termoSet( 0 );
for ( i=0; i<stazioni.nCarScar; i++ ) { // Scarico
st.set_name( "St" + tostring(i) + "\n" + "Sc" );
st.set_pos( rifx + ((i-7)*dxst)-27 );
stazioni.push_back(st);
}
// Define Carri properties
// for (i=0;i<mCarri;i++) Carro_Init( carro[i], i );
return;
};
Impianto::~Impianto() {
return;
};
void Impianto::set_aut(int a) {
aut = a;
};
void Impianto::set_ciclo(int c) {
ciclo = c;
};
//--
void Impianto::gest(float dt) {
};
void Impianto::draw(sf::RenderWindow & prwin) { //<<<<<<<<<<<<<<
sf::Color cBackground( 0,255,0 );
rwin.SetBackgroundColor( cBackground ); // GlobalVar dont run
prwin.SetBackgroundColor( cBackground ); // Par.Var run ok
sfs.SetX(110);
sfs.SetY(110);
sfs.SetText("******************************************\n");
rwin.Draw(sfs); // GlobalVar dont run
prwin.Draw(sfs); // Par.Var run Ok
};
I can pass "sf::RenderWindow & prwin"
to all objects but I find a clear OOP code.
I need other different classes that need to Draw..
..some of this is collected in Vector class..
I prefer to not pass "sf::RenderWindow & prwin"
through many and many classes if possible:
Vector class is only a collector class.
I simply ask for OOP tutorial similar to "Missile" class.
I need to mantain separate class functions and graph?
If you want to see my project, objects (classes now)
I have the complete exe of version 1 without any class. (1MB)
Thanks in advance for any help.