i defined game class globally in main.cpp like this:
#include "game.h"
#include <QApplication>
#include <QTextCodec>
Game *game;
int main(int argc, char *argv[])
{
srand(time(0));
game = new Game;
game->show();
return a.exec();
}
#include "game.h"
#include <QApplication>
#include <QTextCodec>
Game *game;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
srand(time(0));
game = new Game;
game->show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
And in the Bars.cpp its initialized like this:
#include "game.h"
extern Game *game;
#include "game.h"
extern Game *game;
To copy to clipboard, switch view to plain text mode
And if it helps here is the game.h file
#ifndef GAME_H
#define GAME_H
#include "player.h"
#include "button.h"
#include "sea.h"
#include "land.h"
#include "hotbarslots.h"
#include "soundeffects.h"
#include "story.h"
#include "rabbithole.h"
#include "tree.h"
#include "rock.h"
#include "bars.h"
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QObject>
#include <QMouseEvent>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsScene>
#include <QWidget>
#include <QKeyEvent>
Q_OBJECT
public:
// this class stuff
static int language; // 0~ENG, 1~SLO,
void languageMenu();
void menu();
void createMap();
void createPlayer();
void createHotbarSlots();
void spawnAnimals();
void spawnTrees();
void spawnRocks();
void drawBars();
void setStopRectCreated(bool t);
bool getStopRectCreated();
int getDesktopHeight();
int getDesktopWidth();
int getViewHeight();
int getViewWidth();
void setViewWidthToDesktop();
void setViewHeightToDesktop();
void setViewWidthToNormal();
void setViewHeightToNormal();
void changeColorOfButton();
// dark screen stuff
void deleteDarkScreen();
// other class stuff
RabbitHole *rabbitHole;
Story *story;
Player *player;
Land *land;
Sea *sea;
HotbarSlots *hotbarSlots;
SoundEffects *soundEffects;
Tree *tree[3];
Rock *rock[3];
Bars *bars;
// static stuff
private:
// dark screen stuff
double darking_opacity;
bool dark_screen_on;
// this class stuff
int curr_pos_in_menu;
bool stop_rect_created;
int desktop_height;
int desktop_width;
int current_height;
int current_width;
int starting_width;
int starting_height;
public slots:
void setLanguageToSlovenian();
void setLanguageToEnglish();
void startStory();
void start();
// dark screen stuff
void screenGoesDark();
void screenComesFromDark();
};
#endif // GAME_H
#ifndef GAME_H
#define GAME_H
#include "player.h"
#include "button.h"
#include "sea.h"
#include "land.h"
#include "hotbarslots.h"
#include "soundeffects.h"
#include "story.h"
#include "rabbithole.h"
#include "tree.h"
#include "rock.h"
#include "bars.h"
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QObject>
#include <QMouseEvent>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsScene>
#include <QWidget>
#include <QKeyEvent>
class Game: public QGraphicsView{
Q_OBJECT
public:
// this class stuff
static QString in_room;
static QString day_or_night;
static int language; // 0~ENG, 1~SLO,
Game(QWidget *parent=NULL);
QGraphicsScene *scene;
void languageMenu();
void menu();
void createMap();
void createPlayer();
void createHotbarSlots();
void spawnAnimals();
void spawnTrees();
void spawnRocks();
void drawBars();
void setStopRectCreated(bool t);
bool getStopRectCreated();
int getDesktopHeight();
int getDesktopWidth();
int getViewHeight();
int getViewWidth();
void setViewWidthToDesktop();
void setViewHeightToDesktop();
void setViewWidthToNormal();
void setViewHeightToNormal();
void changeColorOfButton();
QGraphicsRectItem *stopRect;
void wheelEvent(QWheelEvent *event);
// dark screen stuff
QGraphicsRectItem *darkScreen;
QTimer *darkScreenTimer;
void deleteDarkScreen();
// other class stuff
RabbitHole *rabbitHole;
Story *story;
Player *player;
Land *land;
Sea *sea;
HotbarSlots *hotbarSlots;
SoundEffects *soundEffects;
Tree *tree[3];
Rock *rock[3];
Bars *bars;
// static stuff
private:
// dark screen stuff
double darking_opacity;
bool dark_screen_on;
// this class stuff
int curr_pos_in_menu;
bool stop_rect_created;
int desktop_height;
int desktop_width;
int current_height;
int current_width;
int starting_width;
int starting_height;
public slots:
void setLanguageToSlovenian();
void setLanguageToEnglish();
void startStory();
void start();
// dark screen stuff
void screenGoesDark();
void screenComesFromDark();
};
#endif // GAME_H
To copy to clipboard, switch view to plain text mode
Bookmarks