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

Pages: [1]
1
SFML projects / Sideview tactical rpg - first mockup
« on: May 29, 2017, 01:55:09 pm »
So, I'm currently working on procedural generated areas and some simple artificial neural network mixed with state machine for ia.
After a lot of iterations it hit me how usable this thing was for a game. So I started making some mockup art while away from my programming computer.

This is not much, but more will come :)

One challenge ahead of me will be rendering the outline of partially hidden objects and units... Anyone have a suggestion on that?

Best regards :)


2
SFML game jam / Making a Jam on Itch io with prizes
« on: May 14, 2017, 03:16:04 pm »
So, seeing as my post in the other thread got no response, I decided I wanted to make a dedicated thread for it.

Here is what I'd like to do (And will do if there is support for it)

-Hold a 1-2 week game Jam. SFML will be a requirement
-1 man team development
-Theme, Vote on a list of 10+ themes, top 3 will be open to use, individually or mixed. creators choice.
-Graphics and sound assets: any free/legal will be allowed. (I think, still not 100% on this one)
-Code assets: Basic framework can be done beforehand (window, game loop ect.) but game mechanics must be made after start.
-SFML tribute must be included in game, regardless of theme.
-Prize: the winner will be able to choose one of the following books (print edition):
SFML Game Development
SFML Essentials
SFML Blueprints
SFML Game Development By Example
Mastering SFML Game Development
Any new SFML Books that comes out before i start the contest
The prize can be given away as a donation if the winner already have the books.

How Ill do it:
-I'll use some time from now to hammer out the details.
-Then ill give 1 month for theme suggestions (I will sort trough these so all are pg 15 or some such) (posting on Itch now, and all other places i can think of)
-1 Week for theme voting
-Announcement of theme, 1-2 weeks for development
-Games come in. 1 week for reviews (no voting yet, but commenting welcome
-1-2 weeks for voting
-announcement of winner



How does this sound?

Q/A:
1) Is this prize paid for already?
- Yes'ish. the money are set aside, but not knowing the selected prize, it cannot be paid.

2) Will there be more prizes?
- Only if others decide to tip in

3) Will this be the only time i sponsor such a contest?
- That will depend on the interest, but i hope to make one contest each 3-4th month

4) Can anyone partissipate?
- Yes, but you will have to live a place where PacktPub or Amazon will send stuff to you to receive the prize

5) Will there be beginner/intimate categories?
- Sadly no, not unless more people sponsores prices so we can devide stuff up.

6) Do you need any help holding this Jam?
- I can handle the stuff myself, but anyone involved with Jams, SFML or sponsoring who wish to help are welcome. but if you are part of the Jam setup you will not be allowed into the Jam. I also claim the right to refuse help for whatever reason I fond needed. (This is mainly to avoid cheating or over-staffing)

3
General / VS 2017 Template errors
« on: May 13, 2017, 01:24:44 am »
So..
I recently updated to VS 2017. and after some problems managed to get my setup to work with sfml 2.4.2
BUT....
I tried to export my project as a template. seemed to work fine.
making a new project also seemed to work fine... right up until i tries to open any file.. they are not there....
They are in the solution explore, but not in the actual folders, trying to open them gives the message:
"The document cannot be opened. It has been renamed, deleted or moved"
Going to the project folder i find this to be true... it is empty...
So, i have to manually copy each cpp, h and dll file into the right folders...

anyone encountered this issue before?
and if... did you solve it and how? my google-fu does not bring much light to the issue

4
SFML projects / A SFML Prototypes collection
« on: May 09, 2017, 12:54:42 am »
Okay, so i guess the title says it a bit.

I felt like making a SFML game prototype, a fully functional game incorporating both keyboard, mouse, rotation, lists, iteration, hittests, vectors all that, in as small a code as i could without any needless optimization.. a game that anyone who wants, can take apart and put together as they want...

But even more, i would Love if we could make a collection of such short, fully functional games. some like this in just one file.
some using functions.
some using multiple files and headers
but all small, gritty fully functional for others to pick apart.
maybe make tutorials on them...
This is not about CORRECT code... this is about WORKING code.... the key stone to prototyping....

