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

Pages: [1]
1
General / Hitbox
« on: March 18, 2022, 12:52:34 am »
Hello! A new programmer here!. I`m developing a videogame, because it`s the final proyect of one of my assignments.

Right now im making the menu, and i dont know how to make the mouse interact with the buttons. I mean, i know how to make the button react to the click of the mouse, but i can`t find a way to verify if the mouse is inside the hitbox of the button

Any help is apprecitaed.

Thank you!~

2
General / Problem spawning multiple enemies
« on: February 22, 2022, 10:08:55 pm »
Hello!

I have a problem whit a game that I am developing, i want to spawn random enemies across time, but only one of them appears in screen. Someone can help me? :D

I made this classes, entidad(entity), entidadmanager(entitymanager) and partida.
entidad::entidad() {
       
        static Texture *tex = 0;
        if(tex == 0){
                tex = new Texture();
                tex->loadFromFile("meteorito.png");
        }
        Sprite ast;
        ast.setTexture(*tex);
        m_sprite = ast;
        m_sprite.setScale(0.03f,0.03f);
        m_pos.x = rand () % 800 + 30;;
        m_pos.y = -10;
        m_sprite.setPosition(m_pos.x,m_pos.y);
}
void entidad::actualizar(){
        m_sprite.move(0,0.3);
}
void entidad::dibujar(RenderWindow &w){
        w.draw(m_sprite);
}

Vector2f entidad::verposi(){
        Vector2f charpos = m_sprite.getPosition();
        return charpos;
}



entidadmanager::entidadmanager() {
        vector<entidad> v;
        m_v = v;
        Clock reloj;
        m_reloj = reloj;
}
void entidadmanager::actualizar(){
       
        if(m_reloj.getElapsedTime().asMilliseconds() >= 1000){
                entidad aux;
                m_v.push_back(aux);
        }
        for(size_t i=0;i<m_v.size();i++) {
                m_v[i].actualizar();
                Vector2f charaux;
                charaux = m_v[i].verposi();
                if(charaux.y > 900){
                        auto it = next(m_v.begin(),i);
                        m_v.erase(it);
                }
        }
        m_reloj.restart();
}
void entidadmanager::dibujar(RenderWindow &w){
        for(size_t i=0;i<m_v.size();i++) {
                entidad aux;
                aux = m_v[i];
                aux.dibujar(w);
        }


Partida::Partida() {
        nave n1;
        entidadmanager met;
       
}
bool fuera(disparo &d){
        Vector2f p = d.verPosicion();
        if(p.x<0 or p.x>1600) return true;
        if(p.y<0 or p.y>900) return true;
        return false;

}
void Partida::actualizar(juego &j) {
        n1.actualizar();
        met.actualizar();
        if(n1.dispara()) vd.push_back(n1.dispGen());
        for(disparo &d : vd) d.actualizar();
        auto it2 = remove_if(vd.begin(),vd.end(),fuera);
        vd.erase(it2,vd.end());
}
void Partida::dibujar(RenderWindow &w, Sprite fondo) {
        w.clear(Color(220,220,180,255));
        w.draw(fondo);
        n1.dibujar(w);
        met.dibujar(w);
        for(disparo &d : vd) d.dibujar(w);
}


I guess that the problem is in entidadmanager::actualizar, but I can`t find it.

3
General / Re: Spawning random enemies
« on: February 21, 2022, 08:01:36 pm »
Hi, im back.

I tried that but the program does not work, just one asteorid appear. If you have time and want to help me with this last thing, I appreciate it!!

Have a good day.

4
General / Re: Spawning random enemies
« on: February 17, 2022, 08:49:11 pm »
Now the program is working!!! Asteroids appears in screen now, but I have to find a way to spawn a lot of them, cuz now only one appears.

Thank you!!!

5
General / Re: Spawning random enemies
« on: February 16, 2022, 07:38:58 pm »
Thank you so much! :D

How can I fix that downside that you said before?


Have a nice day.

