Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Community-Fossil
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
int main() { bool Feld[FELDH][FELDW] = {false}; sf::RenderWindow W(sf::VideoMode(800,600,8),"TD",sf::Style::Close); W.SetFramerateLimit(30); sf::Event E; const sf::Input& Input = W.GetInput(); sf::Shape Rect = sf::Shape::Rectangle(0,0,50,50,sf::Color::White,1,sf::Color::Black); while(W.IsOpened()) { while(W.GetEvent(E)) { if(E.Type==sf::Event::Closed) W.Close(); if(E.Type==sf::Event::MouseButtonReleased) { unsigned int X,Y; X = Input.GetMouseX()-OFFSETX; Y = Input.GetMouseY()-OFFSETY; unsigned int FieldX = X/TILEW, FieldY = Y/TILEH; Feld[FieldY][FieldX]=!Feld[FieldY][FieldX]; } } //Grafik //****** W.Clear(); for(unsigned int y = 0; y < FELDH; y++) { for(unsigned int x = 0; x < FELDW; x++) { if(!Feld[y][x]) Rect.SetColor(sf::Color(0,200,200)); else Rect.SetColor(sf::Color(180,100,255)); Rect.SetPosition(x*50+50, y*50+50); W.Draw(Rect); } } W.Display(); } return 0; } |
Community-Fossil
C-/C++-Quelltext |
|
1 2 |
unsigned int X = (Input.GetMouseX()-OFFSETX)/TILEW, Y = (Input.GetMouseY()-OFFSETY)/TILEH; Feld[Y][X]=!Feld[Y][X]; |
Community-Fossil
Aber in einer Zeile 2 Defintionen+Wertzuweisungen ist ja nicht so feine Art imho.
Community-Fossil
C-/C++-Quelltext |
|
1 2 3 |
unsigned int X = (Input.GetMouseX()-OFFSETX)/TILEW; unsigned int Y = (Input.GetMouseY()-OFFSETY)/TILEH; Feld[Y][X]=!Feld[Y][X]; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
void f1() { unsigned int X = (rand()-rand())/rand(); unsigned int Y = (rand()-rand())/rand(); } void f2() { unsigned int X = rand()-rand(); unsigned int Y = rand()-rand(); unsigned int X2 = X / rand(); unsigned int Y2 = Y / rand(); } |
Werbeanzeige