Why? Because that was how i learned to program back in the day... i took working games (Pacal, VB and later Flash AS2 games btw) and made changes until they did something differently so i could figure out what it was...

So... here is around an hours work.
First the full code without comments and without extra line space.

Main.cpp
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <list>
void main(int argc, char** argv[]) {
        sf::RectangleShape m_tankBody;
        m_tankBody.setFillColor(sf::Color(120, 150, 120));
        m_tankBody.setSize(sf::Vector2f(30, 20));
        m_tankBody.setOrigin(12, 10);
        m_tankBody.setPosition(400, 300);
        sf::RectangleShape m_tankGun;
        m_tankGun.setFillColor(sf::Color(30, 50, 30));
        m_tankGun.setSize(sf::Vector2f(25, 4));
        m_tankGun.setOrigin(2, 2);
        m_tankGun.setPosition(400, 300);
        float m_tankSpeed = 3;
        std::list<sf::Vector3f> m_bullets;
        sf::CircleShape m_bullet;
        m_bullet.setFillColor(sf::Color(130, 50, 30));
        m_bullet.setRadius(2);
        m_bullet.setOrigin(1, 1);
        float m_bulletSpeed = 15;
        sf::Clock m_fireTime;
        m_fireTime.restart();
        float m_fireRate = 0.5;
        sf::CircleShape m_target;
        m_target.setFillColor(sf::Color(200, 30, 30, 150));
        m_target.setRadius(15);
        m_target.setOrigin(15, 15);
        m_target.setPosition(600, 300);
        sf::Clock m_gameTime, m_frameTime;
        m_gameTime.restart();
        m_frameTime.restart();
        int m_UPS = 60, m_FPS = 30;
        static const float PI = 3.14159265359;
        sf::RenderWindow m_window(sf::VideoMode(800, 600), "SFML simple tank");
        while (m_window.isOpen()) {
                sf::Event event;
                while (m_window.pollEvent(event)) {
                        if (event.type == sf::Event::Closed) {
                                m_window.close();
                        }
                }
                if (m_gameTime.getElapsedTime().asSeconds() > 1 / m_UPS) {
                        m_gameTime.restart();
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right)) {
                                m_tankBody.setRotation(m_tankBody.getRotation() + 0.1);
                        }
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left)) {
                                m_tankBody.setRotation(m_tankBody.getRotation() - 0.1);
                        }
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Up)) {
                                float _xPos = m_tankBody.getPosition().x + ((m_tankSpeed / m_UPS) * cos(m_tankBody.getRotation() / 180 * PI));
                                float _yPos = m_tankBody.getPosition().y + ((m_tankSpeed / m_UPS) * sin(m_tankBody.getRotation() / 180 * PI));
                                if (_xPos > m_window.getSize().x) _xPos = 0;
                                else if (_xPos < 0) _xPos = m_window.getSize().x;
                                if (_yPos > m_window.getSize().y) _yPos = 0;
                                else if (_yPos < 0) _yPos = m_window.getSize().y;
                                m_tankBody.setPosition(_xPos, _yPos);
                        }
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Down)) {
                                float _xPos = m_tankBody.getPosition().x - ((m_tankSpeed / m_UPS) * cos(m_tankBody.getRotation() / 180 * PI));
                                float _yPos = m_tankBody.getPosition().y - ((m_tankSpeed / m_UPS) * sin(m_tankBody.getRotation() / 180 * PI));
                                if (_xPos > m_window.getSize().x) _xPos = 0;
                                else if (_xPos < 0) _xPos = m_window.getSize().x;
                                if (_yPos > m_window.getSize().y) _yPos = 0;
                                else if (_yPos < 0) _yPos = m_window.getSize().y;
                                m_tankBody.setPosition(_xPos, _yPos);
                        }
                        if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && m_fireTime.getElapsedTime().asSeconds() > m_fireRate) {
                                m_fireTime.restart();
                                m_bullets.push_back(sf::Vector3f(m_tankBody.getPosition().x, m_tankBody.getPosition().y, m_tankGun.getRotation()));
                        }
                        std::list<sf::Vector3f>::iterator i = m_bullets.begin();
                        while (i != m_bullets.end())
                        {
                                bool isDead = false;

                                //we also need to know how far from the target the bullets are
                                int xDist = i->x - m_target.getPosition().x;
                                int yDist = i->y - m_target.getPosition().y;
                                float m_distance = sqrtf((xDist * xDist) + (yDist*yDist));
                                if (i->x > m_window.getSize().x || i->x < 0 || i->y > m_window.getSize().y || i->y < 0) isDead = true;
                                else if (m_distance < 15) {
                                        isDead = true;

                                        //But we also need to move the target if it is hit.
                                        float nY = rand() % (m_window.getSize().y - 100) + 50;
                                        float nX;
                                        //lets make sure it ends up on hte opposite side of the screen than the tank.
                                        if (m_tankBody.getPosition().x > (m_window.getSize().x / 2)) nX = rand() % (m_window.getSize().x / 3);
                                        else nX = rand() % (m_window.getSize().x / 3) + ((m_window.getSize().x / 3) * 2);
                                        m_target.setPosition(nX, nY);
                                }
                                if (isDead)     {
                                        m_bullets.erase(i++);
                                }
                                else
                                {
                                        i->x += ((m_bulletSpeed / m_UPS) * cos(i->z / 180 * PI));
                                        i->y += ((m_bulletSpeed / m_UPS) * sin(i->z / 180 * PI));
                                i++;
                                }
                        }
                        m_tankGun.setPosition(m_tankBody.getPosition());
                        m_tankGun.setRotation(atan2(sf::Mouse::getPosition(m_window).y - m_tankGun.getPosition().y, sf::Mouse::getPosition(m_window).x - m_tankGun.getPosition().x) * 180 / PI);
                }
                if (m_frameTime.getElapsedTime().asSeconds() > 1 / m_FPS) {
                        m_frameTime.restart();
                        //lets make a nice green field for us to drive the tank on.
                        m_window.clear(sf::Color(0, 110, 50));
                        for (sf::Vector3f it : m_bullets) {
                                m_bullet.setPosition(it.x, it.y);
                                m_window.draw(m_bullet);
                        }
                        m_window.draw(m_tankBody);
                        m_window.draw(m_tankGun);
                        m_window.draw(m_target);
                        m_window.display();
                }
        }
}
 