6
General / Spawning random enemies
« on: February 16, 2022, 02:55:26 pm »
Hello, im new using SFML. I'm doing a proyect for my carreer, the proyect consist in a 2D game, where the user plays as a spaceship, and you have to destroy or avoid asteroids.

The program compiles and execute normally, but it has a problem, and is that the asteroids does not draw in the screen, and I don`t now how to fix it.

For the asteroids I use 2 classes, Entidades(entity) and entidadManager(EntityManager).

///ENTIDAD
#ifndef ENTIDAD_H
#define ENTIDAD_H
#include <SFML/System/Vector2.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Sprite.hpp>
using namespace std;
using namespace sf;
class entidad {
public:
        entidad();
        void actualizar();     
        void dibujar (RenderWindow &w);
        Vector2f verposi();
private:
        Vector2f m_pos;
        Sprite m_sprite;
};

#endif

#include "entidad.h"
#include <SFML/System/Vector2.hpp>
#include <SFML/System/Clock.hpp>
#include <vector>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <cstdlib>
using namespace std;

entidad::entidad() {
        Texture tex;
        Sprite sp;
        tex.loadFromFile("meteorito.png");
        sp.setTexture(tex);
        m_sprite = sp;
        m_sprite.setScale(0.70f,0.70f);
        m_pos.x = rand () % 800 + 30;;
        m_pos.y = 0;
        m_sprite.setPosition(m_pos.x,m_pos.y);
}
void entidad::actualizar(){
        m_sprite.move(0,-5);
}
void entidad::dibujar(RenderWindow &w){
        w.draw(m_sprite);
}

Vector2f entidad::verposi(){
        Vector2f charpos = m_sprite.getPosition();
        return charpos;
}
///ENTIDAD

///ENTIDADMANAGER

#ifndef ENTIDADMANAGER_H
#define ENTIDADMANAGER_H
#include <vector>
#include "entidad.h"
#include <SFML/Graphics/RenderWindow.hpp>
using namespace std;

class entidadmanager {
public:
        entidadmanager();
        void actualizar();
        void dibujar(RenderWindow &w);
private:
        vector<entidad> m_v;
};

#endif

#include "entidadmanager.h"
#include "entidad.h"
#include <vector>
#include <iterator>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
using namespace std;


entidadmanager::entidadmanager() {
        vector<entidad> v;
        m_v = v;
}
void entidadmanager::actualizar(){
        Clock reloj;
        if(reloj.getElapsedTime().asMilliseconds() == 1000){
                entidad aux;
                m_v.push_back(aux);
                reloj.restart();
        }
        for(size_t i=0;i<m_v.size();i++) {
                m_v[i].actualizar();
                Vector2f charaux;
                charaux = m_v[i].verposi();
                if(charaux.y > 900){
                        auto it = next(m_v.begin(),i);
                        m_v.erase(it);
                }
        }
       
}
void entidadmanager::dibujar(RenderWindow &w){
        for(size_t i=0;i<m_v.size();i++) {
                entidad aux;
                aux = m_v[i];
                aux.dibujar(w);
        }
}
///ENTIDADMANAGER

///PARTIDA

Partida::Partida() {
        nave n1;
        entidadmanager met;
       
}
bool fuera(disparo &d){
        Vector2f p = d.verPosicion();
        if(p.x<0 or p.x>1600) return true;
        if(p.y<0 or p.y>900) return true;
        return false;

}
void Partida::actualizar(juego &j) {
        n1.actualizar();
        met.actualizar();
        if(n1.dispara()) vd.push_back(n1.dispGen());
        for(disparo &d : vd) d.actualizar();
        auto it2 = remove_if(vd.begin(),vd.end(),fuera);
        vd.erase(it2,vd.end());
}
void Partida::dibujar(RenderWindow &w, Sprite fondo) {
        w.clear(Color(220,220,180,255));
        w.draw(fondo);
        n1.dibujar(w);
        met.dibujar(w);
        for(disparo &d : vd) d.dibujar(w);
}
///PARTIDA

Sorry if  the post it`s a bit long (a bit too long haha) but it`s my first one.

Any help is appreciated  ;D

Pages: [1]
anything