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

Pages: [1]
1
General / Re: Need your help to solve some problems.
« on: April 06, 2013, 12:37:41 am »
Hello guys, it's me again :)
I have more questions.
First one is about collision:
here is the code:
               
enemy[i].radius = (enemy[i].enemy.getGlobalBounds().width + enemy[i].enemy.getGlobalBounds().height) / 4;
enemy[i].xd = enemy[i].enemy.getPosition().x - p.PlayerBubble.getPosition().x;
enemy[i].yd = enemy[i].enemy.getPosition().y - p.PlayerBubble.getPosition().y;
enemy[i].distance = sqrt(enemy[i].xd * enemy[i].xd + enemy[i].yd * enemy[i].yd);

//and this part
if(enemy[i].distance <= (p.radius + enemy[i].radius))
{ enemy[i].alive = false;
p.PlayerBubble.setScale(p.scale + 1, p.scale + 1);
 

It works, but if I go under group of  enemy-bubbles, it seems like collision is happening. even if it does not.

Other problem is about redrawing enemies.
if I put this code outsie of my game loop:
       
for( int i = 0; i < NUM_ENEMIES; i++)
{ if (!enemy[i].alive) // need to change later 
enemy[i].alive = true;
enemy[i].DrawEnemy(); }
Works fine, but enemies are not redrawing.
If I am putting this inside my main game loop, redrawing is working, but bubbles are not moving at all, they just standing there, until I collide with them and then they appear on the different position.

2
General / Re: Need your help to solve some problems.
« on: April 02, 2013, 03:00:36 pm »
Thank you guys for advises.
Never thought of containers before, gonna google it now.
I've cleaned code as much as possible.
For now my collision is based on x, and y coordinates, it works sometimes.
But now I need to solve one problem: when bubble is eaten, the new bubble should be drawn, so there are always 10 bubbles on the screen.  I guess that container thing gonna help.


#include <SFML/Graphics.hpp>
#include "objects.h"
#include <stdlib.h>
#include <math.h>
#include <Thor/Math.hpp>



//Globals
sf::VideoMode mode = sf::VideoMode::getDesktopMode(); // Get Your Desktop resolution
int Score;
int speed = 15;
const int NUM_ENEMIES = 10;


int main()
{       float timer;

//Playerdata
        Player p;
        p.x = mode.width / 2;
        p.y = -mode.height / 2;
        p.speed = speed + 10;
        p.scale = 1.5;
        p.SWidth = mode.width;
        p.SHeight = mode.height;
//EnemyData
        AngryBubble enemy[10];
        float a, b;
        a = 0.2;
        b = 3.5;
        for( int i = 0; i < NUM_ENEMIES; i++)
        {
                enemy[i].position.x = thor::random(0,mode.width);
                enemy[i].position.y = thor::random(0,mode.height);
                enemy[i].speed = 3;
                enemy[i].scale = thor::random(a, b);
                enemy[i].angry = false;
                enemy[i].alive = false;

       


               
        }
       
        //Open window with your display resolution
    sf::RenderWindow window(sf::VideoMode(mode.width,mode.height), "Bubble!");
        sf::Clock clock;
        p.DrawPlayer();
        for( int i = 0; i < NUM_ENEMIES; i++)
        { if (!enemy[i].alive) // need to change later
        enemy[i].alive = true; 
        enemy[i].DrawEnemy();
               
        }
       
    while (window.isOpen())
    {
               
        sf::Event event;
                sf::Keyboard keyevent;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
       }
                 
                //Controlls
                p.PlayerMove();

                //Enemy logic
               
                //     Movement
               
                for( int i = 0; i < NUM_ENEMIES; i++)  //Angry Enemies ( if enemy is bigger than you it going to angry and it'll try to eat you...)
                { if(enemy[i].enemy.getScale().x > p.PlayerBubble.getScale().x)
                {
               
                if(p.PlayerBubble.getPosition().y < enemy[i].enemy.getPosition().y)
                {
                        enemy[i].enemy.move(0, -enemy[i].speed);
                        if(enemy[i].enemy.getPosition().y < 0) // Enemy won't go off the screen
                                enemy[i].enemy.setPosition(enemy[i].enemy.getPosition().x, 0);
                                       
                }
                if(p.PlayerBubble.getPosition().y > enemy[i].enemy.getPosition().y)
                {
                        enemy[i].enemy.move(0, enemy[i].speed);
                        if(enemy[i].enemy.getPosition().y > mode.height)
                                enemy[i].enemy.setPosition(enemy[i].enemy.getPosition().x, mode.height);
                       
                }
                if(p.PlayerBubble.getPosition().x > enemy[i].enemy.getPosition().x)
                {
                        enemy[i].enemy.move(enemy[i].speed, 0);
                        if(enemy[i].enemy.getPosition().x > mode.width)
                                enemy[i].enemy.setPosition(mode.width, enemy[i].enemy.getPosition().y);
                                       
                }
                        if(p.PlayerBubble.getPosition().x < enemy[i].enemy.getPosition().x)
                {
                        enemy[i].enemy.move(-enemy[i].speed, 0);
                if(enemy[i].enemy.getPosition().x < 0)
                                enemy[i].enemy.setPosition(0, enemy[i].enemy.getPosition().y);
                if(enemy[i].enemy.getPosition().x == p.PlayerBubble.getPosition().x || enemy[i].enemy.getPosition().y == p.PlayerBubble.getPosition().y)
                        { enemy[i].alive = false;
                p.PlayerBubble.setScale(p.scale - 1, p.scale - 1);
                }
                                       
                }
                }
                }

               

                 for( int i = 0; i < NUM_ENEMIES; i++)  //Non-Angry Enemies ( if enemy is smaller than you it going to run away from you...)
                { if(enemy[i].enemy.getScale().x < p.PlayerBubble.getScale().x) {
               
                if(p.PlayerBubble.getPosition().y > enemy[i].enemy.getPosition().y)
                {
                        enemy[i].enemy.move(0, -enemy[i].speed);
                        if(enemy[i].enemy.getPosition().y < 0)
                                enemy[i].enemy.setPosition(enemy[i].enemy.getPosition().x, 0);
                                       
                }
                if(p.PlayerBubble.getPosition().y < enemy[i].enemy.getPosition().y)
                {
                        enemy[i].enemy.move(0, enemy[i].speed);
                        if(enemy[i].enemy.getPosition().y > mode.height)
                                enemy[i].enemy.setPosition(enemy[i].enemy.getPosition().x, mode.height);
                       
                }
                if(p.PlayerBubble.getPosition().x < enemy[i].enemy.getPosition().x)
                {
                        enemy[i].enemy.move(enemy[i].speed, 0);
                        if(enemy[i].enemy.getPosition().x > mode.width)
                                enemy[i].enemy.setPosition(mode.width, enemy[i].enemy.getPosition().y);
                                       
                }
                        if(p.PlayerBubble.getPosition().x > enemy[i].enemy.getPosition().x)
                {
                        enemy[i].enemy.move(-enemy[i].speed, 0);
                if(enemy[i].enemy.getPosition().x < 0)
                                enemy[i].enemy.setPosition(0, enemy[i].enemy.getPosition().y);
                if(enemy[i].enemy.getPosition().x == p.PlayerBubble.getPosition().x || enemy[i].enemy.getPosition().y == p.PlayerBubble.getPosition().y)
                        { enemy[i].alive = false;
                p.PlayerBubble.setScale(p.scale + 1, p.scale + 1);
                }
                                       
                        }
                       
                 } }
                 
               
               

                window.clear(sf::Color::Blue);
                window.setVerticalSyncEnabled(true); //For Smooth animation
                timer = clock.getElapsedTime().asMilliseconds();
                clock.restart();
                window.draw(p.PlayerBubble);
               
                for( int i = 0; i < NUM_ENEMIES; i++)
                { if(enemy[i].alive)
                        window.draw(enemy[i].enemy);
                }
                window.display();
    }

    return 0;
}


