Jump to content
  • Advertisement

LeftyGuitar

Member
  • Content Count

    75
  • Joined

  • Last visited

Community Reputation

245 Neutral

About LeftyGuitar

  • Rank
    Member

Personal Information

  • Interests
    Programming
  1. LeftyGuitar

    C++ Mouse Input Raylib

    Ok I seem to make a little bit more progress. Now it sometimes increases the value and other times it doesen't. EDIT: Ok I figured it out! I needed to put the GetMousePosition inside of the update loop to get the mouse's position in real-time. Vector2 mp; Vector2 pos; RedBall.X_Pos = static_cast <float> (rand() % Width / 2); RedBall.Y_Pos = static_cast <float> (rand() % Height / 2); RedBall.Radius = 20; mp = GetMousePosition(); pos = { GetMousePosition().x,GetMousePosition().y }; if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && CheckCollisionPointCircle(pos,RedBall.Pos,RedBall.Radius)) { Player.Current_Game_Score++; }
  2. Hello, I am trying to get the point counter to increment when the user clicks on a ball using the mouse. I'm using the Raylib library. I have posted a snippet of my code. I can post if more is needed. Vector2 mp = GetMousePosition(); RedBall.X_Pos = static_cast <float> (rand() % Width / 2); RedBall.Y_Pos = static_cast <float> (rand() % Height / 2); RedBall.X_Vel = 8.0f; RedBall.Y_Vel = 8.0f; RedBall.Pos = { RedBall.X_Pos,RedBall.Y_Pos }; RedBall.Vel = { RedBall.X_Vel,RedBall.Y_Vel }; RedBall.Pos.x += RedBall.Vel.x; RedBall.Pos.y += RedBall.Vel.y; if ((RedBall.Pos.x >= (GetScreenWidth() - RedBall.Radius)) || (RedBall.Pos.x <= RedBall.Radius)) RedBall.Vel.x *= -1.0f; if ((RedBall.Pos.y >= (GetScreenHeight() - RedBall.Radius)) || (RedBall.Pos.y <= RedBall.Radius)) RedBall.Vel.y *= -1.0f; //problem with collision detecting? if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && CheckCollisionPointCircle(RedBall.Pos,mp,RedBall.Radius)) { Player.Current_Game_Score++; //does not increment } DrawCircleV(RedBall.Pos, RedBall.Radius, RED);
  3. LeftyGuitar

    Can't get Bullet to shoot [SFML/C++]

    OK, so now I am trying to add more bullets, or make it where you can fire more than one bullet. However whenever I hit the space key, it makes a bullet appear one after the other. It doesn't move to the right of the screen like it did, when there was just one bullet.   EDIT: I figured it out. I had to change this line of code bullet.shape.move(bullets[i].Speed, 0); //Needed to be this bullets[i].shape.move(bullets[i].Speed,0); vector <BULLET> bullets; bullet.X = player.X; bullet.Y = player.Y; bullet.Visible = false; bullet.Speed = 0.0f; bullet.shape.setPosition(sf::Vector2f(bullet.X,bullet.Y )); bullet.shape.setRadius(10); bullet.shape.setFillColor(sf::Color(255, 0, 0)); while (GameWin.isOpen()) { while (GameWin.pollEvent(event)) { if (event.type == sf::Event::Closed) { GameWin.close(); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { bullet.Visible = true; bullet.Speed = 0.010f; bullets.push_back(bullet); } } GameWin.clear(); GameWin.draw(player.shape); if (bullet.Visible) { for (int i = 0; i < bullets.size(); i++) { GameWin.draw(bullets[i].shape); bullet.shape.move(bullets[i].Speed, 0); if (bullets[i].shape.getPosition().x >= 800) { bullets[i].Visible = false; bullets[i].Speed = 0.0f; } } } GameWin.display(); }
  4. LeftyGuitar

    Can't get Bullet to shoot [SFML/C++]

    OK I figured out the first part of my problem. I had setScale, what I needed was setRadius in order for the bullet shape to appear. However when I run the debugger on the if visible statement, it says it is still false, despite pressing the space key, which is supposed to set it to true.   EDIT: Ok I got it. I set the value to true in the debugger and it fixed it. Now I can fire the bullet and it shows when I hit the space key. It didn't seem like there was a bug in the code, but guess there was. Now to work on making it so I can fire multiple bullets. bullet.X = player.X; bullet.Y = player.Y; bullet.Visible = false; bullet.Speed = 0.0f; bullet.shape.setPosition(sf::Vector2f(bullet.X,bullet.Y)); bullet.shape.setRadius(10); bullet.shape.setFillColor(sf::Color(255, 0, 0));
  5. Hello, I can't get a bullet to shoot. When I hit the key, nothing happens. I've posted my code. It compiles fine, but nothing happens when I press the space key, which is supposed to fire the bullet. sf::RenderWindow GameWin; sf::Event event; struct PLAYER { sf::RectangleShape shape; sf::Vector2f Pos; float X, Y; }; struct BULLET { sf::CircleShape shape; sf::Vector2f Pos, Vel; float X, Y; float Speed; bool Visible; }; PLAYER player; BULLET bullet; int main(int argc, char* argv[]) { GameWin.create(sf::VideoMode(800, 600, 32), ""); player.X = 800 / 2; player.Y = 600 / 2; player.Pos = sf::Vector2f(player.X, player.Y); player.shape.setPosition(sf::Vector2f(player.Pos)); player.shape.setSize(sf::Vector2f(30, 30)); player.shape.setFillColor(sf::Color(0, 255, 0)); bullet.X = player.X; bullet.Y = player.Y; bullet.Visible = false; bullet.Speed = 0.0f; bullet.Pos = sf::Vector2f(bullet.X, bullet.Y); bullet.shape.setPosition(sf::Vector2f(bullet.Pos)); bullet.shape.setScale(sf::Vector2f(10, 10)); bullet.shape.setFillColor(sf::Color(255, 0, 0)); while (GameWin.isOpen()) { while (GameWin.pollEvent(event)) { if (event.type == sf::Event::Closed) { GameWin.close(); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { bullet.Visible = true; bullet.Speed = 10.0f; } } GameWin.clear(); GameWin.draw(player.shape); if (bullet.Visible) { GameWin.draw(bullet.shape); bullet.shape.move(bullet.Speed, 0); if (bullet.X >= 800) { bullet.Visible = false; } } GameWin.display(); } return 0; }
  6. LeftyGuitar

    Can't get Iterator to work correctly

      I wrote that, because that is the only way it would draw the graphics on the screen. I'm sure there's a better way to do it, but it was a simple solution. I'm actually looking at other code, similar to what I wanna do and I can see what I was doing wrong, so I am working on fixing that.
  7. LeftyGuitar

    Can't get Iterator to work correctly

    The code inside the for loop is supposed to iterate through the bodies. The draw rectangle code for loop is to iterate through the rectangle shapes of course.
  8. LeftyGuitar

    Can't get Iterator to work correctly

    OK I managed to get it to move, but now it just falls to the ground after a couple of bounces. for (vector<sf::RectangleShape>::iterator it = shapes.begin(); it != shapes.end(); it++) { GameWin.draw(*it = box3); } This code actually makes it move. Ok by changing some values I got it to be more active. However I had wanted it to make multiple blocks, right now it only draws one block.
  9. Hello,   I am trying to make it where multiple boxes fall down in a physics simulation. I'm using SFML 2 and Box2D. I managed to get most of it down. However when I run the program, the box just stays up in the air, it doesen't do anything. Any help as to why? Note: That I only have posted the code that I think needs to be looked at. I can post more if it is needed. sf::RectangleShape box3; b2PolygonShape dynamicBox3; b2FixtureDef fixtureDef3; //set up initial variables vector <b2FixtureDef> fixtures; vector <b2Body*> bodies; vector <sf::RectangleShape> shapes; box3.setPosition(sf::Vector2f(100, 5)); box3.setSize(sf::Vector2f(30, 30)); box3.setFillColor(sf::Color(0, 0, 255)); shapes.push_back(box3); bodyDef3.type = b2_dynamicBody; ballVec3.Set(30, 30); bodyDef3.angularVelocity = 0.0f; bodyDef3.linearVelocity = ballVec3; bodyDef3.position.Set(50, 0); bodyDef3.awake = true; Body3 = World->CreateBody(&bodyDef3); dynamicBox3.SetAsBox(10.0f, 10.0f); fixtureDef3.shape = &dynamicBox3; fixtureDef3.density = 2.0f; fixtureDef3.friction = 2.0f; fixtureDef3.restitution = .05f; Body3->CreateFixture(&fixtureDef3); fixtures.push_back(fixtureDef3); bodies.push_back(Body3); //update section for (int i = 0; i < bodies.size(); i++) { b2Vec2 pos3 = bodies[i]->GetPosition(); float angle3 = bodies[i]->GetAngle(); box3.setPosition(pos3.x, pos3.y); box3.setRotation(angle3); } //Drawing section for (vector<sf::RectangleShape>::iterator it = shapes.begin(); it != shapes.end(); it++) { GameWin.draw(*it); }
  10. LeftyGuitar

    Bullet Doesen't Fire Correctly

    Yes of course, next step would be to add basic collision detection.
  11. LeftyGuitar

    Is this idea too offensive ?

    I'm personally not offended by this. However your idea sounds very similar to the games Hatred and Postal.
  12. LeftyGuitar

    Bullet Doesen't Fire Correctly

    I did figure this problem out. I wasn't updating the bullet movement in the correct part of my code. I had to move that code into the update method, I was trying to do it inside the event loop.
  13. I just listented to it. Sounds pretty good. Sounds like something you would hear on NES or SNES. I like it.
  14. LeftyGuitar

    Bullet Doesen't Fire Correctly

    OK, so I re-did the bullet code. However when I press the space key nothing comes up. Not sure if put the code in the wrong place or what. When I press the space key, it should fire a bullet and go off the screen, however, no bullet appears. #include <iostream> #include <vector> #include <SFML\System.hpp> #include <SFML\Graphics.hpp> #define MAX_BULLETS 100 using namespace std; sf::RenderWindow GameWin; sf::Event event; sf::RectangleShape bullet; sf::RectangleShape rect; bool GameRunning = true; bool Fired = false; typedef struct BULLET { float x, y,speed; struct BULLET *next; } BULLET; BULLET* bullets[MAX_BULLETS] = { NULL }; void addBullet(float x, float y, float speed) { int found = -1; for (int i = 0; i < MAX_BULLETS; i++) { if (bullets[i] == NULL) { found = i; break; } } if (found >= 0) { int i = found; bullets[i] = (BULLET*)malloc(sizeof(BULLET)); bullets[i]->x = x; bullets[i]->y = y; bullets[i]->speed = speed; } } void removebullet(int i) { if (bullets[i]) { free(bullets[i]); bullets[i] = NULL; } } int main(int argc, char* argv[]) { GameWin.create(sf::VideoMode(800, 600), "Shooter"); rect.setSize(sf::Vector2f(50, 50)); rect.setPosition(sf::Vector2f(800 / 2, 600 / 2)); rect.setFillColor(sf::Color(255, 0, 0)); while (GameRunning) { while (GameWin.pollEvent(event)) { if (event.type == sf::Event::Closed) { GameRunning = false; GameWin.close(); } if (event.type == sf::Event::KeyPressed) { if (event.key.code == sf::Keyboard::Escape) { GameRunning = false; GameWin.close(); } if (event.type == sf::Keyboard::Space) { addBullet(rect.getPosition().x + 35, rect.getPosition().y + 20, 3); bullet.setFillColor(sf::Color(0, 255, 0)); } } for (int i = 0; i < MAX_BULLETS; i++) if (bullets[i]) { bullets[i]->x += bullets[i]->speed; if (bullets[i]->x < -100 || bullets[i]->x > 100) { removebullet(i); } } } GameWin.clear(); GameWin.draw(rect); for (int i = 0; i < MAX_BULLETS; i++) if (bullets[i]) { bullet.setPosition(sf::Vector2f(bullets[i]->x, bullets[i]->y)); GameWin.draw(bullet); } GameWin.display(); } for (int i = 0; i < MAX_BULLETS; i++) { removebullet(i); } return 0; }
  15. LeftyGuitar

    Bullet Doesen't Fire Correctly

    Well I'm just trying to get it to fire a bullet. Getting it to be able to fire multiple bullets would be nice, but I seem to be having trouble with just firing one bullet. I tried this code, but it still didn't work correctly. The bullet just stays there idle. Is there a better way of making a bullet class or struct? //set initial position of bullet gBullet.x = rect.getPosition().x, gBullet.y = rect.getPosition().y; gBullet.speed = 0.0f; //update the bullet if (Fired == true) { bullet.setSize(sf::Vector2f(10, 10)); bullet.setFillColor(sf::Color(0, 255, 0)); bullet.setPosition(rect.getPosition().x, rect.getPosition().y); gBullet.speed = 30.0f; gBullet.x = gBullet.speed; bullet.move(gBullet.x, 0); } //draw the bullet if (Fired == true) { GameWin.draw(bullet); }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!