|
You last visited: Today at 15:55
Advertisement
[benötige Hilfe]Spiel Programmieren
Discussion on [benötige Hilfe]Spiel Programmieren within the C/C++ forum part of the Coders Den category.
12/21/2013, 22:53
|
#1
|
elite*gold: 29
Join Date: Aug 2011
Posts: 640
Received Thanks: 493
|
[benötige Hilfe]Spiel Programmieren
Hallo liebe Community
und zwar habe ich eine Frage ich möchte eiin Spiel ertstellen aber wenn ich
diesen Quelltext/Sourcecode ausühre:
(Ist nicht die Main Funktion)
PHP Code:
void Start_Spiel()
{
HWND console_window = GetConsoleWindow();
SetWindowPos(console_window,0,0,0,100,100,SWP_HIDEWINDOW);
sf::RenderWindow window(sf::VideoMode(800,600), "Super Mario Land II");
sf::Texture Mariotextur;
Mariotextur.loadFromFile("Mario.png");
sf::Sprite Mariosprite(Mariotextur);
SetWindowPos(console_window,0,100,100,800,340,SWP_SHOWWINDOW);
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.display();
}
}
Hier ist die Main Funktion
PHP Code:
int main(int argc, char **argv)
{
int tmp;
char Auswahl;
bool running = true;
do
{
std::cout << "====================================|-----|=====================================";
std::cout << "====================================|Spiel|=====================================";
std::cout << "====================================|-----|=====================================";
std::cout << "======================= [S]piel Starten" << " ===========================";
std::cout << "======================= [A]nleitung" << " ===========================";
std::cout << "======================= [C]redits" << " ===========================";
std::cout << "======================= [V]erlassen" << " ===========================";
std::cout << "================================================================================";
std::cout << "================================================================================";
std::cout << "\n";
std::cout << "Herzlich Willkommen zu unserem Projekt, welches wir heute vorstellen moechten. ";
std::cout << "Diese Anwendung die ihr hier sieht, ist ein mit C++ geschriebenes Menue welches ";
std::cout << "folgende Funkionen besitzt:" << std::endl;
std::cout << "\n";
std::cout << "|[S]piel Starten|-- Bei dieser Funktion wird das Spiel gestartet. ";
std::cout << "\n";
std::cout << "|[A]nleitung|-- Bei der Funktion bekommt ihr eine genauere Beschreibung des ";
std::cout << "Spielablaufes und der Steuerung." << std::endl;
std::cout << "\n";
std::cout << "|[C]redits|-- Hier werden alle Mitwirkende, die an diesem Projekt mitgearbeitet ";
std::cout << "haben, aufgelistet." << std::endl;
std::cout << "\n";
std::cout << "|[V]erlassen|-- Das (Konsolen)fenster wird geschlossen; Sie verlassen das Spiel ";
std::cout << "\n";
std::cout << "Deine Eingabe:"; std::cin >> Auswahl;
switch(Auswahl)
{
case ('s'): case('S'):
std::cout << "\n";
Start_Spiel();
system("Cls");
break;
case ('a'): case ('A'):
std::cout << "\n";
Anleitung();
system("Cls");
break;
case ('c'): case ('C'):
std::cout << "\n";
Credits();
system("Cls");
break;
case ('v'): case ('V'):
return 0;
break;
default:
std::cout << "\n";
std::cout <<"Ungueltige Eingabe\n";
std::cout << "\n";
std::cout <<"Bitte geben sie den vorgegebenen Buchstaben ein um eine Funktion nutzten\n" << "zu können!\n";
system("Cls");
}
}while(running);
std::cin >> tmp;
return 0;
}
kommt folgender Fehler heraus:
| Eine Ausnahme (erste Chance) bei 0x6ec11f34 (msvcr100.dll) in GRW Spieleprogrammierung.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x003e1000. | | Unbehandelte Ausnahme bei 0x6ec11f34 (msvcr100.dll) in GRW Spieleprogrammierung.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x003e1000. |
Und da wollte ich fragen was sich da machen lässt hoffe ihr könnt mir da helfen.
|
|
|
12/22/2013, 05:04
|
#2
|
elite*gold: 0
Join Date: Feb 2011
Posts: 1,206
Received Thanks: 736
|
dafür gibt es den debugger...
|
|
|
12/26/2013, 17:37
|
#3
|
elite*gold: 29
Join Date: Aug 2011
Posts: 640
Received Thanks: 493
|
Edit : Oben hat sich das geklärt
Aber ich brauch noch einmal Hilfe und zwar möchte ich mit Mario wenn ich sund(Pfeiltaste)rechts drückt(und auch links), dass er schneller läuft.Hier das Script:
PHP Code:
#include <iostream> #include <string> #include <Windows.h> #include <SFML/Graphics.hpp> #include <SFML/Audio.hpp> #include <SFML/Window.hpp>
using namespace sf;
float offsetX=0, offsetY=0;
const int H = 19; const int W = 150;
String TileMap[H] = { "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "0 0", "0 0", "0 0", "0 0", "0 0", "0 0", "0 0", "0 0", "0 0", "0 0", "0 0", "0 0", "0 0", "0 0", "0 0", "0 0", "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP", "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP", };
class PLAYER { public: float dx,dy;
FloatRect rect; bool onGround; Sprite sprite; float currentFrame;
PLAYER(Texture &image) { sprite.setTexture(image); rect = FloatRect(40,255,16,16);
dx=dy=0.1; currentFrame = 0; }
void update(float time) {
rect.left += dx * time; Collision(0);
if (!onGround) dy=dy+0.0005*time; rect.top += dy*time; onGround=false; Collision(1);
currentFrame += time * 0.005; if (currentFrame > 3) currentFrame -= 3;
if (dx>0) sprite.setTextureRect(IntRect(112+31*int(currentFrame),144,16,16)); if (dx<0) sprite.setTextureRect(IntRect(112+31*int(currentFrame)+16,144,-16,16));
sprite.setPosition(rect.left - offsetX, rect.top - offsetY); dx=0; }
void Collision(int num) { for (int i = rect.top/16 ; i<(rect.top+rect.height)/16; i++) for (int j = rect.left/16; j<(rect.left+rect.width)/16; j++) { if ((TileMap[i][j]=='P') || (TileMap[i][j]=='k') || (TileMap[i][j]=='0') || (TileMap[i][j]=='r') || (TileMap[i][j]=='t')) { if (dy>0 && num==1) { rect.top = i*16 - rect.height; dy=0; onGround=true; } if (dy<0 && num==1) { rect.top = i*16 + 16; dy=0;} if (dx>0 && num==0) { rect.left = j*16 - rect.width; } if (dx<0 && num==0) { rect.left = j*16 +16;} }
if (TileMap[i][j]=='c') { //Nicht ferig -> Coins oder Pilz überprüfung und falscher Code |>^<| if (dy>0 && num==1) { rect.top = i*16 - rect.height; dy=0; onGround=true; } if (dy<0 && num==1) { rect.top = i*16 + 16; dy=0;} if (dx>0 && num==0) { rect.left = j*16 - rect.width; } if (dx<0 && num==0) { rect.left = j*16 +16;} //Ende } }
}
};
class ENEMY {
public: float dx,dy; FloatRect rect; Sprite sprite; float currentFrame; bool life;
void set(Texture &image, int x, int y) { sprite.setTexture(image); rect = FloatRect(820,255,16,16);
dx=0.05; currentFrame = 0; life=true; }
void update(float time) { rect.left += dx * time; Collision();
currentFrame += time * 0.005; if (currentFrame > 2) currentFrame -= 2;
sprite.setTextureRect(IntRect(18*int(currentFrame), 0, 16,16)); if (!life)sprite.setTextureRect(IntRect(58, 0, 16,16)); sprite.setPosition(rect.left - offsetX, rect.top - offsetY); }
void Collision() {
for (int i = rect.top/16 ; i<(rect.top+rect.height)/16; i++) for (int j = rect.left/16; j<(rect.left+rect.width)/16; j++) if ((TileMap[i][j]=='P') || (TileMap[i][j]=='0')) { if (dx>0) { rect.left = j*16 - rect.width; dx*=-1; } else if (dx<0) { rect.left = j*16 + 16; dx*=-1; } } }
};
int main() {
RenderWindow window(VideoMode(500, 300), "Super Mario Land II");
Texture tileSet; //Texture Tileset; tileSet.loadFromFile("Mario_Tileset.png"); //Tileset.loadFromFile("Mario_tileset_end.jpeg"); PLAYER Mario(tileSet); ENEMY enemy; enemy.set(tileSet,48*16,13*16);
Sprite tile(tileSet); //Sprite tilem(Tileset);
SoundBuffer buffer; buffer.loadFromFile("Mario_Jump.ogg"); Sound sound(buffer); sound.setVolume(20);
Music music; music.openFromFile("Mario_Theme.ogg"); music.play(); music.setVolume(40); music.setLoop(true);
Clock clock;
while (window.isOpen()) { float time = clock.getElapsedTime().asMicroseconds(); clock.restart();
time = time/500;
if (time > 20) time = 20;
Event event; while (window.pollEvent(event)) { if (event.type == Event::Closed) window.close(); }
if (Keyboard::isKeyPressed(Keyboard::Left)) Mario.dx=-0.1; if (Keyboard::isKeyPressed(Keyboard::Right)) Mario.dx=0.1; if (Keyboard::isKeyPressed(Keyboard::Up)) if (Mario.onGround) { Mario.dy=-0.27; Mario.onGround=false; sound.play();}
if ((Keyboard::isKeyPressed(Keyboard::S)) && ((Keyboard::isKeyPressed(Keyboard::Right)))) { for(Mario.dx = 0; Mario.dx >= 0.3; 0.1+0.1+0.1) //Mario Rennen { } }
if ((Keyboard::isKeyPressed(Keyboard::S)) && ((Keyboard::isKeyPressed(Keyboard::Left)))) //Mario Rennen { for(Mario.dx = 0; Mario.dx <= -0.3; -0.1-0.1-0.1) { } }
Mario.update(time); enemy.update(time);
if (Mario.rect.intersects( enemy.rect ) ) { if (enemy.life) { if (Mario.dy>0) { enemy.dx=0; Mario.dy=-0.2; enemy.life=false;} else Mario.sprite.setColor(Color::Red); } }
if (Mario.rect.left>200) offsetX = Mario.rect.left-200;
window.clear(Color(92,148,252));
for (int i=0; i<H; i++) for (int j=0; j<W; j++) { if (TileMap[i][j]=='P') tile.setTextureRect( IntRect(143-16*3,112,16,16) ); //brauner Grundboden
if (TileMap[i][j]=='k') tile.setTextureRect( IntRect(143,112,16,16) ); //normaler Gelber Stein(Schornstein) if (TileMap[i][j]=='c') tile.setTextureRect( IntRect(143-16,112,16,16) ); //(?)Fragezeichen Itemstein
if (TileMap[i][j]=='t') tile.setTextureRect( IntRect(0,47,32,48) ); //normales Rohr
if (TileMap[i][j]=='g') tile.setTextureRect( IntRect(0,16*9-5,3*16,37) ); //kleiner Hügel
if (TileMap[i][j]=='G') tile.setTextureRect( IntRect(145,222,222-145,255-222) ); //großer Hügel
if (TileMap[i][j]=='d') tile.setTextureRect( IntRect(0,106,74,127-106) ); //3 Busch Hügel
if (TileMap[i][j]=='w') tile.setTextureRect( IntRect(99,224,140-99,255-224) ); //1 Wolke
if (TileMap[i][j]=='r') tile.setTextureRect( IntRect(143-32,112,16,16) ); //Ein brauner quadratischer Stein
if (TileMap[i][j]=='q') tile.setTextureRect( IntRect(0,222,90,35) ); //3 Wolken
if (TileMap[i][j]=='e') tile.setTextureRect( IntRect(50,55,45,45) ); //1 Busch Hügel
if (TileMap[i][j]=='z') tile.setTextureRect( IntRect(95,5,107,107) ); //End Level Burg
if (TileMap[i][j]=='u') tile.setTextureRect( IntRect(95,128,16,16) ); //blauer Grundboden
if (TileMap[i][j]=='i') tile.setTextureRect( IntRect(143-32,128,16,16) ); //ein blauer quadratischer Stein
if (TileMap[i][j]=='o') tile.setTextureRect( IntRect(143,128,16,16) ); //normaler blauer Stein(Schornstein)
if (TileMap[i][j]=='p') tile.setTextureRect( IntRect(160,123,64,20) ); //2 Busch Hügel
if (TileMap[i][j]=='a') tile.setTextureRect( IntRect(63,145,12,16) ); //kleines Büschlein (am Ende des Levls an der Burg)
if (TileMap[i][j]=='s') tile.setTextureRect( IntRect(0,176,78,32) ); //2 teiliges Rohr
if (TileMap[i][j]=='f') tile.setTextureRect( IntRect(95,160,66,32) ); //2 Wolken
if (TileMap[i][j]=='h') tile.setTextureRect( IntRect(175,192,49,17) ); //(bewegliche/)Plattform
if (TileMap[i][j]=='j') tile.setTextureRect( IntRect(224,176,24,32) ); // Boden mit Wasser
if (TileMap[i][j]=='l') tile.setTextureRect( IntRect(224,176,16,16) ); //Wasser
if (TileMap[i][j]=='m') tile.setTextureRect( IntRect(239,240,17,16) ); //"Brücke"
//if (TileMap[i][j]=='n') tilem.setTextureRect( IntRect(200,5,40,100) ); //Fahnenstangen am Ende des Levels
if ((TileMap[i][j]==' ') || (TileMap[i][j]=='0')) continue;
tile.setPosition(j*16 - offsetX,i*16 - offsetY) ; //tilem.setPosition(j*16 - offsetX,i*16 - offsetY); window.draw(tile); } //window.draw(tilem);
window.draw(Mario.sprite); window.draw(enemy.sprite);
window.display(); }
return 0; }
Dann kommt diese Fehler Meldung :
Code:
1>------ Erstellen gestartet: Projekt: GRW Spiel Projekt, Konfiguration: Debug Win32 ------
1> C:\Users\Privat\Desktop\SFML-2.1\bin\libsndfile-1.dll
1> C:\Users\Privat\Desktop\SFML-2.1\bin\openal32.dll
1> C:\Users\Privat\Desktop\SFML-2.1\bin\sfml-audio-2.dll
1> C:\Users\Privat\Desktop\SFML-2.1\bin\sfml-audio-d-2.dll
1> C:\Users\Privat\Desktop\SFML-2.1\bin\sfml-graphics-2.dll
1> C:\Users\Privat\Desktop\SFML-2.1\bin\sfml-graphics-d-2.dll
1> C:\Users\Privat\Desktop\SFML-2.1\bin\sfml-network-2.dll
1> C:\Users\Privat\Desktop\SFML-2.1\bin\sfml-network-d-2.dll
1> C:\Users\Privat\Desktop\SFML-2.1\bin\sfml-system-2.dll
1> C:\Users\Privat\Desktop\SFML-2.1\bin\sfml-system-d-2.dll
1> C:\Users\Privat\Desktop\SFML-2.1\bin\sfml-window-2.dll
1> C:\Users\Privat\Desktop\SFML-2.1\bin\sfml-window-d-2.dll
1> 12 Datei(en) kopiert.
1> main.cpp
1>c:\users\privat\desktop\spiel c++\grw projekt\grw spiel projekt\grw spiel projekt\main.cpp(64): warning C4244: '=': Konvertierung von 'double' in 'float', möglicher Datenverlust
1>c:\users\privat\desktop\spiel c++\grw projekt\grw spiel projekt\grw spiel projekt\main.cpp(70): warning C4244: '+=': Konvertierung von 'double' in 'float', möglicher Datenverlust
1>c:\users\privat\desktop\spiel c++\grw projekt\grw spiel projekt\grw spiel projekt\main.cpp(87): warning C4244: 'Initialisierung': Konvertierung von 'float' in 'int', möglicher Datenverlust
1>c:\users\privat\desktop\spiel c++\grw projekt\grw spiel projekt\grw spiel projekt\main.cpp(88): warning C4244: 'Initialisierung': Konvertierung von 'float' in 'int', möglicher Datenverlust
1>c:\users\privat\desktop\spiel c++\grw projekt\grw spiel projekt\grw spiel projekt\main.cpp(95): warning C4244: '=': Konvertierung von 'int' in 'float', möglicher Datenverlust
1>c:\users\privat\desktop\spiel c++\grw projekt\grw spiel projekt\grw spiel projekt\main.cpp(99): warning C4244: '=': Konvertierung von 'int' in 'float', möglicher Datenverlust
1>c:\users\privat\desktop\spiel c++\grw projekt\grw spiel projekt\grw spiel projekt\main.cpp(108): warning C4244: '=': Konvertierung von 'int' in 'float', möglicher Datenverlust
1>c:\users\privat\desktop\spiel c++\grw projekt\grw spiel projekt\grw spiel projekt\main.cpp(112): warning C4244: '=': Konvertierung von 'int' in 'float', möglicher Datenverlust
1>c:\users\privat\desktop\spiel c++\grw projekt\grw spiel projekt\grw spiel projekt\main.cpp(149): warning C4244: '+=': Konvertierung von 'double' in 'float', möglicher Datenverlust
1>c:\users\privat\desktop\spiel c++\grw projekt\grw spiel projekt\grw spiel projekt\main.cpp(161): warning C4244: 'Initialisierung': Konvertierung von 'float' in 'int', möglicher Datenverlust
1>c:\users\privat\desktop\spiel c++\grw projekt\grw spiel projekt\grw spiel projekt\main.cpp(162): warning C4244: 'Initialisierung': Konvertierung von 'float' in 'int', möglicher Datenverlust
1>c:\users\privat\desktop\spiel c++\grw projekt\grw spiel projekt\grw spiel projekt\main.cpp(168): warning C4244: '=': Konvertierung von 'int' in 'float', möglicher Datenverlust
1>c:\users\privat\desktop\spiel c++\grw projekt\grw spiel projekt\grw spiel projekt\main.cpp(210): warning C4244: 'Initialisierung': Konvertierung von 'sf::Int64' in 'float', möglicher Datenverlust
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(113): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1> c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(109): Bei der Kompilierung der Klassen-template der bool sf::Rect<T>::intersects(const sf::Rect<T> &,sf::Rect<T> &) const-Memberfunktion
1> with
1> [
1> T=float
1> ]
1> c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(39): Bei der Kompilierung der Klassen-template der sf::Rect<T>::Rect(T,T,T,T)-Memberfunktion
1> with
1> [
1> T=float
1> ]
1> c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\view.hpp(275): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "sf::Rect<T>".
1> with
1> [
1> T=float
1> ]
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(113): error C2059: Syntaxfehler: '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(114): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(114): error C2059: Syntaxfehler: '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(115): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(115): error C2059: Syntaxfehler: '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(116): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(116): error C2059: Syntaxfehler: '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(119): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(119): error C2059: Syntaxfehler: '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(120): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(120): error C2059: Syntaxfehler: '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(121): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(121): error C2059: Syntaxfehler: '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(122): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(122): error C2059: Syntaxfehler: '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(125): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(125): error C2059: Syntaxfehler: '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(126): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(126): error C2059: Syntaxfehler: '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(127): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(127): error C2059: Syntaxfehler: '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(128): error C2589: '(': Ungültiges Token auf der rechten Seite von '::'
1>c:\users\privat\desktop\sfml-2.1\include\sfml\graphics\rect.inl(128): error C2059: Syntaxfehler: '::'
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
Was ist da falsch bei mir denn ich kann keine mehrzeligen Verzweigungen mehr machen. Bitte helft mir .
|
|
|
12/26/2013, 18:06
|
#4
|
elite*gold: 0
Join Date: Feb 2011
Posts: 1,206
Received Thanks: 736
|
sind wir hier neuerdings dein persönlicher debugger oder was?
räum mal dein projekt auf und lern mit der IDE umzugehen, wir machen das hier net für dich.
|
|
|
01/01/2014, 16:32
|
#5
|
elite*gold: 29
Join Date: Aug 2011
Posts: 640
Received Thanks: 493
|
Hallo liebe Community
und zwar habe ich vollgende Frage ich möchte ein Mario Game programmieren nun bin ich bei den Kollisionen verschiedener Tiles da Mario wenn er in einen Graben fällt sterben soll / bzw. ein Leben verlieren soll und nicht dauraus springt und weiter läut hab ich die Frage wie es funktioniert denn ich versuche auch, das zum Beispiel wenn er in den Graben fällt die Musik(Theme music) aufhört zu spielen und die loose life music spielt aber bei mir macht er nicht sondern spielt die normale theme music weiter ab. Hoffe ihr könnt mir helfen.
Hier ist das Script:
PHP Code:
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#include <Windows.h>
using namespace sf;
float offsetX = 0, offsetY = 0;
const int H = 20;
const int W = 150;
String TileMap[H] = {
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"0 0",
"0 0",
"0 w w 0",
"0 w f 0",
"0 w q f 0",
"0 w 0",
"0 w w 0",
"0 f 0",
"0 c 0",
"0 0",
"0 0",
"0 c c c 0",
"0 c kckck t0 t0 c kkk t0 0",
"0 t0 00 00 t0 00 0",
"0G t0 00 bvG bv 00 bv 0",
"0 d g e 00 bv p bv bv d g e d bv e bv g 0",
"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP",
"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP11PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP111PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP",
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
};
class PLAYER {
public:
float dx, dy;
FloatRect rect;
bool onGround;
Sprite sprite;
float currentFrame;
PLAYER(Texture &image)
{
sprite.setTexture(image);
rect = FloatRect(40, 255, 16, 16); //Spawn Position (Mario)
dx = dy = 0.1;
currentFrame = 0;
}
void update(float time)
{
rect.left += dx * time;
Collision(0);
if (!onGround) dy = dy + 0.0005*time;
rect.top += dy*time;
onGround = false;
Collision(1);
currentFrame += time * 0.005;
if (currentFrame > 3) currentFrame -= 3;
if ((Keyboard::isKeyPressed(Keyboard::Left)) || (Keyboard::isKeyPressed(Keyboard::Right)) || (Keyboard::isKeyPressed(Keyboard::Up)))
{
if (dx>0){ sprite.setTextureRect(IntRect(112 + 31 * int(currentFrame), 144, 16, 16)); }
if (dx<0){ sprite.setTextureRect(IntRect(112 + 31 * int(currentFrame) + 16, 144, -16, 16)); }
if (Keyboard::isKeyPressed(Keyboard::Up))
{
sprite.setTextureRect(IntRect(112 + 31 * 4 - 5, 144, 16, 16));
}
}
else
{
sprite.setTextureRect(IntRect(112 - 31, 144, 16, 16));
}
sprite.setPosition(rect.left - offsetX, rect.top - offsetY);
dx = 0;
}
void Collision(int num)
{
for (int i = rect.top / 16; i<(rect.top + rect.height) / 16; i++)
for (int j = rect.left / 16; j<(rect.left + rect.width) / 16; j++)
{
if ((TileMap[i][j] == 'P') || (TileMap[i][j] == 'k') || (TileMap[i][j] == '0') || (TileMap[i][j] == 'r') || (TileMap[i][j] == 't') || (TileMap[i][j] == 'u') || (TileMap[i][j] == 'i') || (TileMap[i][j] == 'o') || (TileMap[i][j] == 's') || (TileMap[i][j] == 'h') || (TileMap[i][j] == 'm') || (TileMap[i][j] == 'b') || (TileMap[i][j] == 'v'))
{
if (dy>0 && num == 1)
{
rect.top = i * 16 - rect.height; dy = 0; onGround = true;
}
if (dy<0 && num == 1)
{
rect.top = i * 16 + 16; dy = 0;
}
if (dx>0 && num == 0)
{
rect.left = j * 16 - rect.width;
}
if (dx<0 && num == 0)
{
rect.left = j * 16 + 16;
}
}
if (TileMap[i][j] == 'c')
{
//Nicht ferig -> Coins oder Pilz überprüfung und falscher Code |>^<|
if (dy>0 && num == 1)
{
rect.top = i * 16 - rect.height; dy = 0; onGround = true;
}
if (dy<0 && num == 1)
{
rect.top = i * 16 + 16; dy = 0;
}
if (dx>0 && num == 0)
{
rect.left = j * 16 - rect.width;
}
if (dx<0 && num == 0)
{
rect.left = j * 16 + 16;
}
//Ende
}
if (TileMap[i][j] == '1')//Hier beginnt die Kollision
{
if (dy>0 && num == 0)
{
Music music;//standard theme music
music.setLoop(false);schleife wird auf alse gesetzt
music.pause();//und wird dann pausiert
SoundBuffer Buffer;////mario_die music
Buffer.loadFromFile("Mario_die.ogg");
Sound ssound(Buffer);
ssound.play();//Hier sollte es abgespielt werden tut es aber nicht :(
}
}//Hier endet sie
}
}
};
class ENEMY
{
public:
float dx, dy;
FloatRect rect;
Sprite sprite;
float currentFrame;
bool life;
void set(Texture &image, int x, int y)
{
sprite.setTexture(image);
rect = FloatRect(820, 255, 16, 16);//spawn Position(Enemy)
dx = 0.05;
currentFrame = 0;
life = true;
}
void update(float time)
{
rect.left += dx * time;
Collision();
currentFrame += time * 0.005;
if (currentFrame > 2) currentFrame -= 2;
sprite.setTextureRect(IntRect(18 * int(currentFrame), 0, 16, 16));
if (!life)
{
life = false;
sprite.setTextureRect(IntRect(58, 0, 16, 16));
}
else
{
life = true;
}
sprite.setPosition(rect.left - offsetX, rect.top - offsetY);
}
void Collision()
{
for (int i = rect.top / 16; i<(rect.top + rect.height) / 16; i++)
for (int j = rect.left / 16; j<(rect.left + rect.width) / 16; j++)
if ((TileMap[i][j] == 'P') || (TileMap[i][j] == '0') || (TileMap[i][j] == 'v') || (TileMap[i][j] == 'b'))
{
if (dx>0)
{
rect.left = j * 16 - rect.width; dx *= -1;
}
else if (dx<0)
{
rect.left = j * 16 + 16; dx *= -1;
}
}
}
};
void Start_Spiel()
{
HWND console_window = GetConsoleWindow();
system("Cls");
//SetWindowPos(console_window,0,0,0,100,100,SWP_HIDEWINDOW);
RenderWindow window(VideoMode(500, 300), "Super Mario Land II");
Texture tileSet;
//Texture Tileset;
tileSet.loadFromFile("Mario_Tileset.png");
//Tileset.loadFromFile("Mario_tileset_end.jpeg");
PLAYER Mario(tileSet);
ENEMY enemy;
enemy.set(tileSet, 48 * 16, 13 * 16);
Sprite tile(tileSet);
//Sprite tilem(Tileset);
SoundBuffer buffer;
buffer.loadFromFile("Mario_Jump.ogg");
Sound sound(buffer);
sound.setVolume(20);
SoundBuffer gmbuffer;
gmbuffer.loadFromFile("Mario_Game_Over.ogg");
Sound gmsound(gmbuffer);
SoundBuffer bfbriet;
bfbriet.loadFromFile("Mario_Level_Complete.ogg");
Sound bfSound(bfbriet);
SoundBuffer briet;
briet.loadFromFile("Star_Man.ogg");
Sound stsound(briet);
SoundBuffer Buffer;
Buffer.loadFromFile("Mario_die.ogg");
Sound ssound(Buffer);
Music music;
music.openFromFile("Mario_Theme.ogg");
music.play();
music.setVolume(40);
music.setLoop(true);
Clock clock;
while (window.isOpen())
{
float time = clock.getElapsedTime().asMicroseconds();
clock.restart();
time = time / 500;
if (time > 20) time = 20;
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
window.close();
}
if ((Keyboard::isKeyPressed(Keyboard::S)) && (Keyboard::isKeyPressed(Keyboard::Right)) && (Keyboard::isKeyPressed(Keyboard::Up)))
{
if (Mario.onGround)
{
Mario.dy = -0.30;
Mario.onGround = false;
sound.play();
}
}
if ((Keyboard::isKeyPressed(Keyboard::S)) && (Keyboard::isKeyPressed(Keyboard::Left)) && (Keyboard::isKeyPressed(Keyboard::Up)))
{
if (Mario.onGround)
{
Mario.dy = -0.30;
Mario.onGround = false;
sound.play();
}
}
if (Keyboard::isKeyPressed(Keyboard::Left)) Mario.dx = -0.08;
if (Keyboard::isKeyPressed(Keyboard::Right)) Mario.dx = 0.08;
if (Keyboard::isKeyPressed(Keyboard::Up)) if (Mario.onGround) { Mario.dy = -0.29; Mario.onGround = false; sound.play(); }
if ((Keyboard::isKeyPressed(Keyboard::S)) && (Keyboard::isKeyPressed(Keyboard::Left)))
{
Mario.dx = -0.11;
Mario.dx = -0.12;
}
if ((Keyboard::isKeyPressed(Keyboard::S)) && (Keyboard::isKeyPressed(Keyboard::Right)))
{
Mario.dx = 0.11;
Mario.dx = 0.12;
}
Mario.update(time);
enemy.update(time);
if (Mario.rect.intersects(enemy.rect))
{
if (enemy.life) {
if (Mario.dy>0) { enemy.dx = 0; Mario.dy = -0.2; enemy.life = false; }
else Mario.sprite.setColor(Color::Red);
}
}
if (Mario.rect.left>200) offsetX = Mario.rect.left - 200;
window.clear(Color(92, 148, 252));
for (int i = 0; i<H; i++)
for (int j = 0; j<W; j++)
{
if (TileMap[i][j] == 'P') tile.setTextureRect(IntRect(143 - 16 * 3, 112, 16, 16)); //brauner Grundboden
if (TileMap[i][j] == 'k') tile.setTextureRect(IntRect(143, 112, 16, 16)); //normaler Gelber Stein(Schornstein)
if (TileMap[i][j] == 'c') tile.setTextureRect(IntRect(143 - 16, 112, 16, 16)); //(?)Fragezeichen Itemstein
if (TileMap[i][j] == 't') tile.setTextureRect(IntRect(0, 47, 32, 48)); //normales Rohr
if (TileMap[i][j] == 'g') tile.setTextureRect(IntRect(0, 16 * 9 - 5, 3 * 16, 37)); //kleiner Hügel
if (TileMap[i][j] == 'G') tile.setTextureRect(IntRect(145, 222, 222 - 145, 255 - 222)); //großer Hügel
if (TileMap[i][j] == 'd') tile.setTextureRect(IntRect(0, 106, 74, 127 - 106)); //3 Busch Hügel
if (TileMap[i][j] == 'w') tile.setTextureRect(IntRect(99, 224, 140 - 99, 255 - 224)); //1 Wolke
if (TileMap[i][j] == 'r') tile.setTextureRect(IntRect(143 - 32, 112, 16, 16)); //Ein brauner quadratischer Stein
if (TileMap[i][j] == 'q') tile.setTextureRect(IntRect(0, 222, 90, 35)); //3 Wolken
if (TileMap[i][j] == 'e') tile.setTextureRect(IntRect(50, 55, 45, 45)); //1 Busch Hügel
if (TileMap[i][j] == 'z') tile.setTextureRect(IntRect(95, 5, 107, 107)); //End Level Burg
if (TileMap[i][j] == 'u') tile.setTextureRect(IntRect(95, 128, 16, 16)); //blauer Grundboden
if (TileMap[i][j] == 'i') tile.setTextureRect(IntRect(143 - 32, 128, 16, 16)); //ein blauer quadratischer Stein
if (TileMap[i][j] == 'o') tile.setTextureRect(IntRect(143, 128, 16, 16)); //normaler blauer Stein(Schornstein)
if (TileMap[i][j] == 'p') tile.setTextureRect(IntRect(160, 123, 64, 20)); //2 Busch Hügel
if (TileMap[i][j] == 'a') tile.setTextureRect(IntRect(63, 145, 12, 16)); //kleines Büschlein (am Ende des Levls an der Burg)
if (TileMap[i][j] == 's') tile.setTextureRect(IntRect(0, 176, 78, 32)); //2 teiliges Rohr
if (TileMap[i][j] == 'f') tile.setTextureRect(IntRect(95, 160, 66, 32)); //2 Wolken
if (TileMap[i][j] == 'h') tile.setTextureRect(IntRect(175, 192, 49, 17)); //(bewegliche/)Plattform
if (TileMap[i][j] == 'j') tile.setTextureRect(IntRect(224, 176, 24, 32)); // Boden mit Wasser
if (TileMap[i][j] == 'l') tile.setTextureRect(IntRect(224, 176, 16, 16)); //Wasser
if (TileMap[i][j] == 'm') tile.setTextureRect(IntRect(239, 240, 17, 16)); //"Brücke"
if (TileMap[i][j] == 'b') tile.setTextureRect(IntRect(0, 70, 16, 16)); //weiteres Rohrteil(quadrat->links)
if (TileMap[i][j] == 'v') tile.setTextureRect(IntRect(16, 70, 16, 16)); //weiteres Rohrteil(quadrat->rechts)
//if (TileMap[i][j]=='n') tilem.setTextureRect( IntRect(552,2,55,350) ); //Fahnenstangen am Ende des Levels
if (TileMap[i][j] == '1') tile.setTextureRect(IntRect(0, 0, 0, 0)); //Fall/Tod
if ((TileMap[i][j] == ' ') || (TileMap[i][j] == '0')) continue;
tile.setPosition(j * 16 - offsetX, i * 16 - offsetY);
//tilem.setPosition(j*16 - offsetX,i*16 - offsetY);
//window.draw(tilem);
window.draw(tile);
}
window.draw(Mario.sprite);
window.draw(enemy.sprite);
window.display();
}
SetWindowPos(console_window, 0, 100, 100, 800, 340, SWP_SHOWWINDOW);
}
void Anleitung()
{
char AEingabe;
system("Cls");
}
void Credits()
{
char Eingabe;
system("Cls");
std::cout << "================================================================================";
std::cout << "==================================|-Credits-|===================================";
std::cout << "================================================================================";
std::cout << "\n";
std::cout << "\n";
std::cout << "Gesch\x84 \bftsf\x81\hrer-----------------------------------------------------";
std::cout << "\n";
std::cout << "Angestellte---------------------------- ------------";
std::cout << "--------------------------------------- -----------------------";
std::cout << "\n";
std::cout << "Logo Kreationist---------------------------------------------------";
std::cout << "\n";
std::cout << "Finanzen------------------------------------------------------------";
std::cout << "\n";
std::cout << "Gesch\x84 \bftsidee-------------------------- ----------";
std::cout << "--------------------------------------------- -------------------";
std::cout << "--------------------------------------------- -----------------------";
std::cout << "\n";
std::cout << "Werbung-------------------------------- -------------------------";
std::cout << "\n";
std::cout << "Programmierer-------------------------- -----------------------";
std::cout << "\n";
std::cout << " ©FrameGame ";
std::cout << "\n";
std::cout << "Um die Credits zu verlassen dr\x81\cken sie eine Taste und dann Enter:"; std::cin >> Eingabe;
system("Cls");
}
int main(int argc, char **argv)
{
int tmp;
char Auswahl;
bool running = true;
do
{
std::cout << "================================================================================";
std::cout << "==============================|Super Mario Land II|=============================";
std::cout << "================================================================================";
std::cout << "======================= [S]piel Starten" << " ===========================";
std::cout << "======================= [A]nleitung" << " ===========================";
std::cout << "======================= [C]redits" << " ===========================";
std::cout << "======================= [V]erlassen" << " ===========================";
std::cout << "================================================================================";
std::cout << "================================================================================";
std::cout << "\n";
std::cout << "Herzlich Willkommen zu unserem Projekt, welches wir heute vorstellen m\x94\chten. ";
std::cout << "Diese Anwendung die ihr hier sieht, ist ein mit C++ geschriebenes Men\x81 welches ";
std::cout << "folgende Funkionen besitzt:" << std::endl;
std::cout << "\n";
std::cout << "|[S]piel Starten|-- Bei dieser Funktion wird das Spiel gestartet. ";
std::cout << "\n";
std::cout << "|[A]nleitung|-- Bei der Funktion bekommt ihr eine genauere Beschreibung des ";
std::cout << "Spielablaufes und der Steuerung." << std::endl;
std::cout << "\n";
std::cout << "|[C]redits|-- Hier werden alle Mitwirkende, die an diesem Projekt mitgearbeitet ";
std::cout << "haben, aufgelistet." << std::endl;
std::cout << "\n";
std::cout << "|[V]erlassen|-- Das (Konsolen)fenster wird geschlossen; Sie verlassen das Spiel ";
std::cout << "\n";
std::cout << "Deine Eingabe:"; std::cin >> Auswahl;
switch (Auswahl)
{
case ('s') : case('S') :
std::cout << "\n";
Start_Spiel();
break;
case ('a') : case ('A') :
std::cout << "\n";
Anleitung();
break;
case ('c') : case ('C') :
std::cout << "\n";
Credits();
break;
case ('v') : case ('V') :
return 0;
break;
default:
std::cout << "\n";
std::cout << "Ungueltige Eingabe\n";
std::cout << "\n";
std::cout << "Bitte geben sie den vorgegebenen Buchstaben ein um eine Funktion nutzten\n" << "zu k\x94nnen!\n";
system("pause");
system("Cls");
}
} while (running == true);
std::cin >> tmp;
return 0;
}
|
|
|
 |
Similar Threads
|
Spiel Programmieren (cube world , minecraft)
08/03/2013 - .NET Languages - 15 Replies
Hallo,
Mich interesiert schon so lange spiele wie minecraft & neuerdings such cube world.
Ich würde gerne auch so etwas in der art Programmieren.
Ich habe aber keine Ahnung wie.
ich weiß , dass man eine Spiele engine braucht.
Ich habe schon mak XNA 4.0 getestet , aber wenn ich dann vb.net 2010 öffne , kann ich XNA nicht öffnen , wenn ich ein neues Project erstellen möchte.
Könnt ihr mir eine Spiele engine empfehlen ?
Und ist vb.net für sowelche anliegen gut ausgelegt ?
Mfg,
|
Seriöse firmen die einem ein Spiel Programmieren?
03/21/2013 - General Gaming Discussion - 2 Replies
Ich hab eine geniale Idee für ein Browsergame die es so auf dem Markt noch nicht gibt
Zum Spiel:
es ist ein 2D spiel und ist nicht allzu komplex ( mit pacman / bomberman (vonfrüher) vergleichbar )
kennt wer seriöse Anbieter die soetwas gegen bezahlung herstellen?
|
[Projekt]Online Spiel Programmieren.
01/29/2011 - Main - 8 Replies
Hallo liebe Com,
Hiermit möchte ich eine Suche nach Leuten die sich dafür Interessieren,
ein Online Rollenspiel zu erstellen aufgeben.
Damit meine ich nicht ein Metin2 P-Server zu erstellen womit man sich nur strafbar macht, weil die Serverfiles geklaut wurden und somit das Benutzen dieser Files strafbar ist zu machen!
Nein! Ich suche Leute mit den ich ein eigene Rollenspiel erfinde.
Ich suche Leute die Mind. 16 Jahre alt sind.
Ich möchte in diesen Thema keine Posts wie z.B. "Dazu...
|
memory spiel programmieren
04/26/2007 - General Coding - 2 Replies
hat sicher erledigt , habs fertig bekommen, kann geschlossen/gelöscht werden !
|
All times are GMT +1. The time now is 15:55.
|
|