Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

hi!

Also ich programmier gerade Pacman und nun habe ich einen Geist der apprallt und den Blick ändert zu welcher Wand er apprallt, jedoch muss ich nun noch mehr Geister einfügen und die sollen natürlich nciht den gleichen Weg bzw. gleich anfangen wie der erste nur irgendwie weiß ich cniht wie ich das machen soll kann mir jemand auf die sprünge helfen. Danke

#include <allegro.h>

enum RICHTUNG

{

	LINKS,

	RECHTS,

	OBEN,

	UNTEN,

	RICHTUNG_ANZ

};

enum ZIPFEL

{

	ZU,

	OFFEN,

	ZIPFEL_ANZ

};


void fataler_fehler() {

	allegro_message(allegro_error);

	exit(1);	

}

int main() {


	allegro_init();

	if (install_keyboard() < 0) {

		fataler_fehler();

	}

	set_color_depth(24);

	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0) < 0) {

		fataler_fehler();

	}


	BITMAP *bmp = NULL;

	BITMAP *ghost[RICHTUNG_ANZ][ZIPFEL_ANZ] = {NULL};



	bmp = load_bitmap("pac800.bmp", NULL);

	if (bmp == NULL) {

		allegro_message("Konnte die Bitmap-Datei nicht finden");

		exit(1);		

	}


	for(int i=0; i<RICHTUNG_ANZ; i++){

		for (int j=0; j<ZIPFEL_ANZ; j++)

		{

			ghost[i][j] = create_sub_bitmap(bmp, (2*i+j)*36, 0, 36, 36); /*öffnet den Geist*/


		}

	}


	int x = 0; /*ObenRand*/ 

	int y = 0; /*LinkerRand*/

	int RaufRunter = 1;

	int LinksRechts = 1;

	int iFlattern = ZU;

	int iFlatterGeschwindigkeit = 10;

	int iSchritte = 0;

	int iRichtung=RECHTS;

	while(!keypressed()) { /*wenn keine Taste gedrueckt wurde*/


		x = x + LinksRechts;

		y = y + RaufRunter;


		vsync();

		clear_bitmap(screen);



		draw_sprite(screen, ghost[iRichtung][iFlattern], x, y); /*(x,y)anfangskoordinaten wo der geist beginnt*/



		iSchritte++;

		if (iSchritte > iFlatterGeschwindigkeit)

		{

			iFlattern = (iFlattern == ZU ? OFFEN : ZU);

			iSchritte = 0;

		}


		if(x + 36 > SCREEN_W) { 

			LinksRechts *= -1;

			iRichtung = LINKS;

		}


		if(x < 0) { 

			LinksRechts *= -1;

			iRichtung = RECHTS;

		}


		if(y + 36 > SCREEN_H) {

			RaufRunter *= -1;

			iRichtung = OBEN;

		}


		if(y < 0) { 

			RaufRunter *= -1;

			iRichtung = UNTEN;

		}


	}

	destroy_bitmap(bmp);


	for(int i=0; i<4; i++){

		for (int j=0; j<ZIPFEL_ANZ; j++)

		{

			destroy_bitmap(ghost[i][j]);

		}

	}




	return 0;

} END_OF_MAIN()

Hi!

Weil ich das noch nicht gelernt hab bin erst im ersten jahr.

gruß

Hi!

Wie soll ich denn eine Zufallszahl erstellen? Mit Rand?? Kannste mir ein kleines Beispiel machen dann versteh cih das besser.

Danke

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.