Sign in to follow this  

Yes, I'm still trying to make pong, and yes, I do have another bug.

This topic is 1904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here's the code:
Paddle Class Header:
[CODE]
#include <SFML/Graphics.hpp>
class Paddle
{
public:
void Draw(sf::RenderWindow Window);
void Update(sf::RenderWindow Window);
void Initialize(float speedx, bool isplayercontrolled, sf::Image Image);
private:
sf::FloatRect Collision;
sf::Image PaddleImage;
sf::Sprite PaddleSprite;
bool HasAI;
float speedx;
};
[/CODE]
Paddle Class Source:
[CODE]
#pragma once
#include <SFML/Graphics.hpp>
#include "Paddle.h"
void Paddle::Initialize(float speedx, bool isplayercontrolled, sf::Image Image)
{
this->speedx = speedx;
this->HasAI = isplayercontrolled;
this->PaddleImage = Image;
PaddleSprite.SetImage(Image);
}
void Paddle::Draw(sf::RenderWindow Window)
{
Window.Draw(PaddleSprite);
return;
}
void Paddle::Update(sf::RenderWindow Window)
{
if (sf::Key::Left) PaddleSprite.Move(-speedx * Window.GetFrameTime(), 0);
else if (sf::Key::Right) PaddleSprite.Move(speedx * Window.GetFrameTime(), 0);
Collision.Top = PaddleSprite.GetPosition().y;
Collision.Left = PaddleSprite.GetPosition().x;
Collision.Bottom = Collision.Top + PaddleImage.GetHeight();
Collision.Right = Collision.Left + PaddleImage.GetWidth();
}
[/CODE]
Main(Testing the Paddle Class out):
[CODE]
// Pong.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <SFML/Graphics.hpp>
#include "Paddle.cpp"

int _tmain(int argc, _TCHAR* argv[])
{
sf::RenderWindow App(sf::VideoMode(800,600,32), "Pong");
App.SetFramerateLimit(30);
Paddle Paddle1;
sf::Image Image1;
bool AI = false;
Paddle1.Initialize(200, AI, Image1);

while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
Paddle1.Update(App);
Paddle1.Draw(App);
App.Clear();
App.Display();
}
return 0;
}
[/CODE]
It gives me an error message for:
[CODE]
1>------ Build started: Project: Pong, Configuration: Debug Win32 ------
1> stdafx.cpp
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(6): error C2653: 'Paddle' : is not a class or namespace name
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(8): error C2355: 'this' : can only be referenced inside non-static member functions
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(8): error C2227: left of '->speedx' must point to class/struct/union/generic type
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(9): error C2355: 'this' : can only be referenced inside non-static member functions
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(9): error C2227: left of '->HasAI' must point to class/struct/union/generic type
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(10): error C2355: 'this' : can only be referenced inside non-static member functions
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(10): error C2227: left of '->PaddleImage' must point to class/struct/union/generic type
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(11): error C2065: 'PaddleSprite' : undeclared identifier
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(11): error C2228: left of '.SetImage' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(14): error C2653: 'Paddle' : is not a class or namespace name
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(16): error C2065: 'PaddleSprite' : undeclared identifier
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(20): error C2653: 'Paddle' : is not a class or namespace name
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(22): error C2065: 'PaddleSprite' : undeclared identifier
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(22): error C2228: left of '.Move' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(23): error C2065: 'PaddleSprite' : undeclared identifier
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(23): error C2228: left of '.Move' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(24): error C2065: 'Collision' : undeclared identifier
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(24): error C2228: left of '.Top' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(24): error C2065: 'PaddleSprite' : undeclared identifier
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(24): error C2228: left of '.GetPosition' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(24): error C2228: left of '.y' must have class/struct/union
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(25): error C2065: 'Collision' : undeclared identifier
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(25): error C2228: left of '.Left' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(25): error C2065: 'PaddleSprite' : undeclared identifier
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(25): error C2228: left of '.GetPosition' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(25): error C2228: left of '.x' must have class/struct/union
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(26): error C2065: 'Collision' : undeclared identifier
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(26): error C2228: left of '.Bottom' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(26): error C2065: 'Collision' : undeclared identifier
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(26): error C2228: left of '.Top' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(26): error C2228: left of '.GetHeight' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(27): error C2065: 'Collision' : undeclared identifier
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(27): error C2228: left of '.Right' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(27): error C2065: 'Collision' : undeclared identifier
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(27): error C2228: left of '.Left' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\tom\documents\visual studio 2010\projects\pong\paddle.cpp(27): error C2228: left of '.GetWidth' must have class/struct/union
1> type is ''unknown-type''
[/CODE]
What is going on? it gives me an error on every line of code for .cpp all saying THE EXACT SAME THING: .(Name of Function) Must Have a Class/Struct/Union? WTF!

Share this post


Link to post
Share on other sites
How can I compile both of them by themselves? (#I'mANoob)
[size=6]--------EDIT: FIXED------[/size]
Okay, so the problem turned out to be me including the .cpp instead of the .h, and I had to change from passing sf::RenderWindow as a value to passing it as a reference because of sf::NonCopyable. But overall, it's fixed. Edited by superman3275

Share this post


Link to post
Share on other sites

This topic is 1904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this