示例#1
0
void Initialize()
{
    g_pBackground = GfxImageLoad("gfx/bg3.tga");
    g_pTextureTest = GfxTextureCreate(g_pBackground);
    g_pSpritesBg = GfxSpriteCreate(g_pTextureTest);
    g_pTexture = GfxTextureLoad("gfx/tileset.tga"); // On crée g_pTexture ici et on l'envoie dans l'appel de fonction

    g_pSpriteHero = CreateTile(g_pTexture, 7, 7, 7, 5); // Initialisée en dehors du scope pour l'utiliser autre part ( Donc on n'écrit pas "TGfxSPrite *" devant ) ( debug mode = 2, 1 | normal mode = 0, 0 )

    TGfxImage * pMapImage = GfxImageLoad("gfx/map.tga"); // Pas en const car on peut vouloir la delete ( Si on le laisse comme ça, il sera inutile et prendra de la mémoire inutile ! il faut le delete après la boucle avec le destroy
    int iImgSizeX = GfxImageGetSizeX(pMapImage);
    int iImgSizeY = GfxImageGetSizeY(pMapImage);

    for (int y = 0; y < iImgSizeY; ++y)
    {
        for (int x = 0; x < iImgSizeX; ++x)
        {

            const int iIndex = x + y * iImgSizeX;
            if (GfxImageGetData(pMapImage)[iIndex] == GfxColor(255, 255, 255, 255)) // SI je veux aller voir le premier élément je dois mettre [0]
            {
                g_pSpriteWall[g_iWallCount] = CreateTile(g_pTexture, 6, 1, x, y); // 6 et 1 au lieu de 1 et 1 pour mur ( 1, 1 = debug mode test )
                g_iWallCount++;
            }
            if (GfxImageGetData(pMapImage)[iIndex] == GfxColor(255, 0, 0, 255)) // SI je veux aller voir le premier élément je dois mettre [0]
            {
                g_pSpriteDeathWall[g_iDeathWallCount] = CreateTile(g_pTexture, 7, 1, x, y);
                g_iDeathWallCount++;
            }
        }
    }

    GfxImageDestroy(pMapImage);

    //	for (int i = 0; i < WALL_HEIGHT; i++)  !!!!!! Attention que ça doit bien s'adapter à la taille du tableau !!!!!!
    //	{
    //		g_pSpriteWall[i] = CreateTile(g_pTexture, 12, 3, 0, i);
    //	}
    // TGfxImage            Les 3 permettent d'afficher des choses.
    // TGfxTexture			Une image est un ensemble de pixel d'un certaine taille.
    // TGfxSprite			32 bits par pixel.
    // Un sprite n'est pas autonome, ça fait référence à une texture existente, il contiendra les info qui lui diront avec quelle rotation, quelle SCALE, et quelle partie de la texture utiliser ! Le sprite c'est la transformation. une partie de la texture

}
示例#2
0
void Initialize()
{
	g_pTexture = GfxTextureLoad("gfx/tileset.tga"); // On crée g_pTexture ici et on l'envoie dans l'appel de fonction

	g_pSpriteHero = CreateTile(g_pTexture, 1, 4, 1, 1); // Initialisée en dehors du scope pour l'utiliser autre part ( Donc on n'écrit pas "TGfxSPrite *" devant )
	g_pSpriteEnemy = CreateTile(g_pTexture, 8, 7, 2, 2);

	TGfxImage * pMapImage = GfxImageLoad("gfx/map.tga"); // Pas en const car on peut vouloir la delete ( Si on le laisse comme ça, il sera inutile et prendra de la mémoire inutile ! il faut le delete après la boucle avec le destroy
	int iImgSizeX = GfxImageGetSizeX(pMapImage);
	int iImgSizeY = GfxImageGetSizeY(pMapImage);

	for (int y = 0; y < iImgSizeY; ++y)
	{
		for (int x = 0; x < iImgSizeX; ++x)
		{   
			 
			const int iIndex = x + y * iImgSizeX; // Le *15 permet de compter les lignes déja parcourue ...
			if (GfxImageGetData(pMapImage)[iIndex] == GfxColor(255,255,255,255)) // SI je veux aller voir le premier élément je dois mettre [0]
			{
				g_pSpriteWall[g_iWallCount] = CreateTile(g_pTexture, 6, 1, x, y);
				g_iWallCount++;
			}
		}
	}

	GfxImageDestroy(pMapImage);

	//	for (int i = 0; i < WALL_HEIGHT; i++)  !!!!!! Attention que ça doit bien s'adapter à la taille du tableau !!!!!!
	//	{
	//		g_pSpriteWall[i] = CreateTile(g_pTexture, 12, 3, 0, i);
	//	}

	GfxSpriteSetPosition(g_pSpriteEnemy, -16 * SCALE, 0 * SCALE); // *4 car on a agrandi la texture X4, c'est pour avoir la même échelle

	// TGfxImage            Les 3 permettent d'afficher des choses.
	// TGfxTexture			Une image est un ensemble de pixel d'un certaine taille.
	// TGfxSprite			32 bits par pixel.
	// Un sprite n'est pas autonome, ça fait référence à une texture existente, il contiendra les info qui lui diront avec quelle rotation, quelle SCALE, et quelle partie de la texture utiliser ! Le sprite c'est la transformation. une partie de la texture

}
示例#3
0
void Update()
{
	const int mPosX = int(GfxGetCurrentMouseX() / (SCALE * TILE_SIZE));
	const int mPosY = int(GfxGetCurrentMouseY() / (SCALE * TILE_SIZE));

	iPosX = int(GfxSpriteGetPositionX(g_pSpriteHero) / (SCALE * 16));  // Le deuxieme int sert à forcer un int ! ça retire les virgules probable
	iPosY = int(GfxSpriteGetPositionY(g_pSpriteHero) / (SCALE * 16));
	int iPosX2 = int(GfxSpriteGetPositionX(g_pSpriteEnemy) / (SCALE * 16));
	int iPosY2 = int(GfxSpriteGetPositionY(g_pSpriteEnemy) / (SCALE * 16));

	const int iTileCountX = GfxGetDisplaySizeX() / (SCALE * 16) - 1;  // valeur de type INT pour ne pas garder ce qui est après la virgule
	const int iTileCountY = GfxGetDisplaySizeY() / (SCALE * 16) - 1;


	// Clic perso ( pose cookie )

	if (GfxInputIsJustPressed(EGfxInputID_MouseLeft) && iPosX == mPosX && iPosY == mPosY && g_cptCookie < MAX_COOKIE)
	{
		g_pCookie[g_cptCookie] = CreateTile(g_pTexture, 13, 3, iPosX, iPosY);
		g_cptCookie++;
	}

	// MOUSE MOVE ( with collision )

	if (GfxInputIsJustPressed(EGfxInputID_MouseLeft) && iPosX < iTileCountX && iPosX < mPosX)
	{
		iPosX++;
		for (int i = 0; i < g_iWallCount; i++)
		{
			if (iPosX *(SCALE * 16) == GfxSpriteGetPositionX(g_pSpriteWall[i]) && iPosY*(SCALE * 16) == GfxSpriteGetPositionY(g_pSpriteWall[i]))
			{
				iPosX--;
			}
		}
	}

	if (GfxInputIsJustPressed(EGfxInputID_MouseLeft) && iPosX > 0 && iPosX > mPosX)
	{
		iPosX--;
		for (int i = 0; i < g_iWallCount; i++)
		{
			if (iPosX *(SCALE * 16) == GfxSpriteGetPositionX(g_pSpriteWall[i]) && iPosY*(SCALE * 16) == GfxSpriteGetPositionY(g_pSpriteWall[i]))
			{
				iPosX++;
			}
		}
	}

	if (GfxInputIsJustPressed(EGfxInputID_MouseLeft) && iPosY < iTileCountY && iPosY < mPosY)
	{
		iPosY++;
		for (int i = 0; i < g_iWallCount; i++)
		{
			if (iPosX *(SCALE * 16) == GfxSpriteGetPositionX(g_pSpriteWall[i]) && iPosY*(SCALE * 16) == GfxSpriteGetPositionY(g_pSpriteWall[i]))
			{
				iPosY--;
			}
		}
	}

	if (GfxInputIsJustPressed(EGfxInputID_MouseLeft) && iPosY > 0 && iPosY > mPosY)
	{
		iPosY--;
		for (int i = 0; i < g_iWallCount; i++)
		{
			if (iPosX *(SCALE * 16) == GfxSpriteGetPositionX(g_pSpriteWall[i]) && iPosY*(SCALE * 16) == GfxSpriteGetPositionY(g_pSpriteWall[i]))
			{
				iPosY++;
			}
		}
	}

	// KEYBOARD MOVE ( With collision )

		if (GfxInputIsJustPressed(EGfxInputID_KeyArrowRight) && iPosX < iTileCountX)
		{
			iPosX++;
			for (int i = 0; i < g_iWallCount; i++)
			{
				if (iPosX *(SCALE * 16) == GfxSpriteGetPositionX(g_pSpriteWall[i]) && iPosY*(SCALE * 16) == GfxSpriteGetPositionY(g_pSpriteWall[i]))
				{
					iPosX--;
				}
			}
		}

		if (GfxInputIsJustPressed(EGfxInputID_KeyArrowLeft) && iPosX > 0)
		{
			iPosX--;
			for (int i = 0; i < g_iWallCount; i++)
			{
				if (iPosX *(SCALE * 16) == GfxSpriteGetPositionX(g_pSpriteWall[i]) && iPosY*(SCALE * 16) == GfxSpriteGetPositionY(g_pSpriteWall[i]))
				{
					iPosX++;
				}
			}
		}
		
		if (GfxInputIsJustPressed(EGfxInputID_KeyArrowDown) && iPosY < iTileCountY)
		{
			iPosY++;
			for (int i = 0; i < g_iWallCount; i++)
			{
				if (iPosX *(SCALE * 16) == GfxSpriteGetPositionX(g_pSpriteWall[i]) && iPosY*(SCALE * 16) == GfxSpriteGetPositionY(g_pSpriteWall[i]))
				{
					iPosY--;
				}
			}
		}
		
		if (GfxInputIsJustPressed(EGfxInputID_KeyArrowUp) && iPosY > 0)
		{
			iPosY--;
			for (int i = 0; i < g_iWallCount; i++)
			{
				if (iPosX *(SCALE * 16) == GfxSpriteGetPositionX(g_pSpriteWall[i]) && iPosY*(SCALE * 16) == GfxSpriteGetPositionY(g_pSpriteWall[i]))
				{
					iPosY++;
				}
			}
		}
		

	GfxSpriteSetPosition(g_pSpriteHero, float(iPosX * SCALE * 16), float(iPosY * SCALE * 16));

	// DEPLACEMENT JOUEUR 2 CACHÉ HORS DE L'ECRAN POUR LES VERSION ANDROID ( caché à gauche )

	if (GfxInputIsJustPressed(EGfxInputID_KeyCharD) && iPosX2 < iTileCountX)
	{
		iPosX2++;
	}
	if (GfxInputIsJustPressed(EGfxInputID_KeyCharQ) && iPosX2 > 0)
	{
		iPosX2--;
	}
	if (GfxInputIsJustPressed(EGfxInputID_KeyCharS) && iPosY2 < iTileCountY)
	{
		iPosY2++;
	}
	if (GfxInputIsJustPressed(EGfxInputID_KeyCharZ) && iPosY2 > 0)
	{
		iPosY2--;
	}

	GfxSpriteSetPosition(g_pSpriteEnemy, float(iPosX2 * SCALE * 16), float(iPosY2 * SCALE * 16));


}
示例#4
0
EntityWindow::EntityWindow(EditorWidget *editor, EntityType type, EntityWindowType windowType)
{
    if(!editor->levelOpen)
    {
        close();
        QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection);
        return;
    }

    this->editor = editor;

    QGridLayout* gLayout = new QGridLayout(this);
    QLabel* nameLabel = new QLabel(QString("Name:"));
    QLabel* tileLabel = new QLabel(QString("Tile:"));
    QLabel* paramLabel = new QLabel(QString("Function:"));
    QLabel* tilesetLabel = new QLabel(QString("Tileset Name:"));
    QLabel* xLabel = new QLabel(QString("Texture Region X:"));
    QLabel* yLabel = new QLabel(QString("Texture Region Y:"));
    QLabel* twLabel = new QLabel(QString("Texture Region Width:"));
    QLabel* thLabel = new QLabel(QString("Texture Region Height:"));
    QLabel* wLabel = new QLabel(QString("Width:"));
    QLabel* hLabel = new QLabel(QString("Height:"));
    QLabel* oxLabel = new QLabel(QString("Origin X:"));
    QLabel* oyLabel = new QLabel(QString("Origin Y:"));
    nameBox = new QLineEdit();
    tilesetBox = new QComboBox();

    int textureNameCount = editor->data.configuration.textureNames.size();
    for(int i = 0; i < textureNameCount; i++)
    {
        tilesetBox->addItem(QString(editor->data.configuration.textureNames[i].c_str()));
    }
    valueBox = Tools::NewSpinBox(0);
    paramBox = Tools::NewSpinBox(0);
    tXBox = Tools::NewSpinBox(INT_MIN); tYBox = Tools::NewSpinBox(INT_MIN);
    tWBox = Tools::NewSpinBox(INT_MIN); tHBox = Tools::NewSpinBox(INT_MIN);
    wBox = Tools::NewSpinBox(INT_MIN); hBox = Tools::NewSpinBox(INT_MIN);
    oxBox = Tools::NewSpinBox(INT_MIN); oyBox = Tools::NewSpinBox(INT_MIN);
    QPushButton* okButton = new QPushButton(QString("OK"));
    QPushButton* cancelButton = new QPushButton(QString("Cancel"));

    gLayout->addWidget(nameLabel,0,0);
    gLayout->addWidget(nameBox,0,1);

    connect(cancelButton,SIGNAL(clicked()),this,SLOT(FullClose()));

    int row = editor->window->manager->entityList->selectionModel()->currentIndex().row();
    int bottomLayoutRow = 3;

    switch(type)
    {
    case Tiles:
        tilePreview = new TilePreviewWidget(editor);

        gLayout->addWidget(tileLabel,1,0);
        gLayout->addWidget(valueBox,1,1);
        gLayout->addWidget(paramLabel,2,0);
        gLayout->addWidget(paramBox,2,1);
        gLayout->addWidget(tilePreview,3,0);
        bottomLayoutRow = 4;

        connect(valueBox, SIGNAL(valueChanged(int)), tilePreview, SLOT(SetTileIndex(int)));
        break;

    case Props:
        gLayout->addWidget(tilesetLabel,0,2);
        gLayout->addWidget(tilesetBox,0,3);
        gLayout->addWidget(xLabel,1,0);
        gLayout->addWidget(tXBox,1,1);
        gLayout->addWidget(yLabel,1,2);
        gLayout->addWidget(tYBox,1,3);
        gLayout->addWidget(twLabel,2,0);
        gLayout->addWidget(tWBox,2,1);
        gLayout->addWidget(thLabel,2,2);
        gLayout->addWidget(tHBox,2,3);
        gLayout->addWidget(wLabel,3,0);
        gLayout->addWidget(wBox,3,1);
        gLayout->addWidget(hLabel,3,2);
        gLayout->addWidget(hBox,3,3);
        gLayout->addWidget(oxLabel,4,0);
        gLayout->addWidget(oxBox,4,1);
        gLayout->addWidget(oyLabel,4,2);
        gLayout->addWidget(oyBox,4,3);
        bottomLayoutRow = 5;
        break;

    case Sprites:
        bottomLayoutRow = 1;
        break;
    }

    switch(windowType)
    {
    case New:
        switch(type)
        {
        case Tiles: connect(okButton,SIGNAL(clicked()),this,SLOT(CreateTile())); break;
        case Props: connect(okButton,SIGNAL(clicked()),this,SLOT(CreateProp())); break;
        case Sprites: connect(okButton,SIGNAL(clicked()),this,SLOT(CreateSprite())); break;
        case Textures: connect(okButton,SIGNAL(clicked()),this,SLOT(CreateTexture())); break;
        case Polygons: connect(okButton,SIGNAL(clicked()),this,SLOT(CreatePolygon())); break;
        }
        break;
    case Edit:
        switch(type)
        {
        case Tiles:
            SetEditTileValues(row);
            connect(okButton,SIGNAL(clicked()),this,SLOT(EditTile()));
            break;
        case Props:
            SetEditPropValues(row);
            connect(okButton,SIGNAL(clicked()),this,SLOT(EditProp()));
            break;
        case Sprites:
            nameBox->setText(QString(editor->data.configuration.spriteDefinitions[row].name.c_str()));
            connect(okButton,SIGNAL(clicked()),this,SLOT(EditSprite()));
            break;
        case Textures:
            nameBox->setText(QString(editor->data.configuration.textureNames[row].c_str()));
            connect(okButton,SIGNAL(clicked()),this,SLOT(EditTexture()));
            break;
        case Polygons:
            nameBox->setText(QString(editor->data.configuration.polygonDefinitions[row].name.c_str()));
            connect(okButton,SIGNAL(clicked()),this,SLOT(EditPolygon()));
            break;
        }
        break;
    }

    gLayout->addWidget(okButton,bottomLayoutRow,0);
    gLayout->addWidget(cancelButton,bottomLayoutRow,1);

}