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. - #include <SFML/Window.hpp>
-
#include <SFML/Graphics.hpp>
-
-
using namespace std;
-
using namespace sf;
-
-
constexpr int windowWidth{800}, windowHeight{600};
-
constexpr float ballRadius{10.f}, ballVelocity{8.f};
-
-
//constants for the bat;
-
constexpr float batWidth{60.f},batHeight{10.f},batVelocity{6.f};
-
-
struct Bat{
-
//CircleShape is an SFML class that defines a renderable circle
-
RectangleShape shape;
-
//2D vector that stores the Bat's velocity
-
Vector2f velocity;
-
//creating the Bat constructor
-
//argument mX -> starting x coordinate
-
//argument mY -> starting y coordinate
-
Bat(float mX,float mY);
-
{
-
shape.setPosition(mX,mY);
-
shape.setSize(batWidth,batHeight);
-
shape.setFillColor(Color::Red);
-
shape.setOrigin(batWidth/2,batHeight/2);
-
};
-
// Move update
-
void update(){
-
shape.move(velocity);
-
-
if(Keyboard::isKeyPressed(Keyboard::Key::Left) && left() > 0)
-
velocity.x = -batVelocity;
-
else if(Keyboard::isKeyPressed(Keyboard::Key::Right))
-
velocity.x = batVelocity;
-
else
-
velocity.x = 0;
-
}
-
//create property methods to easily get commonly used values
-
float x() { return shape.getPosition().x; }
-
float y() { return shape.getPosition().y; }
-
float left() { return x() - shape.getSize().x/2.f; }
-
float right() { return x() + shape.getSize().x/2.f; }
-
float top() { return y() - shape.getSize().y/2.f; }
-
float bottom() { return y() + shape.getSize().y/2.f; }
-
-
};
-
//creating the template
-
template<class T1, class T2> bool isIntersecting(T1& mA, T2& mB);
-
{
-
mA.right => mB.left()&& mA.left() <= mB.right() && mA.bottom()> =mB.top() <= mB.bottom();
-
-
return;
-
-
}
-
//creating the collision functions
-
void testCollision(Bat mBat, Ball mBall);
-
-
{
-
if(!isIntersecting(mBat, mBall)) return;
-
mBall.Velocity.y = -ballVelocity;
-
-
if(mBall.x()<mBat.x()) mBall.velocity.x = -ballVelocity;
-
else mBall.velocity.x = ballVelocity;
-
};
-
//creating a circle class/struct for the Ball
-
struct Ball
-
{
-
//CircleShape is an SFML class that defines a renderable circle
-
CircleShape shape;
-
-
//2D vector that stores the Ball's velocity
-
Vector2f velocity{-ballVelocity, -ballVelocity};
-
-
//creating the Ball constructor
-
//argument mx -> starting x coordinate
-
//argument my -> starting y coordinate
-
Ball(float mX, float mY)
-
{
-
//apply position, radius, colour and origin to the CircleShape shape
-
shape.setPosition(mX,mY);
-
shape.setRadius(ballRadius);
-
shape.setFillColor(Color::Red);
-
shape.setOrigin(ballRadius, ballRadius);
-
}
-
//Update the ball: by moving is shape by the current velocity
-
void update()
-
{
-
shape.move(velocity);
-
//we need to keep the ball inside the screen
-
//if it is leaving towards the left, we need to set horizontal velocity to a positive
-
//value
-
if(left() < 0) velocity.x = ballVelocity;
-
//otherwise, if it is leaving towards the right, we need to right we need to set
-
// velocity a negative value
-
else if(right() > windowWidth) velocity.x = -ballVelocity;
-
-
//apply the same idea to the top and bottom collisions
-
if(top() < 0) velocity.y = ballVelocity;
-
else if(bottom() > windowHeight) velocity.y = -ballVelocity;
-
}
-
//create property methods to easily get commonly used values
-
float x() {return shape.getPosition().x; }
-
float y() {return shape.getPosition().y; }
-
float left() {return x() - shape.getRadius(); }
-
float right() {return x() + shape.getRadius(); }
-
float top() {return y() - shape.getRadius(); }
-
float bottom() {return y() + shape.getRadius(); }
-
};
-
-
int main()
-
{
-
//create an instance of Ball positioning it at the centre of the window
-
Ball ball(windowWidth / 2, windowHeight / 2);
-
Bat bat(windowWidth / 2, windowHeight - 5);
-
-
//creation of the game window
-
RenderWindow window{{windowWidth, windowHeight}, "Space Pool- 1"};
-
window.setFramerateLimit(60);
-
-
//Game loop
-
while(true)
-
{
-
//clear the window from previously drawn graphics
-
window.clear(Color::Blue);
-
-
//if "Escape" is pressed, break out of the loop
-
if(Keyboard::isKeyPressed(Keyboard::Key::Escape)) break;
-
-
//every loop iteration, we need to update the ball
-
ball.update();
-
bat.update();
-
-
-
//render the Ball instance on the window
-
window.draw(ball.shape);
-
window.draw(bat.shape);
-
-
//Show the window contents
-
window.display();
-
}
-
return 0;
-
}
6 1307
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.
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
On line 21 their is no need of semicolon same goes with line 50 and 59.
OK. You're saying that but when I try to compile it, i'm getting more errors now when I remove the semicolon
Write this program:
Compile it and verify there are no errors.
Then change it to: -
#include <SFML/Window.hpp>
-
#include <SFML/Graphics.hpp>
-
-
using namespace std;
-
using namespace sf;
-
-
int main()
-
{
-
-
}
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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 <%=...
|
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...
|
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...
|
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 ...
|
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"...
|
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...
|
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...
|
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...
|
by: ranaharis |
last post by:
how can i get line number of file where error has occured?
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |