473,386 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Trying to figure out where the error is

4
OK so i'm writing this program for a game we're making in school. I'll send the codes and I would like someone to let me know how i can fix these errors.

Expand|Select|Wrap|Line Numbers
  1. #include <SFML/Window.hpp>
  2. #include <SFML/Graphics.hpp>
  3.  
  4. using namespace std;
  5. using namespace sf;
  6.  
  7. constexpr int windowWidth{800}, windowHeight{600};
  8. constexpr float ballRadius{10.f}, ballVelocity{8.f};
  9.  
  10. //constants for the bat;
  11. constexpr float batWidth{60.f},batHeight{10.f},batVelocity{6.f};
  12.  
  13. struct Bat{
  14.     //CircleShape is an SFML class that defines a renderable circle
  15.     RectangleShape shape;
  16.     //2D vector that stores the Bat's velocity
  17.     Vector2f velocity;
  18.     //creating the Bat constructor
  19.     //argument mX -> starting x coordinate
  20.     //argument mY -> starting y coordinate
  21.     Bat(float mX,float mY);
  22.     {
  23.         shape.setPosition(mX,mY);
  24.         shape.setSize(batWidth,batHeight);
  25.         shape.setFillColor(Color::Red);
  26.         shape.setOrigin(batWidth/2,batHeight/2);
  27.     };
  28. // Move update
  29.     void update(){
  30.         shape.move(velocity);
  31.  
  32.         if(Keyboard::isKeyPressed(Keyboard::Key::Left) && left() > 0)
  33.             velocity.x = -batVelocity;
  34.         else if(Keyboard::isKeyPressed(Keyboard::Key::Right))
  35.             velocity.x = batVelocity;
  36.         else
  37.             velocity.x = 0;
  38.     }
  39. //create property methods to easily get commonly used values
  40.     float x()         { return shape.getPosition().x; }
  41.     float y()         { return shape.getPosition().y; }
  42.     float left()    { return x() - shape.getSize().x/2.f; }
  43.     float right()    { return x() + shape.getSize().x/2.f; }
  44.     float top()        { return y() - shape.getSize().y/2.f; }
  45.     float bottom()    { return y() + shape.getSize().y/2.f; }
  46.  
  47. };
  48. //creating the template
  49. template<class T1, class T2> bool isIntersecting(T1& mA, T2& mB);
  50. {
  51.      mA.right => mB.left()&& mA.left() <= mB.right() && mA.bottom()> =mB.top() <= mB.bottom();
  52.  
  53.     return;
  54.  
  55. }
  56. //creating the collision functions
  57. void testCollision(Bat mBat, Ball mBall);
  58.  
  59. {
  60.     if(!isIntersecting(mBat, mBall)) return;
  61.     mBall.Velocity.y = -ballVelocity;
  62.  
  63.     if(mBall.x()<mBat.x()) mBall.velocity.x = -ballVelocity;
  64.     else mBall.velocity.x = ballVelocity;
  65. };
  66. //creating a circle class/struct for the Ball
  67. struct Ball
  68. {
  69.     //CircleShape is an SFML class that defines a renderable circle
  70.     CircleShape shape;
  71.  
  72.     //2D vector that stores the Ball's velocity
  73.     Vector2f velocity{-ballVelocity, -ballVelocity};
  74.  
  75.     //creating the Ball constructor
  76.     //argument mx -> starting x coordinate
  77.     //argument my -> starting y coordinate
  78.     Ball(float mX, float mY)
  79.     {
  80.         //apply position, radius, colour and origin to the CircleShape  shape
  81.         shape.setPosition(mX,mY);
  82.         shape.setRadius(ballRadius);
  83.         shape.setFillColor(Color::Red);
  84.         shape.setOrigin(ballRadius, ballRadius);
  85.     }
  86.     //Update the ball: by moving is shape by the current velocity
  87.     void update()
  88.     {
  89.         shape.move(velocity);
  90.         //we need to keep the ball inside the screen
  91.         //if it is leaving towards the left, we need to set horizontal velocity to a positive
  92.         //value
  93.         if(left() < 0) velocity.x = ballVelocity;
  94.         //otherwise, if it is leaving towards the right, we need to right we need to set
  95.         // velocity a negative value
  96.         else if(right() > windowWidth) velocity.x = -ballVelocity;
  97.  
  98.         //apply the same idea to the top and bottom collisions
  99.         if(top() < 0) velocity.y = ballVelocity;
  100.         else if(bottom() > windowHeight) velocity.y = -ballVelocity;
  101.     }
  102.     //create property methods to easily get commonly used values
  103.     float x()        {return shape.getPosition().x; }
  104.     float y()        {return shape.getPosition().y; }
  105.     float left()    {return x() - shape.getRadius(); }
  106.     float right()    {return x() + shape.getRadius(); }
  107.     float top()        {return y() - shape.getRadius(); }
  108.     float bottom()    {return y() + shape.getRadius(); }
  109. };
  110.  
  111. int main()
  112. {
  113.     //create an instance of Ball positioning it at the centre of the window
  114.     Ball ball(windowWidth / 2, windowHeight / 2);
  115.     Bat bat(windowWidth / 2, windowHeight - 5);
  116.  
  117.     //creation of the game window
  118.     RenderWindow window{{windowWidth, windowHeight}, "Space Pool- 1"};
  119.     window.setFramerateLimit(60);
  120.  
  121.     //Game loop
  122.     while(true)
  123.     {
  124.         //clear the window from previously drawn graphics
  125.         window.clear(Color::Blue);
  126.  
  127.         //if "Escape" is pressed, break out of the loop
  128.         if(Keyboard::isKeyPressed(Keyboard::Key::Escape)) break;
  129.  
  130.         //every loop iteration, we need to update the ball
  131.         ball.update();
  132.         bat.update();
  133.  
  134.  
  135.         //render the Ball instance on the window
  136.         window.draw(ball.shape);
  137.         window.draw(bat.shape);
  138.  
  139.         //Show the window contents
  140.         window.display();
  141.     }
  142.     return 0;
  143. }
