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

Pages: [1]
1
Graphics / Circular movement
« on: January 13, 2014, 06:25:33 pm »
Hello,

I want to let move circle in a circular path. How can I do that?

I tried this. It works, but this was not the solution for my problem => its completly wrong:

        //if(stoney <= 100){down=true; up=false;}
        //if(stoney >= 350){down=false; up=true;}

        //if(down==true,up==false)
        //{
        //      stone.move(0,Speed*ElapsedTime);
        //}
        //else if(down==false,up==true)
        //{
        //      stone.move(0,-Speed*ElapsedTime);
        //}

        //if(stonex <= 125){right=true; left=false;}
        //if(stonex >= 375){right=false; left=true;}

        //if(right==true,left==false)
        //{
        //      stone.move(Speed*ElapsedTime,0);
        //}
        //else if(right==false,left==true)
        //{
        //      stone.move(-Speed*ElapsedTime,0);
        //}

        //std::cout << "X: " << stonex << " Y: " << stoney << std::endl;

I think, I have to work with sin and cos, but I dont know how I can do that..

kurs

2
Graphics / two questions: "collision-stop-detect" and "random move"
« on: January 06, 2014, 10:31:39 am »
Hello!!

Im working on new projects and there is two things that I dont understand.

Question 1:
I know how I can make a Collision with this Code:
object.getGlobalBounds().intersects( player.getGlobalBounds()....

I know, how I can "destroy" the object or the player, set a other position for the players etc.

But.. if I want to make a 2D-RPG game, how should the Code looks like, if I want that the Player "stops" to the object? Should I work with booleans? I never implented this and I have no idea how I can do this.
I think, I would do this (pseudo code):

if (object.getglobalBounds intersects player globalbounds
   &&pressRight=true)
{
   Walkspeed = 0;
}
else if(object.getglobalBounds intersects player globalbounds
   &&pressRight=true)
{
   Walkspeed = 0;
} //(...)
else
{
   Walkspeed = X
}

or this:

if(...) &&right=true
{
 move(x-1,y)
}

But I know its stupid and wrong, and I dont know if this stupid code is working.
Can you tell me, how you do this? How you create a Code that the player "stops" at the objects?

Question 2:

This is a bit more complex (maybe..): I want to give every Sprite his own moves.

For example, please have a look at this pseudo code:

timer >= 100
{

randomz = rand() % 5 + 1;

if(randomz = 1)
  randomx = 5, randomy  = 3;
if(randomz = 2)
  randomx = -2, randomy = -5;
(...)

Create Sprite process

sprite*move(randomx, randomy)
timer = 0
}

The problem is: I dont know, if every sprite get his "own" move, or its a "global move" like: movement is changing every time for all sprites.

Kursukia :)

Sorry for my broken english!

3
Window / [solved]Problems to record my game
« on: December 28, 2013, 11:05:48 pm »
Hello guys,

I have a exotic problem that I cant record my created app.

I cant use FRAPS, and some other recording-tools for record my selfcreated game.
If I start to use the record-tool, its like my game have a super fps-dropdown, all is going slown.
Its happening with all record tools that im tested: Fraps 19D, Fraps 3.5, MSI afterburner and camtasia studio.

But if I show someone via Skype my game, so I dont have this problems.

Can you tell me, what this problem is caused?
I tryed with FrameLimit and without FrameLimit. The maximum setting on Fraps is 60 FPS, and on MSI afterburner with 100 fps. But still the same problem. The whole game is going crazy. So if I use FRAPS, it shows me over 4500 fps.

I really dont know what code I should post. Please tell me it. The whole project is a bit too large.

Im sorry for my broken english.

