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.


Messages - freesoul

Pages: [1] 2
1
SFML projects / Re: Screenshot Thread
« on: January 07, 2024, 10:53:14 pm »
An exploration RPG in development for a few months now.


2
SFML projects / RarePG, an experimental game
« on: July 07, 2018, 03:36:59 pm »
Hello. I am developing a totally experimental game in my free time using this library.

Next step I think that will be adding a menu, and all ideas from the readme.md

Maybe I left some comment in spanish, but I am moving it to english.

If you wish, you are free to contribute with code, graphics, sounds or whatever

I initially made it as a MVS project, but now it runs under Linux and its compiled with gcc

https://github.com/freesoul/RarePG

You are welcome!

And try to spawn the "rocket" object, I love it

3
General / Re: Global input vs event?
« on: August 13, 2013, 08:44:00 pm »
In which tutorial can I find which system is better? I could read what does events and what does global input, but I didn't find which I should use

4
General / Global input vs event?
« on: August 13, 2013, 07:37:58 pm »
What is better way to get input of mouse/keyboard for a game? Events, or testing global input?

5
Graphics / Re: Need real corner coordinates of rotated rectangle
« on: August 11, 2013, 10:30:56 pm »
Finally I finished my little collision check for rotated rectangles, thanks you. Code below

sat.h
#ifndef SAT_
#define SAT_

#include <SFML/Graphics.hpp>


        struct rectangle {
                sf::Vector2f vertex[4];
        };

class SAT {
public:
        bool collision(sf::Sprite* s1, sf::Sprite* s2);
private:
        void  SAT::project(sf::Vector2f& axis, rectangle* _rectangle, float &min, float &max);
        void normalize(sf::Vector2f& vector);
        float dot(sf::Vector2f& vector1, sf::Vector2f& vector2);
        float SAT::distance(float minA, float maxA, float minB, float maxB) ;
};


#endif


#include <math.h>
#include "SATcollision.h"


void SAT::normalize(sf::Vector2f& vector) {
        const float length = sqrt(vector.x * vector.x + vector.y * vector.y);
        if(length==0)
                return;
        vector.x = vector.x / length;
        vector.y = vector.y / length;
}

float SAT::dot(sf::Vector2f& vector1, sf::Vector2f& vector2)
{
        return vector1.x*vector2.x + vector1.y*vector2.y;
}

float SAT::distance(float minA, float maxA, float minB, float maxB) // Positive return = no hit
{
        if(minB > maxA) return minB-maxA;
        else return minA-maxB;
}




void  SAT::project(sf::Vector2f& axis, rectangle* _rectangle, float &min, float &max)
{
        float _dot = dot(axis, _rectangle->vertex[0]);

        min=_dot;
        max=_dot;

        for(short i=1; i<4; i++)
        {
                _dot = dot(_rectangle->vertex[i], axis);

                if(_dot<min)
                        min=_dot;
                else if(_dot>max)
                        max=_dot;
        }
}