and of course, one with my comments. And somewhat better spacing....

Main.cpp
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <list>

void main(int argc, char** argv[]) {

        //Set up a figure to use as a tank
        sf::RectangleShape m_tankBody;
        m_tankBody.setFillColor(sf::Color(120, 150, 120));
        m_tankBody.setSize(sf::Vector2f(30, 20));
        m_tankBody.setOrigin(12, 10);
        m_tankBody.setPosition(400, 300);
       
        //Set up a box to use as the gun of the tank
        sf::RectangleShape m_tankGun;
        m_tankGun.setFillColor(sf::Color(30, 50, 30));
        m_tankGun.setSize(sf::Vector2f(25, 4));
        m_tankGun.setOrigin(2, 2);
        m_tankGun.setPosition(400, 300);

        //We need to know how fast the tank can drive
        float m_tankSpeed = 3;

        //make a list for bullets, it needs to be a 3 dimenisonel vector, tow dimensions will be used for x and y, and the last one will be used for rotation.
        //so the vectors x, and y will be x and y. its z will be rotation.
        std::list<sf::Vector3f> m_bullets;

        //Make a circle for bullets
        sf::CircleShape m_bullet;
        m_bullet.setFillColor(sf::Color(130, 50, 30));
        m_bullet.setRadius(2);
        m_bullet.setOrigin(1, 1);

        //We need to know how fast do bullets fly?
        float m_bulletSpeed = 15;

        //and a timer for fiering:
        sf::Clock m_fireTime;
        m_fireTime.restart();
        float m_fireRate = 0.5;

        //Make a circle for a target
        sf::CircleShape m_target;
        m_target.setFillColor(sf::Color(200, 30, 30, 150));
        m_target.setRadius(15);
        m_target.setOrigin(15, 15);
        m_target.setPosition(600, 300);

        //We also need a way to keep updates and frame rate stable (We could use delta time, but for now we go with the most simple solution)
        sf::Clock m_gameTime, m_frameTime;
        m_gameTime.restart();
        m_frameTime.restart();
        int m_UPS = 60,  m_FPS = 30;

        //PI is a great number, and we need it to calculate rotation and movement.
        static const float PI = 3.14159265359;

        //Set up a window to render our game in.
        sf::RenderWindow m_window(sf::VideoMode(800, 600), "SFML simple tank");

        //Update the game as long as the window is open
        while (m_window.isOpen()) {
                //This allows us to close the game window
                sf::Event event;
                while (m_window.pollEvent(event)) {
                        if (event.type == sf::Event::Closed) {
                                m_window.close();
                        }
                }

                //if enough time has passed, update the game, remember to restart the clock.
                if (m_gameTime.getElapsedTime().asSeconds() > 1 / m_UPS) {
                        m_gameTime.restart();

                        //Rotate the tank when left or right key is pressed
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right)) {
                                m_tankBody.setRotation(m_tankBody.getRotation() + 0.1);
                        }
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left)) {
                                m_tankBody.setRotation(m_tankBody.getRotation() - 0.1);
                        }

                        //move the tank forward based on rotation if UP is pressed
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Up)) {
                                float _xPos = m_tankBody.getPosition().x + ((m_tankSpeed / m_UPS) * cos(m_tankBody.getRotation() / 180 * PI));
                                float _yPos = m_tankBody.getPosition().y + ((m_tankSpeed / m_UPS) * sin(m_tankBody.getRotation() / 180 * PI));
                                if (_xPos > m_window.getSize().x) _xPos = 0;
                                else if (_xPos < 0) _xPos = m_window.getSize().x;
                                if (_yPos > m_window.getSize().y) _yPos = 0;
                                else if (_yPos < 0) _yPos = m_window.getSize().y;
                                m_tankBody.setPosition(_xPos, _yPos);
                        }

                        //move the tank back based on rotation if DOWN is pressed
                        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Down)) {
                                float _xPos = m_tankBody.getPosition().x - ((m_tankSpeed / m_UPS) * cos(m_tankBody.getRotation() / 180 * PI));
                                float _yPos = m_tankBody.getPosition().y - ((m_tankSpeed / m_UPS) * sin(m_tankBody.getRotation() / 180 * PI));
                                if (_xPos > m_window.getSize().x) _xPos = 0;
                                else if (_xPos < 0) _xPos = m_window.getSize().x;
                                if (_yPos > m_window.getSize().y) _yPos = 0;
                                else if (_yPos < 0) _yPos = m_window.getSize().y;
                                m_tankBody.setPosition(_xPos, _yPos);
                        }

                        //if the mouse button LEFT is pressed, and time enough has passed since last bullet was fired. add a bullet to the bullet list.
                        if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && m_fireTime.getElapsedTime().asSeconds() > m_fireRate) {
                                m_fireTime.restart();
                                m_bullets.push_back(sf::Vector3f(m_tankBody.getPosition().x, m_tankBody.getPosition().y, m_tankGun.getRotation()));
                        }
                       


                        //Move, hittest and erase each bullet as needed.
                        std::list<sf::Vector3f>::iterator i = m_bullets.begin();
                        while (i != m_bullets.end())
                        {
                                //we need a bolean to see if the bullets are dead.
                                bool isDead = false;

                                //we also need to know how far from the target the bullets are
                                int xDist = i->x - m_target.getPosition().x;
                                int yDist = i->y - m_target.getPosition().y;
                                float m_distance = sqrtf((xDist * xDist) + (yDist*yDist));

                                //if the bullets are to close at or over edge of the window, they are dead.
                                if (i->x > m_window.getSize().x || i->x < 0 || i->y > m_window.getSize().y || i->y < 0) isDead = true;

                                //or if the bullet is close enough to the target that they hit it.
                                else if (m_distance < 15) {
                                        isDead = true;

                                        //But we also need to move the target if it is hit.
                                        float nY = rand() % (m_window.getSize().y - 100) + 50;
                                        float nX;
                                        //lets make sure it ends up on hte opposite side of the screen than the tank.
                                        if (m_tankBody.getPosition().x > (m_window.getSize().x / 2)) nX = rand() % (m_window.getSize().x / 3);
                                        else nX = rand() % (m_window.getSize().x / 3) + ((m_window.getSize().x / 3) * 2);
                                        m_target.setPosition(nX, nY);
                                }

                                //So if hte bullet is dead, erase it.
                                if (isDead)     {
                                        m_bullets.erase(i++);
                                }

                                //or, if hte bullet is alive, move it based on its rotation and the bullet speed.
                                else
                                {
                                        i->x += ((m_bulletSpeed / m_UPS) * cos(i->z / 180 * PI));
                                        i->y += ((m_bulletSpeed / m_UPS) * sin(i->z / 180 * PI));
                                        i++;
                                }
                        }


                        //move the gun with the tank and Make the gun point towards the mouse!
                        m_tankGun.setPosition(m_tankBody.getPosition());
                        m_tankGun.setRotation(atan2(sf::Mouse::getPosition(m_window).y - m_tankGun.getPosition().y, sf::Mouse::getPosition(m_window).x - m_tankGun.getPosition().x) * 180 / PI);
                }


                //Draw the update if the target time has gone by since last frame, restart the frame clock.
                if (m_frameTime.getElapsedTime().asSeconds() > 1 / m_FPS) {
                        m_frameTime.restart();
                        //lets make a nice green field for us to drive the tank on.
                        m_window.clear(sf::Color(0, 110, 50));

                        //draw bullets:
                        for (sf::Vector3f it : m_bullets) {
                                m_bullet.setPosition(it.x, it.y);
                                m_window.draw(m_bullet);
                        }
                        m_window.draw(m_tankBody);
                        m_window.draw(m_tankGun);
                        m_window.draw(m_target);
                        m_window.display();
                }
        }
}

