Forum Sveta kompjutera

Nazad   Forum Sveta kompjutera > Test Run > Programiranje > Pravljenje igara
Uputstvo Članstvo Kalendar Današnje poruke Pretraži

Pravljenje igara Programski jezici, tehnike, alatke u službi pravljenja igara...

Odgovor
 
Alatke vezane za temu Vrste prikaza
Stara 22.7.2011, 2:51   #1
Ivan-94
Veteran
 
Član od: 15.3.2009.
Lokacija: Beograd
Poruke: 654
Zahvalnice: 240
Zahvaljeno 63 puta na 43 poruka
Slanje poruke preko MSN-a korisniku Ivan-94 Slanje poruke preko Skypea korisniku Ivan-94
Određen forumom Nece da iscrta...

Ovako, evo koda:
Kod:
#include <iostream>
#include <allegro.h>

#define DOWN 0
#define LEFT 32
#define RIGHT 64
#define UP 96
#define MAX_BULLETS 60

bool canshoot = true;
BITMAP *buffer;

class Bullet{
	public:
		int bx; //x value for bullet
		int by; //y value for bullet
		int bs; // bullet speed
		int direction;
		bool exist;
		void shoot();
		void movebullet();
		Bullet();
	private:
};

Bullet::Bullet(){
	bx = 0;
	by = 0;
	bs = 3;
	exist = false;
}

void Bullet::shoot(){
	circlefill(buffer, bx, by, 1, makecol(255, 0, 0));
	exist = true;
}

void Bullet::movebullet(){
	circlefill(buffer, bx, by, 1, makecol(0, 0, 0));
	switch(direction){
		case 1:
			by -= bs;
		break;
		case 2:
			by += bs;
		break;
		case 3:
			bx -= bs;
		break;
		case 4:
			bx += bs;
		break;
		circlefill(buffer, bx, by, 1, makecol(255, 0, 0));
		if(bx > 640)
			exist = false;
		if(by > 480)
			exist = false;
	}
}

int main(){
	allegro_init();
	install_keyboard();
	set_color_depth(32);
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
	set_window_title("My Allegro");

	Bullet bullet[MAX_BULLETS];

	buffer = create_bitmap(640, 480);
	BITMAP *walking = load_bitmap("walking.bmp", NULL);

	bool done(false);

	int x = 0, y = 0;
	int ImageX = 0;
	int ImageY = DOWN;

	while(!done){
		if(key[KEY_ESC]){
			done = true;
		}

		if(key[KEY_RIGHT]){
			ImageY = RIGHT;
			x += 5;
		}
		else if(key[KEY_LEFT]){
			ImageY = LEFT;
			x -= 5;
		}
		else if(key[KEY_UP]){
			ImageY = UP;
			y -= 5;
		}
		else if(key[KEY_DOWN]){
			ImageY = DOWN;
			y += 5;
		}

		if(!key[KEY_RIGHT] && !key[KEY_LEFT] && !key[KEY_DOWN] && !key[KEY_UP])
			ImageX = 32;
		else
			ImageX += 32;

		if(ImageX > 64)
			ImageX = 0;

		if(key[KEY_SPACE]){
			for(int i = 0; i < MAX_BULLETS; i++){
				if((bullet[i].exist == true) && (canshoot == true)){
					bullet[i].bx = x;
					bullet[i].by = y;
					switch(ImageY){
						case UP:
							bullet[i].direction = 1;
						break;
						case DOWN:
							bullet[i].direction = 2;
						break;
						case RIGHT:
							bullet[i].direction = 4;
						break;
						case LEFT:
							bullet[i].direction = 3;
						break;
						bullet[i].shoot();
						canshoot = false;
					}
				}
			}
		}

		if(!key[KEY_SPACE]){
			if(canshoot == false)
				canshoot = true;
		}

		for(int i = 0; i < MAX_BULLETS; i++){
			if(bullet[i].exist == true)
				bullet[i].movebullet();
		}

		masked_blit(walking, buffer, ImageX, ImageY, x, y, 32, 32);
		blit(buffer, screen, 0, 0, 0, 0, 640, 480);
		rest(60);
		clear_bitmap(buffer);
	}

	return 0;
}

END_OF_MAIN()
Tek sam poceo da ucim da koristim allegro, i vec sam zapeo...Ja mislim da sam sve lepo odradio ali nece da mi iscrta bullet i da ga pomeri.
Evo vam i sprite da vidite(ovaj je png ali sam ga ja naravno konvertovao u bmp,da ne pomislite odma na to).
Priložene slike
 
