• Advertisement
Sign in to follow this  

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

This topic is 1972 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:

#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;
};

Paddle Class Source:

#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();
}

Main(Testing the Paddle Class out):

// 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;
}

It gives me an error message for:

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

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
Advertisement
How can I compile both of them by themselves? (#I'mANoob)

--------EDIT: FIXED------
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
Sign in to follow this  

  • Advertisement