This code teaches a lot of the skills i feel is necessary to make a full game prototype.
or even a full game...

but it would be awesome if others could add small game codes like this... comment or ask questions. even if someone would make a tutorial on the individual things in this code...

oh yes, and an image of the game in attachment


5
General discussions / Books list and suggestions.
« on: May 06, 2017, 08:51:27 pm »
It's a long time no see.

So, I've just revised a bunch of books.
Some on programming in general, some on c++, and lastly some specific on SFML.

I'd like to hear if anyone has any suggestions as what to add to my collection (or want to hear a personal opinion on any of my books)
I like to program simulations and simple small 2d games.
(love boids, cellular automatons, neural networks and any thing that mimics natural systems...)

My library so far consists of:

-SFML game development by example
-SFML blue prints
-SFML essentials
-Mastering SFML game development (got it today)
-Procedural Content Generation for C++ Game Development
-Game programming patterns
-Beginning C++ Through Game Programming
-Programming Game AI By Example
-Artificial Intelligence for Humans, Volume 1: Fundamental Algorithms
-Artificial Intelligence for Humans, Volume 2: Nature-Inspired Algorithms
-Artificial Intelligence for Humans, Volume 3: Deep Learning and Neural Networks
(also got those 3 today)

Older books:
-Beginning Java Game Programming
-Developing Games in Java