Ivan-94 je offline   Odgovor sa citatom ove poruke
Stara 22.7.2011, 11:40   #2
Belphegor
V.I.P. Programiranje
 
Član od: 29.8.2007.
Lokacija: Valjevo
Poruke: 1.349
Zahvalnice: 983
Zahvaljeno 371 puta na 280 poruka
Određen forumom Re: Nece da iscrta...

Nikad nisam koristio alegro pa cu pretpostaviti neke stvari. Vidim da funkcija shoot() jedina postavlja promenjljivu exist na true ali je pozivas samo unutar if statement-a do koje ne mozes doci jer proveravas da li je vec true, sto nije jer je inicijalizovana u konstruktoru na false:
Kod:
if((bullet[i].exist == true) && (canshoot == true)){
...
bullet[i].shoot(); ...
}
edit: Pod hitno promeni logiku koda, IMO imas dosta gresaka.
Recimo:
Kod:
switch(ImageY){                        
 case UP:                             
    bullet[i].direction = 1;                         
    break;                         
case DOWN:                             
    bullet[i].direction = 2;                         
    break;                         
case RIGHT:                             
    bullet[i].direction = 4;                         
    break;                         
case LEFT:                             
    bullet[i].direction = 3;                         
    break;                         
    bullet[i].shoot();                         
    canshoot = false;                     
}
Plus na ono gore navedeno kod nikad i nece doci do zadnja 2 izraza u switch-u jer ne podpada ni pod jedan case, da nisi nameravao za default case?

Poslednja ispravka: Belphegor (22.7.2011 u 13:21)
Belphegor je offline   Odgovor sa citatom ove poruke
Sledeći korisnik se zahvaljuje korisniku Belphegor na korisnoj poruci:
Ivan-94 (22.7.2011)
Stara 22.7.2011, 14:41   #3
Ivan-94
Veteran
 
Član od: 15.3.2009.
Lokacija: Beograd
Poruke: 654
Zahvalnice: 240
Zahvaljeno 63 puta na 43 poruka
Slanje poruke preko MSN-a korisniku Ivan-94 Slanje poruke preko Skypea korisniku Ivan-94
Određen forumom Re: Nece da iscrta...

Citat:
Belphegor kaže: Pregled poruke
Nikad nisam koristio alegro pa cu pretpostaviti neke stvari. Vidim da funkcija shoot() jedina postavlja promenjljivu exist na true ali je pozivas samo unutar if statement-a do koje ne mozes doci jer proveravas da li je vec true, sto nije jer je inicijalizovana u konstruktoru na false:
Kod:
if((bullet[i].exist == true) && (canshoot == true)){
...
bullet[i].shoot(); ...
}
edit: Pod hitno promeni logiku koda, IMO imas dosta gresaka.
Recimo:
Kod:
switch(ImageY){                        
 case UP:                             
    bullet[i].direction = 1;                         
    break;                         
case DOWN:                             
    bullet[i].direction = 2;                         
    break;                         
case RIGHT:                             
    bullet[i].direction = 4;                         
    break;                         
case LEFT:                             
    bullet[i].direction = 3;                         
    break;                         
    bullet[i].shoot();                         
    canshoot = false;                     
}
Plus na ono gore navedeno kod nikad i nece doci do zadnja 2 izraza u switch-u jer ne podpada ni pod jedan case, da nisi nameravao za default case?
Oooo...tek sad vidim, ta dva izraza treba da budu van switch-a...Hvala
I stavio sam u konstruktoru da exist bude false.I sad puca ali samo jedan metak, kad pritisnem ponovo space on vraca metak na pocetak?

EDIT:
Evo koda sad, ali opet nece da crta:
Kod:
#include <iostream>
#include <allegro.h>

#define DOWN 0
#define LEFT 32
#define RIGHT 64
#define UP 96
#define MAX_BULLETS 60

bool canshoot = true;
BITMAP *buffer;

class Bullet{
	public:
		int bx; //x value for bullet
		int by; //y value for bullet
		int bs; // bullet speed
		int direction;
		bool exist;
		void shoot();
		void movebullet();
		Bullet();
	private:
};

Bullet::Bullet(){
	bx = 0;
	by = 0;
	bs = 3;
	exist = false;
}

void Bullet::shoot(){
	circlefill(buffer, bx, by, 1, makecol(255, 0, 0));
	exist = true;
}

void Bullet::movebullet(){
	circlefill(buffer, bx, by, 1, makecol(0, 0, 0));
	switch(direction){
		case 1:
			by -= bs;
		break;
		case 2:
			by += bs;
		break;
		case 3:
			bx -= bs;
		break;
		case 4:
			bx += bs;
		break;
	}
	circlefill(buffer, bx, by, 1, makecol(255, 0, 0));
	if(bx > 640)
		exist = false;
	if(by > 480)
		exist = false;
}