bool SAT::collision(sf::Sprite* s1, sf::Sprite* s2)
{
        rectangle one;
        rectangle two;

        sf::Transform transform = s1->getTransform();
        sf::FloatRect rect = s1->getLocalBounds();

        one.vertex[0]=transform.transformPoint(sf::Vector2f(rect.left, rect.top));
        one.vertex[1]=transform.transformPoint(sf::Vector2f(rect.left+rect.width, rect.top));
        one.vertex[2]=transform.transformPoint(sf::Vector2f(rect.left+rect.width, rect.top+rect.height));
        one.vertex[3]=transform.transformPoint(sf::Vector2f(rect.left, rect.top+rect.height));

        transform = s2->getTransform();
        rect = s2->getLocalBounds();

        two.vertex[0]=transform.transformPoint(sf::Vector2f(rect.left, rect.top));
        two.vertex[1]=transform.transformPoint(sf::Vector2f(rect.left+rect.width, rect.top));
        two.vertex[2]=transform.transformPoint(sf::Vector2f(rect.left+rect.width, rect.top+rect.height));
        two.vertex[3]=transform.transformPoint(sf::Vector2f(rect.left, rect.top+rect.height));

        sf::Vector2f axis;
        float minA;
        float minB;
        float maxA;
        float maxB;
       

        // Test one
        axis.x = one.vertex[1].x - one.vertex[0].x;
        axis.y = one.vertex[1].y - one.vertex[0].y;
        SAT::normalize(axis);

        project(axis, &one, minA, maxA);
        project(axis, &two, minB, maxB);

        if(distance(minA,maxA,minB,maxB)>0.f)
                return false;


        // Test two
        axis.x = one.vertex[3].x - one.vertex[0].x;
        axis.y = one.vertex[3].y - one.vertex[0].y;
        SAT::normalize(axis);

        project(axis, &one, minA, maxA);
        project(axis, &two, minB, maxB);

        if(distance(minA,maxA,minB,maxB)>0.f)
                return false;


        // Test three
        axis.x = two.vertex[1].x - two.vertex[0].x;
        axis.y = two.vertex[1].y - two.vertex[0].y;
        SAT::normalize(axis);

        project(axis, &one, minA, maxA);
        project(axis, &two, minB, maxB);

        if(distance(minA,maxA,minB,maxB)>0.f)
                return false;


        // Test four
        axis.x = two.vertex[3].x - two.vertex[0].x;
        axis.y = two.vertex[3].y - two.vertex[0].y;
        SAT::normalize(axis);

        project(axis, &one, minA, maxA);
        project(axis, &two, minB, maxB);

        if(distance(minA,maxA,minB,maxB)>0.f)
                return false;

        return true;

}

6
Graphics / Re: Need real corner coordinates of rotated rectangle
« on: August 11, 2013, 05:56:42 pm »
Ok thanks. I set origin on centre, but I got rare results.

I got an image sized 223 x 75 px

I put the origin on the middle of the sprite, then rotate it 45º.

I make a point transform to a point (0, 75) and the result is

+      point   {x=-105.35892 y=-51.618793 }   sf::Vector2<float>


Why? -105 on x axis??

My expected result should be like (-10, 10) or so

I guess it has to do with origin. So, how can I rotate at that origin but have the input (0, 75), and the output from normal (0, 0) coord? thanks

7
Graphics / Need real corner coordinates of rotated rectangle
« on: August 11, 2013, 04:12:24 pm »
I want to apply SAT collision detection to my 2D game. As I understood, getGlobalBounds retrieves the bigger box that contains the rotated rectangle, but it isnt what i need. getLocalBounds gives the sprite without transformation, which I could use to get the rotated coords, but I actually dont know how to apply maths to, set an origin and an angle, get the coords ¿is there a way to get the real coordinates of the rotated sprite? thanks.

8
Graphics / Re: Rotation origin
« on: October 06, 2012, 10:14:38 pm »
Oh thanks. Well I can't do that move because I need to keep the global position relative to other sprites I display.

I've done this and it works :)
transf.rotate(mIt->fDegrees,mIt->spMissile.getPosition().x + mIt->halfWidth, mIt->spMissile.getPosition().y + mIt->halfHeight);
_window.draw(mIt->spMissile, transf);

But I don't know why I have to pass the global center position of the sprite to rotate it, but im glad it works !


Well, I needed to :

- calculate and save half width / height (2 int) for each item.
- save degrees in each items for post-using, instead of using it directly
- declare and define a new local variable sf::transform
- pass it as argument and add global sprite position

all that to do a simple rotation. I still think it would be simpler to add to sf::Transformable a SetRotationOrigin() member (by default rotation origin would be 0,0), but its ok

9
Graphics / Re: Rotation origin
« on: October 06, 2012, 09:32:59 pm »
I don't know what "transform" I should pass as argument :S  I would thank for a simple example.

I want to keep my position coords as (0, 0). So how to rotate at center?

Or an alternative to this (i actually dont know if this is correct):
sprite.setOrigin(center_x, center_y);
sprite.setRotation(angle);
sprite.setOrigin(-center_x, -center_y);

btw, sf::transform::rotate is it absolute or relative?

10
Graphics / Re: Rotation origin
« on: October 06, 2012, 09:24:23 pm »
Quote
To do such things, use sf::Transform directly.
How?  ;D

11
Graphics / Re: Rotation origin
« on: October 06, 2012, 09:13:42 pm »
I've read that but I don't get it  :o

I want to do absolute rotations given some degrees. I've read about sf::Transform, but I don't know how to use that