So.. What do you guys think... Anything to add? What do you guys have?

6
Window / program slows down during fullscreen
« on: July 27, 2016, 06:20:52 pm »
So, I have this game that im currently working on
(link in spoiler:

the normal screen size for this game is 800 by 600.
it uses sf::view (400 by 300 pixels) and sf::window
it uses a flexible timestep
it runs fine using only 3-6& cpu and few %memory

but if i toggle fullscreen to true (or if i start in full screen) it slows down a lot.
but also, the animation gets slower still and thus out of sync.
(eg, walking becomes sliding)

toggeling fullscreen back off again solves the problem instantly...
I've tried running as administrator and searching with all my google'fu but no solution so far.

the toggleFullscreen code is:

void Window::ToggleFullScreen() {
        m_isFullscreen = !m_isFullscreen;
        Destroy();
        Create();
}

if it has any interest the animation code is called right after the units have updated their current location and status.

void Agent::animate() {
        _currentFrame+= (_speed / 160);
        if (_aniAtt) {
                if (_currentFrame > _attFrames) _currentFrame = 0;
                _animation = 3;
        }
        else if (_aniJump) {
                if (_yVel < 0) _currentFrame = 0;
                else _currentFrame = 1;
                _animation = 2;
        }
        else if (_aniWalk) {
                if (_currentFrame > _walkFrames) _currentFrame = 0;
                _animation = 1;
        }
        //standing
        else{
                if (_currentFrame > _standFrames) _currentFrame = 0;
                _animation = 0;
        }
        if (_dirLeft) _animation += 6;
}

_animation corresponds to a specific row and _current frame to the column in a texture.
a sprite is set to the corresponding coordinates and then rendered to the window.
_speed is the movement speed of the characters.

again, the cpu, memory and gpu usage remains roughly the same, and never exceeds 12% but both the program in general slows down and the animation, the animation just more than the rest.

any suggestions?

7
Hello SFML folks.

So, I've recently got a lot of extra time on my hands and my hands on some sfml books.
So, ive decided i wanted to give it a go at a game from scratch. my first major project on my own.

my background - an outdated webintegrator education from 2005, some Pacal, Turbo pacal, html, AS, AS2, java and java script, all at a low level mostly by hobby and free time.

gone trough all "making games with Ben" tutorials on youtube. (check thm out, you'll be glad you did)
read all of "SFML game devolopment by example" by R. Pupius (awesome book btw, can recommend, especial if a v. 2 comes out)

and this will be my devolopment log.

A demo can be downloaded here from my google drive:
https://drive.google.com/folderview?id=0B0wU233V6VHRZms3eGY4Y19acjA&usp=sharing
Latest update - Pre-Alpha : 28/7-16



About the game:
(click to show/hide)
The worksheet
(click to show/hide)

First video in spoiler:
(click to show/hide)


here is a video of my current progress
- 27/7-16 -

http://youtu.be/B-mRCY-JCYQ

8
Window / SOLVED! Render window and iterators / vectors
« on: July 20, 2016, 02:56:46 pm »
So. i seem to have a small problem here.

I got a number of Buttons (a class i made) stored in a vector like so:
vector<Buttons> _Btns;

now, all _Btns members have been initialized. each contain a
sf rect
sf text
void render(sf::RenderWindow& l_window)
int update(int x, int y)

and some other functions and variables that are irrelevant to this problem.


now, i update the buttons like so:
Quote
int updated = 0;
for (auto itr = _Btns.begin(); itr != _Btns.end(); ++itr) {
   itr->update(sf::Mouse::getPosition(l_window).x / 2, sf::Mouse::getPosition(l_window).y / 2);
   if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
      updated = itr->TestPress();
      if (updated != 0) current = updated;
   }
}

No problem there.

now, rendering gets a bit odd.

This works:
Quote
_Btns.back().render(l_window);
except that it only lets me render the last button added.

but this:

Quote
for (auto itr = _Btns.begin(); itr != _Btns.end(); ++itr) {
   itr->render(l_window);
}
does not?

neither does:
Quote
_Btns.front().render(l_window);
Now, seeing as i can iterate with the update function, and I can render calling only the "back()"

I'm at a lost... what should i do to iterate and render my _Btns?

//I will get back with the answer if i find it first, but after 12 hours of google search I'm a bit done for!

//i know, the update function is not need in this example, it was just to show that one form works, another does not :S

Pages: [1]