int main(){
	allegro_init();
	install_keyboard();
	set_color_depth(32);
	set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
	set_window_title("My Allegro");

	Bullet bullet[MAX_BULLETS];

	buffer = create_bitmap(640, 480);
	BITMAP *walking = load_bitmap("walking.bmp", NULL);

	bool done(false);

	int x = 0, y = 0;
	int ImageX = 0;
	int ImageY = DOWN;

	while(!done){
		if(key[KEY_ESC]){
			done = true;
		}

		if(key[KEY_RIGHT]){
			ImageY = RIGHT;
			x += 5;
		}
		else if(key[KEY_LEFT]){
			ImageY = LEFT;
			x -= 5;
		}
		else if(key[KEY_UP]){
			ImageY = UP;
			y -= 5;
		}
		else if(key[KEY_DOWN]){
			ImageY = DOWN;
			y += 5;
		}

		if(!key[KEY_RIGHT] && !key[KEY_LEFT] && !key[KEY_DOWN] && !key[KEY_UP])
			ImageX = 32;
		else
			ImageX += 32;

		if(ImageX > 64)
			ImageX = 0;

		if(key[KEY_SPACE]){
			for(int i = 0; i < MAX_BULLETS; i++){
				if( bullet[i].exist == false && canshoot == true){
					bullet[i].bx = x;
					bullet[i].by = y;
					switch(ImageY){
						case UP:
							bullet[i].direction = 1;
						break;
						case DOWN:
							bullet[i].direction = 2;
						break;
						case RIGHT:
							bullet[i].direction = 4;
						break;
						case LEFT:
							bullet[i].direction = 3;
						break;

						bullet[i].shoot();
						canshoot = false;
					}
				}
			}
		}

		if(!key[KEY_SPACE]){
			if(canshoot == false)
				canshoot = true;
		}

		for(int i = 0; i < MAX_BULLETS; i++){
			if(bullet[i].exist == true)
				bullet[i].movebullet();
		}

		masked_blit(walking, buffer, ImageX, ImageY, x, y, 32, 32);
		blit(buffer, screen, 0, 0, 0, 0, 640, 480);
		rest(60);
		clear_bitmap(buffer);
	}

	return 0;
}

END_OF_MAIN()

Poslednja ispravka: Ivan-94 (22.7.2011 u 14:54)
Ivan-94 je offline   Odgovor sa citatom ove poruke
Stara 22.7.2011, 15:13   #4
NISAM NESTO SMART
Član
 
Član od: 14.7.2009.
Lokacija: Srbija
Poruke: 315
Zahvalnice: 53
Zahvaljeno 73 puta na 54 poruka
Slanje poruke preko MSN-a korisniku NISAM NESTO SMART
Određen forumom Re: Nece da iscrta...

Pa i u ovom kodu sto si sad postavio je u switch-u:

Kod:
	switch(ImageY){
						case UP:
							bullet[i].direction = 1;
						break;
						case DOWN:
							bullet[i].direction = 2;
						break;
						case RIGHT:
							bullet[i].direction = 4;
						break;
						case LEFT:
							bullet[i].direction = 3;
						break;

						bullet[i].shoot();
						canshoot = false;
					}
NISAM NESTO SMART je offline   Odgovor sa citatom ove poruke
Sledeći korisnik se zahvaljuje korisniku NISAM NESTO SMART na korisnoj poruci:
Ivan-94 (22.7.2011)
Odgovor

Bookmarks sajtovi


Vaš status
Ne možete postavljati teme
Ne možete odgovarati na poruke
Ne možete slati priloge uz poruke
Ne možete prepravljati svoje poruke

BB kod: uključeno
Smajliji: uključeno
[IMG] kod: uključeno
HTML kod: isključeno


Slične teme
tema temu započeo forum Odgovora Poslednja poruka
nece da udje u bios ?! Svrbisha Kvarovi 8 16.12.2009 14:32
nece da upali tanasko1975 Kvarovi 4 16.12.2009 11:51
Komp nece nikako da se upali BMWM5 Kvarovi 18 6.12.2009 21:49
Nece da se uključi MSN p1ay80y Kvarovi 3 4.9.2009 15:16
Help! DVD uređaj nece da se otvori perakle Kvarovi 17 18.8.2009 0:00


Sva vremena su po Griniču +2 h. Sada je 20:11.


Powered by vBulletin® verzija 3.8.7
Copyright ©2000–2024, vBulletin Solutions, Inc.
Hosted by Beograd.com