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 - Kyubey

Pages: [1]
1
General / Question about lighting in 2D game.
« on: May 18, 2014, 07:45:54 pm »
Hello there.
I've been talking with my friend about making a 2D game in SFML 2.1 and we wanted to make (kinda) realistic lighting. Let me use as example this trailer for Crawl https://www.youtube.com/watch?v=2_3xrqjTyes. We really liked the view perspective this game shows, but the thing that really bugged us were lights that... didn't light up the room and didn't reflect on the walls. So here's our question - is it possible to make a decent lighting in SFML for 2D game without resorting to "3D" graphics and/or some sketchy code? (The whole idea is pretty much in infancy, so we're sorry for not being more specific -  we were just wondering if there is an easy way to do it)

2
Graphics / Creating player class.
« on: October 21, 2013, 04:37:59 pm »
Hello there. I'm currently trying to implement player class to my game (here's the link to my topic with code if you're curious: http://en.sfml-dev.org/forums/index.php?topic=13253.0). However, I'm kind of stuck at how should I do it. Should I just redraw character sprite with each loop, with position depending on input? Is there some kind of method my brain cannot fathom? I'd appriciate any form of help on the matter.

(also, if there's a topic on this subject, then I'm sorry I made another one - search function gave me nothing)

3
SFML projects / 2d game engine done by a newbie - progress diary
« on: October 15, 2013, 12:17:37 am »
Hey there. I'm slowly but surely making my first 2d game engine in SFML 2.1. I figured that sice I'm making it, I might as well share my code, and get some feedback to make it better :)

15.10.2013
http://speedy.sh/V88ww/IncuEngine-15.10.rar
20.10.2013
http://s000.tinyupload.com/index.php?file_id=00971552907888389184
What's in so far:
- Main loop and all the basics
- image manager class
- tile class
- basic mapping
To be done next:
- basic camera movement

4
Graphics / Placing image on the screen - problem.
« on: October 09, 2013, 12:48:40 am »
Hello, I have a problem with getting my image on the screen. Since I only started learning SFML today, I probably just did some dumb mistake due to my lack of knowledge and understanding, but I can't figure out what it is and I'm getting sleepy... If you have some time, please take a look and point it out if you can find it. Thanks in advance!

#Edit: Since I didn't put the more detailed explanation of my problem, I'm doing it now: Ok so, I wanted to put my test image (the one from Engine::LoadImages() - it is in the right folder) on the screen. What I get is some strange assertion error (thus my assumption that I made a mistake in the code) and after I skip the error, I get a black screen (probably meaning, that it's doing the "window clear" stage) That's all I can tell with my tired mind - I hope it helps!

(If this subforum isn't for such requests, then I'm sorry and simply ignore this thread)

MAIN.cpp
#include <Windows.h>

#include "Engine.h"

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
        Engine* engine = new Engine();

        try
        {
                engine->Go();
        }
        catch(char* e)
        {
                MessageBoxA(NULL, e, "Exception Occured", MB_OK | MB_ICONERROR);
        }
}
 

Engine.h
#ifndef _ENGINE_H
#define _ENGINE_H

#include <SFML\Graphics.hpp>
#include "ImageManager.h"
#include "Tile.h"


class Engine
{
private:
        //Image'n'tile stuff
        ImageManager imageManager;

    void LoadImages();

    Tile* testTile;

        //Render that window
        sf::RenderWindow *window;

        //Starto!
        bool Init();

        //Main Game loop
        void MainLoop();
        //Render one frame
        void RenderFrame();
        //Processes user input
        void ProcessInput();
        //Update engine intervals
        void Update();

public:
        Engine();
        ~Engine();

        //start that engine
        void Go();


};

#endif

Engine.cpp
#include "Engine.h"
#include <SFML\Graphics.hpp>



Engine::Engine()
{

}


Engine::~Engine()
{

}

//image stuff
void Engine::LoadImages()
{
        sf::Image image;
        image.loadFromFile("test.png");

        imageManager.AddImage(image);

        testTile = new Tile(imageManager.GetImage(0));
}

void Engine::RenderFrame()
{
        window->clear();
        testTile->Draw(0,0, window);
        window->display();
}




//startup stuff \/
bool Engine::Init()
{
        window = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "IncuEngine");

        if(!window)
                return false;
        LoadImages();

        return true;
}

//basic user input process
void Engine::ProcessInput()
{
        sf::Event event;
    while (window->pollEvent(event))
    {
        // Request for closing the window
        if (event.type == sf::Event::Closed)
            window->close();
    }
}

void Engine::Update()
{

}

void Engine::MainLoop()
{
        while(window->isOpen())
        {
                ProcessInput();
                Update();
                RenderFrame();
        }
}

void Engine::Go()
{
        if(!Init())
                throw "Engine initialization failed.";

        MainLoop();
}

 

Tile.h
#ifndef _TILE_H
#define _TILE_H

#include <SFML\Graphics.hpp>


class Tile
{
private:
        sf::Texture baseTexture;
        sf::Sprite baseSprite;

public:
        Tile(sf::Image& image);
        ~Tile(void);

        void Draw(int x, int y, sf::RenderWindow* rw);
};

#endif

Tile.cpp
#include "Tile.h"


Tile::Tile(sf::Image& image)
{
        baseTexture.create(200,200);
        baseTexture.update(image);
}


Tile::~Tile(void)
{
}

void Tile::Draw(int x, int y, sf::RenderWindow* rw)
{
        baseSprite.setTexture(baseTexture);
        baseSprite.setPosition(x, y);
        rw->draw(baseSprite);
}


 

ImageManager.h
#ifndef _IMAGEMANAGER_H
#define _IMAGEMANAGER_H

#include <vector>
#include <SFML\Graphics.hpp>

class ImageManager
{
private:
        std::vector <sf::Image> imageList;
public:
        ImageManager(void);
        ~ImageManager(void);

        void AddImage(sf::Image& image);
        sf::Image& GetImage(int index);
};

#endif
 

Image.cpp
#include "ImageManager.h"


ImageManager::ImageManager(void)
{
}


ImageManager::~ImageManager(void)
{
}

void ImageManager::AddImage(sf::Image& image)
{
        imageList.push_back(image);
}

sf::Image& ImageManager::GetImage(int index)
{
        return imageList[index];
}
 

Pages: [1]