And here what I mean by refresh:
 
        sf:: Font MyFont;
        MyFont.loadFromFile("font.ttf");
        sf::Text myText;


       
        myText.setFont(MyFont);
        myText.setCharacterSize(30);
std::string s;
std::stringstream out;
out << p.PlayerBubble.getPosition().x << " : " <<  p.PlayerBubble.getPosition().y;

        myText.setString(out.str());
        myText.setPosition( mode.width - 300, mode.height -100); // y = close to 0
        myText.setColor(sf::Color::Black);
 
I for example want to display current x and y coordinates of player, but they are not updating.
I hope now my explanation is a bit better.

3
General / Re: Need your help to solve some problems.
« on: April 02, 2013, 01:20:34 pm »
Ok, seems like no one wants to answer my question.
I have another one: How do I refresh things?
For example my text string does not want to update, and I want to have always for example 10 enemies in the screen, but ether they exist,ether they don't...

4
General / Need your help to solve some problems.
« on: March 28, 2013, 02:12:50 pm »
Hello guys!
I am trying to apply to game development university to learn programming, but in order to get there I need to make a game. What a paradox.  They have a specific topic for the game called "bubbles".
Well I learned a bit of C++, and then I was playing with different Allegro and SFML , now I stopped on SFML.

My idea of the game is simple: You control a bubble, and there are other bubbles on the screen. If enemy bubble is smaller he'll try to escape from you, as you can eat him. If you eat him you will grow.
But if enemy bubble is bigger than you, he will try to eat you!

Well, I've managed to make bubbles to follow and run away from player, but I have problems which I do not know how to solve:

  • Small bubbles stuck in corners. (you can see one in top right corner)
    Bubbles which are following you after a while will be in one spot.
    Don't know how to make player to eat bubbles.
    Don't really know how to redraw bubbles after they died.
(basically I do know how to deal with collision)

Other problem that my string with variable does not updating( You can also see it in the video), I was trying to display player position in order to understand what's happening, but it does not updating.

Here is the video of my "game", so you can understan what I am talking about.



I will attach the code as a file, as I can't make the minimum code, because everything sucks in my code  ;D

I've read and watched a lot of tutorial, but guys, I need your help in order to solve my problems, which are most likely about collision. I was thinking about using box2d, but I guess my game is too simple for it.

[attachment deleted by admin]

Pages: [1]