Greetings :(

4
Graphics / [solved]Collision - want remove Sprite from List + Update
« on: December 27, 2013, 06:19:48 pm »
Hello ^_^

im working on my project and I have a problem with the collision-class.

All is working fine and if getGlobalBounds turn to "true", the collision is detect. But.. it dont delete the Sprite from the list. It still "moving" and my list is still "full".

Please, dont be angry. Im still in practice. ._. Im trying my best. But the Collision is very hard (not to create - its only because of make OOP and use the right syntax and right return-methods(?)). So I hope you can show me, what I can do. I know, the Code is not "clean". But for the first one, it should be a good step.

Collision.hpp:
#ifndef COLLISION_HPP
#define COLLISION_HPP

#include "Enemy.hpp"
#include "Player.hpp"
#include <SFML\Graphics.hpp>
#include <list>

using namespace sf;

class Collision
{
public:
        void            Collision2Attack(std::list<sf::Sprite>enemyList,
                                                                std::list<sf::Sprite>::iterator enemyIt,
                                                                sf::Sprite hitBoxR,
                                                                RenderWindow &window
                                                                );
        void            update4List(std::list<sf::Sprite>enemyList,
                                                                std::list<sf::Sprite>::iterator enemyIt
                                                                );
};

#endif

Collision.cpp:
#include "Enemy.hpp"
#include "Player.hpp"
#include "Collision.hpp"
#include <SFML\Graphics.hpp>
#include <list>

using namespace sf;

Enemy enemy;
Player player;

void Collision::Collision2Attack(std::list<sf::Sprite>enemyList,
                                                                std::list<sf::Sprite>::iterator enemyIt,
                                                                sf::Sprite hitBoxR,
                                                                RenderWindow &window
                                                                )
{

        for(enemyIt=enemyList.begin();enemyIt!=enemyList.end();)
        {
                if( hitBoxR.getGlobalBounds().intersects(enemyIt->getGlobalBounds() ))
                {
                        //enemyIt=enemyList.erase(enemyIt);
                        enemyIt->setPosition(0,0);
                        std::cout << "delete" << std::endl;
                        Collision::update4List(enemyList, enemyIt);
                }
                else
                {
                        enemyIt++;
                }
        }

       
}

void Collision::update4List(std::list<sf::Sprite>enemyList,
         std::list<sf::Sprite>::iterator enemyIt
         )
{
        ::enemy.update4ListE(enemyList,
                                                enemyIt
                                                );
}

Enemy.cpp:
#include "Enemy.hpp"
#include "Collision.hpp"
#include <SFML\Graphics.hpp>
#include <iostream>
#include <string>

using namespace sf;

Enemy::Enemy()
{
        Speed = 300.f;
        enemyTex.loadFromFile("enemy_l.png");
        enemyTime = 0.0000;
}

void Enemy::Draw(RenderWindow &window, float ElapsedTime)
{
        for(enemyIt=enemyList.begin();enemyIt!=enemyList.end();enemyIt++)
        {
                enemyIt->move(-Speed*ElapsedTime,0);
                window.draw(*enemyIt);
        }
}

void Enemy::Process(RenderWindow &window, float ElapsedTime, float enemyTimer)
{
        enemyTime += enemyTimer;

        if(enemyTime>=9000)
        {
                enemySprite = new sf::Sprite;
                enemySprite->setTexture(enemyTex);
                enemySprite->setPosition(720, 410);
                enemySprite->setScale(0.6,0.6);
                enemyList.push_back(*enemySprite);
                enemyTime=0;
        }

        for(enemyIt=enemyList.begin();enemyIt!=enemyList.end();)
        {
                if(enemyIt->getPosition().x<=0)
                {
                        enemyList.erase(enemyIt);
                        enemyIt=enemyList.begin();
                }
                else
                {
                        enemyIt++;
                }
        }

}

void Enemy::update4ListE(std::list<sf::Sprite>enemyList,
                                                std::list<sf::Sprite>::iterator enemyIt
                                                )
{
        enemyList = enemyList;
        enemyIt = enemyIt;
       
        std::cout << static_cast<int>(enemyList.size() ) << std::endl;

}

So I didnt know, how the Enemy-Class can get the "new List", so I thought i just create a simply "update4ListE" method for updating the current List on the other class, but it isnt working.

So I want to ask you (because you all have more skills). ._.

Greetings

5
Graphics / Bad Movement (judder) for Player-image
« on: December 22, 2013, 04:00:16 pm »
Hello guys, thank you for joining this community.

Im new on SFML and C++ and want to learn several things. At first, im sorry for my bad english skills.

I want to make a little game. All works fine, but if I moving the "player sprite", so its like a "move judder".
I dont understand why and I hope you can give me the answer for this (maybe I did something wrong?)

The first one: Its SFML version 2.1, and Im working with Visual Studio 10.

The Codes are:

main.cpp
// internal
#include "Background.hpp"
#include "Player.hpp"

// external
#include <SFML/Graphics.hpp>
#include <iostream>

using namespace sf;

int main()
{

        // settings
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Window");
window.setFramerateLimit(60);

        // classes
Background background;
Player player;

        // variable
sf::Clock clock;

        // Start the game loop
        while (window.isOpen())
        {
        // Process events
        sf::Event event;

        float ElapsedTime = clock.restart().asMilliseconds();

                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

        // Clear the screen
                window.clear();

        // draw background
                background.Update(window);
               
        // draw player plus animation
                player.Animation(window, ElapsedTime);
                player.Draw(window);
       
        // display window
                window.display();
        }
        return EXIT_SUCCESS;
}
 

player.hpp:
#include <SFML\Graphics.hpp>

using namespace sf;

class Player
{

public:
        void                    Animation(RenderWindow &window, float ElapsedTime);
        void                    Draw(RenderWindow &window);
        Vector2f                getPosition();
        Player();

public:
        Texture tP;
        Sprite sP;

private:
        float Speed;

};

player.cpp:
// internal
#include "Player.hpp"

// external
#include <SFML\Graphics.hpp>
#include <iostream>

using namespace sf;

Player::Player()
{
        Speed = .4f;
       
        tP.setSmooth(true);    
        tP.loadFromFile("player1_r.png");
        sP.setTexture(tP);
        sP.setPosition(50,50);
}

void Player::Animation(RenderWindow &window, float ElapsedTime)
{
        float x = sP.getPosition().x;
        float y = sP.getPosition().y;

                if(Keyboard::isKeyPressed(Keyboard::Left))
                {
                        if(x <= 10)
                        {
                                x = 10;
                        }else{
                                x = x - (Speed*ElapsedTime);
                        }                                              
                }
                if(Keyboard::isKeyPressed(Keyboard::Right))
                {
                        if(x >= window.getSize().x - 10)
                        {
                                x = window.getSize().x - 10;
                        }else{
                                x = x + (Speed*ElapsedTime);                   
                        }
                }
                sP.setPosition(x,y);
}

void Player::Draw(RenderWindow &window)
{
        window.draw(sP);
}

Vector2f Player::getPosition()
{
        return sP.getPosition();
}

Pages: [1]