Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Kyoukan97

Pages: [1]
1
SFML projects / Isometric tile map
« on: June 22, 2018, 04:21:43 pm »
Hi :)
I am working on a small project for which I need an isometric map, that's being procedurally generated.
For the procedural generation I am using a simplex noise class, provided on this repository ( not mine )
https://github.com/SRombauts/SimplexNoise

Here is the code (no GitHub, I know x) )
https://www.onlinegdb.com/rkeg7K5WQ

Known bugs/things to point out:
- Scrolling direction doesn't adjust to map orientation
- Adding the map orientation onto the look-up index into the height map, has no effect yet, because all the vertices of a tile have the same height( for now )

And here is what it looks like so far :)
https://imgur.com/gQLId42

Simply copy&paste the code + the SimplexNoise.h and SimplexNoise.cpp files
You can scroll the map with WASD and rotate it with R

Feel free to use this code in your projects or simply to mess around

2
SFML wiki / Object Properties
« on: August 23, 2015, 10:49:58 pm »
Hi,
i was looking through the SFML-Wiki and I found this article about object property management :
https://github.com/SFML/SFML/wiki/Tutorial%3A-Object-Properties

Can someone explain, how he is able to call "getValue()" & "setValue()" in the member functions get/set of the PropertyManager ? The member variable mList stores an object of type IProperty* , and those functions are no members of that class? I don't get how he does that ^^

P.s My english isnt the best, dont judge  :D

3
SFML projects / TETRIS Clone
« on: July 31, 2015, 05:03:35 pm »
Hi ^.^
I am new to this forum and i currently working on my first game , Tetris *yay*

I just wanted to share my Tetromino class and get some opinions on how i can improve it :) ( i tried messing around with C++11 a bit )
This is the header file :
#ifndef TETROMINO_HPP
#define TETROMINO_HPP

#include <array>

#include <SFML\Graphics.hpp>

enum typeTetrominoID { IBrick, JBrick, LBrick, OBrick, SBrick, TBrick, ZBrick };

struct TetrominoCodes
{
        using TetrominoCode = std::array < std::array<sf::Uint32, 4>, 2 >;

        TetrominoCode I;
        TetrominoCode J;
        TetrominoCode L;
        TetrominoCode O;
        TetrominoCode S;
        TetrominoCode T;
        TetrominoCode Z;

        TetrominoCodes()
                : I(TetrominoCode{ { { 1, 1, 1, 1 }, { 0, 0, 0, 0 } } }),
                  J(TetrominoCode{ { { 1, 0, 0, 0 }, { 1, 1, 1, 0 } } }),
                  L(TetrominoCode{ { { 0, 0, 1, 0 }, { 1, 1, 1, 0 } } }),
                  O(TetrominoCode{ { { 1, 1, 0, 0 }, { 1, 1, 0, 0 } } }),
                  S(TetrominoCode{ { { 0, 1, 1, 0 }, { 1, 1, 0, 0 } } }),
                  T(TetrominoCode{ { { 0, 1, 0, 0 }, { 1, 1, 1, 0 } } }),
                  Z(TetrominoCode{ { { 1, 1, 0, 0 }, { 0, 1, 1, 0 } } })
        {};
};

struct TetrominoColors
{
        using TetrominoColor = sf::Color;

        TetrominoColor I = TetrominoColor(152, 245, 255);
        TetrominoColor J = TetrominoColor(0, 0, 255);
        TetrominoColor L = TetrominoColor(255, 165, 79);
        TetrominoColor O = TetrominoColor(255, 255, 0);
        TetrominoColor S = TetrominoColor(0, 255, 0);
        TetrominoColor T = TetrominoColor(160, 32, 240);
        TetrominoColor Z = TetrominoColor(255, 0, 0);
};

class Tetromino : public sf::Drawable, public sf::Transformable
{
private:
        typeTetrominoID   m_typeID;

        sf::Texture     m_texture;
        sf::Vector2u    m_brickSize;
        sf::VertexArray m_vertices;

        void create(TetrominoCodes::TetrominoCode code, TetrominoColors::TetrominoColor color);

        virtual void draw(sf::RenderTarget& renderTarget, sf::RenderStates renderStates) const;

public:
        Tetromino();
        Tetromino(typeTetrominoID typeID);

        void updateFixed(void);
        void updateVariable(sf::Time dt);
};

#endif // TETROMINO_HPP
 

And this is the .cpp file :
#include <iostream>

#include <SFML\Graphics.hpp>

#include "Tetromino.hpp"

Tetromino::Tetromino()
{}

Tetromino::Tetromino(typeTetrominoID typeID)
        : m_typeID(typeID), m_brickSize(sf::Vector2u(16, 16))
{
        TetrominoCodes  tetrominoCodes;
        TetrominoColors tetrominoColors;

        std::cout << "m_typeID: " << m_typeID << std::endl;

        switch (m_typeID)
        {
        case IBrick:
                create(tetrominoCodes.I, tetrominoColors.I); break;
        case JBrick:
                create(tetrominoCodes.J, tetrominoColors.J); break;
        case LBrick:
                create(tetrominoCodes.L, tetrominoColors.L); break;
        case OBrick:
                create(tetrominoCodes.O, tetrominoColors.O); break;
        case SBrick:
                create(tetrominoCodes.S, tetrominoColors.S); break;
        case TBrick:
                create(tetrominoCodes.T, tetrominoColors.T); break;
        case ZBrick:
                create(tetrominoCodes.Z, tetrominoColors.Z); break;
        }
}

void Tetromino::updateFixed(void)
{
        sf::Vector2f pos = this->getPosition();
        pos.y += m_brickSize.y;

        this->setPosition(pos);
}

void Tetromino::updateVariable(sf::Time dt)
{}

void Tetromino::create(TetrominoCodes::TetrominoCode code, TetrominoColors::TetrominoColor color)
{
        m_vertices.setPrimitiveType(sf::Quads);
        m_vertices.resize(16);

        std::array<std::array<sf::Vertex, 4>, 4> quads;

        sf::Uint16 vertexCounter = 0;

        for (sf::Uint16 i = 0; i < 2; i++)
        {
                for (sf::Uint16 j = 0; j < 4; j++)
                {
                        std::cout << "code[" << i << "][" << j << "]: " << code[i][j] << std::endl;

                        if (code[i][j] == 1)
                        {
                                quads[vertexCounter][0].color = color;
                                quads[vertexCounter][1].color = color;
                                quads[vertexCounter][2].color = color;
                                quads[vertexCounter][3].color = color;

                                quads[vertexCounter][0].position = sf::Vector2f(i * m_brickSize.x, j* m_brickSize.y);
                                quads[vertexCounter][1].position = sf::Vector2f((i + 1) * m_brickSize.x, j * m_brickSize.y);
                                quads[vertexCounter][2].position = sf::Vector2f((i + 1) * m_brickSize.x, (j + 1) * m_brickSize.y);
                                quads[vertexCounter][3].position = sf::Vector2f(i * m_brickSize.x, (j + 1) * m_brickSize.y);

                                for (auto i : quads[vertexCounter])
                                {
                                        m_vertices.append(i);

                                        std::cout << "position: " << i.position.x << ", " << i.position.y << std::endl;
                                }
                                vertexCounter++;
                        }
                }
        }
}

void Tetromino::draw(sf::RenderTarget& renderTarget, sf::RenderStates renderStates) const
{
        renderStates.transform *= getTransform();
        renderStates.texture = &m_texture;

        renderTarget.draw(m_vertices, renderStates);
}
 

P.s my english isn't always on point ... so yea  :D

Pages: [1]
anything