May 4 '14 #1
6 1307
weaknessforcats
9,208 Expert Mod 8TB
What errors are you speaking of? Debugging compiler and run-time errors is a skill each person needs to develop. Therefore, I usually don't just jump in and fix your code but I will help you if you steer me a little.
May 4 '14 #2
Knobs
4
I'm using code blocks 13.12
When i try compile it i'm getting this error: expected unqualified-id before '{' token. on lines 22,50 and 59
May 4 '14 #3
techboy
28
On line 21 their is no need of semicolon same goes with line 50 and 59.
May 5 '14 #4
Knobs
4
OK. You're saying that but when I try to compile it, i'm getting more errors now when I remove the semicolon
May 5 '14 #5
weaknessforcats
9,208 Expert Mod 8TB
Write this program:

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.  
  4. }
Compile it and verify there are no errors.

Then change it to:
Expand|Select|Wrap|Line Numbers
  1. #include <SFML/Window.hpp>
  2. #include <SFML/Graphics.hpp>
  3.  
  4.  using namespace std;
  5.  using namespace sf;
  6.  
  7. int main()
  8. {
  9.  
  10. }
Now compile it again and verify there are no errors.

Add your struct declarations. Recompile and verify there are no errors.

Repeat this over and over each time adding code and each time compiling an verifying there are no errors.

Writing 10,000 lines of code and then trying to compile won't work. Been there. Done that.
May 6 '14 #6
Knobs
4
OK Thanks I'll try that.
May 6 '14 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tom Petersen | last post by:
I am trying figure this out, I am using the example from aspfaq dot com <% If not objRS.EOF then DO WHILE NOT objRS.EOF %> <p align="left"><font face="Arial" size="1">Posted by <%=...
2
by: Jack | last post by:
The following is the error: Error Type: Microsoft JET Database Engine (0x80040E14) Syntax error (missing operator) in query expression 'ApplicantIntID ='. /subgrantapptest/ListSaved.asp, line...
5
by: Mark Kamoski | last post by:
Hi Everyone-- How can one get the line number of where an error was thrown and/or caught? For example, note the following, for use at any given point in a piece of code: ....to get the...
8
by: deercreek | last post by:
I have the following table test3. RESERVATIONID Site SitePrice 101 RV2 $25.00 101 RV3 $25.00 102 RV4 $25.00 102 RV5 $25.00 104 ...
3
by: Chris_147 | last post by:
but it seems to depend on from where I start the Python shell. so I've got a module selfservicelabels.py with some variables defined, like this: BtnSave = "link=label.save"...
1
by: =?Utf-8?B?U3VzYW4=?= | last post by:
I am in the process of upgrading my application to Visual Studio 2005 and the ..Net 2.0 Framework. When I run my application in Debug, I get several hundred lines of the following message in the...
1
by: AccessHunter | last post by:
Hi, I am trying to run the following query, is giving me an error saying "missing right paranthesis" on the line where the SWITCH is. I couldn't figure out error, please help. Please treat this a...
1
by: xhunter | last post by:
I have been working on this for some time and I came to the conclusion that I have no idea what is the problem, I am sure it should be something simple that I am overlooking, but I can't figure...
1
by: ranaharis | last post by:
how can i get line number of file where error has occured?
2
by: tvnaidu | last post by:
Downloaded PowerPC cross compiler tool chain for LINUX, trying to compile C / CPP file, I am getting "Floating Point exception" to compile any file, no problem with regular GCC. any idea why I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.