Szary Temat założony przez niniejszego użytkownika |
» 2013-10-04 11:23:30 Ktoś prosił żebym wkleił całość... #pragma once #include <stdlib.h> #include <cstdlib> #include <SFML/Graphics.hpp> #include <SFML/Audio.hpp> #include <SFML/Window.hpp> #include <iostream> #include <string> #include <math.h> #include <cmath> using namespace std; class Graphics { public: double x, y; double fast; int width, height; sf::Sprite sprite; sf::Texture texture; Graphics( const char[], int, int, int, int, double ); Graphics(); ~Graphics( void ); void setGraphic( const char[], int, int, int, int, double ); bool collision( Graphics enemy ); private: };
#include "StdAfx.h" #include "Graphics.h"
Graphics::Graphics( const char file[], int _x, int _y, int _width, int _height, double _fast = 0 ) : x( _x ) , y( _y ) , fast( _fast ) , width( _width ) , height( _height ) { if( texture.loadFromFile( file ) ) { cout << "nie mozna wczytac " << file << endl; return; } sprite.setTexture( texture ); }
Graphics::Graphics() { }
Graphics::~Graphics( void ) { }
bool Graphics::collision( Graphics enemy ) { if( sqrt(( abs( pow( x + width / 2 - enemy.x + enemy.width / 2, 2 ) ) +( abs( pow( y + height / 2 - enemy.y + enemy.width / 2, 2 ) ) ) ) ) <= sqrt(( abs( pow(( width / 2 ) -( enemy.width / 2 ), 2.0 ) ) +( abs( pow(( height / 2 ) -( enemy.width / 2 ), 2.0 ) ) ) ) ) ) return true; return false; }
void Graphics::setGraphic( const char file[], int _x, int _y, int _width, int _height, double _fast = 0 ) { if( !texture.loadFromFile( file ) ) { cout << "nie mozna wczytac " << file << endl; return; } sprite.setTexture( texture ); x = _x; y = _y; height = _height; width = _height; fast = _fast; }
#include "StdAfx.h" #include "Menus.h"
#pragma once #include <iostream> #include <fstream> #include <string> using namespace std;
class Menus { public: int record; Menus( void ); ~Menus( void ); bool Save( int ); int Load(); };
Menus::Menus( void ) { record = Load(); }
Menus::~Menus( void ) { }
bool Menus::Save( int milage ) { ofstream file( "distance.txt" ); if( !file.is_open() ) { return false; } file << milage; cout << "Zapisano do pliku: " << milage << endl; file.close(); return true; }
int Menus::Load() { ifstream file( "distance.txt" ); if( !file.is_open() ) { cout << "Nie udało się otworzyć pliku!" << endl; return 0; } file.clear(); file.seekg( 0, ios::beg ); int milage; file >> milage; cout << "Odczytano z pliku: " << milage << endl; file.close(); return milage; }
#include "stdafx.h" #include <sstream> #include "Graphics.h" #include "Menus.h" using namespace std;
Graphics pigs[ 3 ], ground[ 3 ], sky[ 2 ], player( "graphics/gracz.png", 50, 290, 45, 60, 0 ), menu( "menu.png", 0, 0, 800, 600, 0 ), out( "graphics/exit.jpg", 50, 550, 88, 70, 0 ), start( "graphics/start.jpg", 700, 200, 145, 79, 0 ); Menus file;
int main() { for( int iK = 0; iK < 3; iK++ ) pigs[ iK ].setGraphic( "graphics/swinie.png", rand() % 1000 + 1000, rand() % 350, 60, 60, 0.2 ); ground[ 0 ].setGraphic( "graphics/kafelek.png", 0, 350, 465, 255, 0.1 ); ground[ 1 ].setGraphic( "graphics/kafelek.png", 464, 350, 465, 255, 0.1 ); ground[ 2 ].setGraphic( "graphics/kafelek.png", 928, 350, 465, 255, 0.1 ); sky[ 0 ].setGraphic( "graphics/tlo.png", 0, 0, 800, 357, 0.05 ); sky[ 0 ].setGraphic( "graphics/tlo.png", 800, 0, 800, 357, 0.05 ); int distance = 0; sf::RenderWindow window( sf::VideoMode( 800, 600 ), "GAME" ); menu.sprite.setPosition( sf::Vector2f( menu.x, menu.y ) ); out.sprite.setPosition( sf::Vector2f( out.x, out.y ) ); start.sprite.setPosition( sf::Vector2f( start.x, start.y ) ); while( window.isOpen() ) { sf::Event event; while( window.pollEvent( event ) ) { if( event.type == sf::Event::Closed ) window.close(); else if( event.key.code == sf::Keyboard::Escape && !event.KeyReleased ) window.close(); if( event.type == sf::Event::MouseButtonPressed ) { sf::FloatRect areaStart( start.sprite.getGlobalBounds() ); sf::FloatRect areaOut( out.sprite.getGlobalBounds() ); sf::Vector2f mause( sf::Mouse::getPosition( window ) ); if( areaOut.contains( mause ) ) window.close(); else if( areaStart.contains( mause ) ) { sf::Font font; if( !font.loadFromFile( "graphics/arial.ttf" ) ) return - 1; bool gameOver = false; while( !gameOver ) { window.pollEvent( event ); for( int iK = 0; iK < 3; iK++ ) { gameOver = player.collision( pigs[ iK ] ); } std::ostringstream StrP2; StrP2 << distance / 100; std::string scoreP2( StrP2.str() ); sf::Text text; text.setFont( font ); text.setCharacterSize( 50 ); text.setString( scoreP2 ); for( int iK = 0; iK < 3; iK++ ) { if( pigs[ iK ].x < - 60 ) { pigs[ iK ].x = rand() % 1000 + 1000; pigs[ iK ].y = rand() % 290; } } ground[ 0 ].sprite.setPosition( sf::Vector2f( ground[ 0 ].x, ground[ 0 ].y ) ); ground[ 1 ].sprite.setPosition( sf::Vector2f( ground[ 1 ].x, ground[ 1 ].y ) ); ground[ 2 ].sprite.setPosition( sf::Vector2f( ground[ 2 ].x, ground[ 2 ].y ) ); sky[ 0 ].sprite.setPosition( sf::Vector2f( sky[ 0 ].x, sky[ 0 ].y ) ); sky[ 1 ].sprite.setPosition( sf::Vector2f( sky[ 1 ].x, sky[ 1 ].y ) ); player.sprite.setPosition( sf::Vector2f( player.x, player.y ) ); text.setPosition( 700, 20 ); for( int iK = 0; iK < 3; iK++ ) pigs[ iK ].sprite.setPosition( sf::Vector2f( pigs[ iK ].x, pigs[ iK ].y ) ); if( event.type == sf::Event::Closed ) window.close(); if( event.key.code == sf::Keyboard::Escape && event.KeyPressed ) break; if( event.key.code == sf::Keyboard::Space && player.y > 0 && event.type == event.KeyPressed ) player.y -= player.fast; else if( player.y < 295 && event.type == event.KeyReleased ) player.y += player.fast; window.clear(); window.draw( sky[ 0 ].sprite ); window.draw( sky[ 1 ].sprite ); window.draw( ground[ 0 ].sprite ); window.draw( ground[ 1 ].sprite ); window.draw( ground[ 2 ].sprite ); window.draw( player.sprite ); for( int iK = 0; iK < 3; iK++ ) window.draw( pigs[ iK ].sprite ); window.draw( text ); window.display(); ejl distance++; for( int iK = 0; iK < 3; iK++ ) pigs[ iK ].x -= pigs[ iK ].fast; if( sky[ 1 ].x <= 0 || sky[ 0 ].x <= - 800 ) { sky[ 1 ].x = 800; sky[ 0 ].x = 0; } if( ground[ 0 ].x <= - 464 || ground[ 1 ].x <= 0 || ground[ 2 ].x <= 464 ) { ground[ 0 ].x = 0; ground[ 1 ].x = 464; ground[ 2 ].x = 928; } } } } } window.clear(); window.draw( menu.sprite ); window.draw( start.sprite ); window.draw( out.sprite ); window.display(); } return 0; }
Wklejam te obrazki prawie w każdy folder i nic! Dalej nie może ich znaleźć a ja nie mam pojęcia dlaczego.. pomocy mądry ludu! |