12
Graphics / Rotation origin
« on: October 06, 2012, 08:42:03 pm »
Hello, I need to draw some stuff with it's origin point (0, 0), but I need to rotate these stuff as the origin was in the center. Is it possible to do this? have two origins: one for rotation, other one for positioning? if not, I suggest to add this feature, thanks !

13
General / Re: Optimizing my main loop.
« on: September 24, 2012, 06:50:46 pm »
Ok sorry it was really long. Well, this is the part of code I think can ralentize more.

I've to say that my game is slow intermittently, 1 sec goes good, 1 sec goes bad

I check for each missile (there can be 1 to 150 at a time) if it's being hit by any of the current bullets casted (1 to 15 aprox)

void Missile_mgr::UpdateAndDrawMissiles(sf::RenderWindow& _window, float elapsedTime) {

        bool bHitByBullet;

         //////// MISSILE LOOP START ///////
        // This could be done with missileList.RemoveAllThatComply_nodeArg() + a condition function... but simplier this way.
        for(std::list<Missile>::iterator mIt = missileList.begin(); mIt!=missileList.end(); )
        {
                mIt->Update(elapsedTime);
                bHitByBullet = false;


                ////// BULLET LOOP START ////////
                for(std::list<Bullet>::iterator bIt=pBullet_mgr->bulletList.begin(); bIt!=pBullet_mgr->bulletList.end(); )
                {

                        if(Collision::BoundingBoxTest(mIt->spMissile, bIt->spBullet)) //// BULLET-MISSILE COLLISION.
                        {
                                mIt->hp -= pPlayer->damage;
                                if(mIt->hp <= 0)
                                {
                                        bHitByBullet=true; // should be bDeadMonster

                                        switch(mIt->type)
                                        {
                                        case Missile::Apple: // DEAD FRUIT -> NO REWARD.
                                                break;
                                        case Missile::Normal:
                                        default:
                                                        pLevel_mgr->xpReward+=10;
                                                        pLevel_mgr->coinReward+=10;
                                        }
                       
                                }

                                pBullet_mgr->bulletList.erase(bIt++);// laser weapon may ignore this line -> go through missiles.
                                                                                                                                                  // we can also break, so only 1 bullet is deleted, no 2. Plus we directly delete missile and no need bool bHitByBullet
                        } else ++bIt;
                       
                }
                ////// BULLET LOOP END ////////

                if(bHitByBullet) {
                        // score already increased in bullet loop. (may hit more than 1 missile)
                        missileList.erase(mIt++);
                } else {
                        if(Collision::BoundingBoxTest(mIt->spMissile, pPlayer->spPlayer)) //// MISSILE HIT PLAYER
                        {
                                switch(mIt->type) {
                                case Missile::Apple:
                                        pPlayer->Heal(1); // to be updated
                                        break;
                                case Missile::Normal:
                                default:
                                        pPlayer->DoDmg(2.5); // to be updated
                                        break;
                                }
                                missileList.erase(mIt++);
                        } else {
                                if(mIt->spMissile.getPosition().y > GROUND_ALTITUDE) { //// MISSILE HIT GROUND
                                        missileList.erase(mIt++);
                                } else { // Nothing happens
                                        _window.draw(mIt->spMissile);
                                        ++mIt;
                                }
                        }

                }

        } //////// MISSILE LOOP END ///////

}

14
General / Optimizing my main loop.
« on: September 24, 2012, 02:52:51 pm »
Hello all, a week ago I started working on my first game project, and a friend recommended me this library, which I found really good :)

The thing is, as I'm new to game programming, I don't know how to increase FPS. Actually I post this because I've noticed I my sprites stuck a bit while moving. My main code is below, I'm looking just for some advices, thanks :)

NOTE: this was written using SFML 1.6, I will pass to 2.0 soon.

I'd appreciate some advise to make my main loop more readable, because I'm tired of scrolling up an down to search my game loop case :P I know, maybe put code into functions, but I avoid calling functions the more I can, I think that ralentizes a bit, doesn't it?


15
General / Re: Window.input() or Mousemove event ?
« on: September 24, 2012, 02:40:12 pm »
Nice, thanks, that was good. I will pass my project to SFML 2.0 soon

Pages: [1] 2
anything