Commits

Ivan Vučica committed a051fd9

Početni commit.

Comments (0)

Files changed (8)

.hgignore

Empty file added.
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+	<FileVersion major="1" minor="6" />
+	<Project>
+		<Option title="Crtanje" />
+		<Option pch_mode="2" />
+		<Option compiler="gcc" />
+		<Build>
+			<Target title="Debug">
+				<Option output="bin\Debug\Crtanje" prefix_auto="1" extension_auto="1" />
+				<Option object_output="obj\Debug\" />
+				<Option type="1" />
+				<Option compiler="gcc" />
+				<Compiler>
+					<Add option="-g" />
+				</Compiler>
+				<Linker>
+					<Add library="mingw32" />
+					<Add library="SDLmain" />
+					<Add library="SDL" />
+					<Add library="SDL_mixer" />
+				</Linker>
+			</Target>
+			<Target title="Release">
+				<Option output="bin\Release\Crtanje" prefix_auto="1" extension_auto="1" />
+				<Option object_output="obj\Release\" />
+				<Option type="1" />
+				<Option compiler="gcc" />
+				<Compiler>
+					<Add option="-O2" />
+				</Compiler>
+				<Linker>
+					<Add option="-s" />
+				</Linker>
+			</Target>
+		</Build>
+		<Compiler>
+			<Add option="-Wall" />
+		</Compiler>
+		<Unit filename="main.cpp" />
+		<Extensions>
+			<code_completion />
+			<envvars />
+			<debugger />
+			<lib_finder disable_auto="1" />
+		</Extensions>
+	</Project>
+</CodeBlocks_project_file>

glavnilik.bmp

Added
New image
+#include <SDL/SDL.h>
+#include <math.h>
+#include<SDL/SDL_Mixer.h>
+
+
+#define MAX_PARTIKLA 9001
+
+void izlaz();
+typedef struct
+{
+float x,y;
+    float brzinax, brzinay;
+} GlavniLik;
+
+GlavniLik glavniLik;
+SDL_Surface* glavniLikSprite;
+SDL_Surface* ekran;
+
+typedef struct
+{
+    float x, y;
+    float vx, vy;
+    float t;
+}Particle;
+
+Particle raketa;
+Particle partikli[MAX_PARTIKLA];
+
+SDL_Surface* particleSprite;
+SDL_Surface* raketaSprite;
+
+int igraSeJosUvijekVrti = 1;
+
+void updateRaketa (Particle *raketa, float dt);
+void updateParticle (Particle *partikl, float dt);
+void paintParticle  (Particle *partikl);
+void paintRaketa  (Particle *partikl);
+
+
+
+int slikaX = 0;
+
+
+void paintGlavniLik(GlavniLik *lik)
+{
+    SDL_Rect dst;
+    dst.x=lik->x;
+    dst.y=lik->y;
+    dst.w=0;
+    dst.h=0;
+    SDL_BlitSurface(glavniLikSprite, NULL,
+                    ekran, &dst);
+}
+void updateGlavniLik(GlavniLik *lik,
+                        float t)
+
+
+{
+    lik->x+=lik->brzinax*t;
+    lik->y+=lik->brzinay*t;
+
+}
+void izlaz()
+{
+    SDL_FreeSurface(glavniLikSprite);
+    SDL_Quit();
+    exit(0);
+}
+int main(int argc, char** argv)
+{
+
+    SDL_Surface* slika;
+    printf("%p\n", slika);
+    SDL_Init (SDL_INIT_VIDEO);
+
+
+    glavniLik.x=0;
+    glavniLik.y=0;
+    glavniLik.brzinax=60;
+    glavniLik.brzinay=60;
+
+
+    ekran=SDL_SetVideoMode(640,480,0,0);
+
+    glavniLikSprite=SDL_LoadBMP ("glavnilik.bmp");
+    slika=SDL_LoadBMP ("slika.bmp");
+    particleSprite=SDL_LoadBMP ("particle.bmp");
+    raketaSprite=SDL_LoadBMP ("raketa.bmp");
+
+    memset (&raketa, 0, sizeof(Particle));
+    memset (&partikli[0], 0, sizeof(Particle)*MAX_PARTIKLA);
+
+
+
+
+    while (igraSeJosUvijekVrti)
+    {
+        SDL_Event event;
+
+        while (SDL_PollEvent(&event))
+        {
+            if (event.type==SDL_QUIT)
+            {
+                igraSeJosUvijekVrti = 0;
+            }
+            if (event.type == SDL_KEYDOWN)
+            {
+                if(event.key.keysym.sym == SDLK_ESCAPE)
+                {
+                    izlaz();
+                }
+                if(event.key.keysym.sym == SDLK_w)
+                {
+                    glavniLik.brzinay=-30;
+                }
+                if (event.key.keysym.sym == SDLK_s)
+                {
+                    glavniLik.brzinay=30;
+                }
+
+                if (event.key.keysym.sym == SDLK_a)
+                {
+                    glavniLik.brzinax=-30;
+                }
+                if (event.key.keysym.sym == SDLK_d)
+                {
+                    glavniLik.brzinax=30;
+                }
+            }
+
+            if (event.type == SDL_KEYUP)
+            {
+
+                if(event.key.keysym.sym == SDLK_w)
+                {
+                    glavniLik.brzinay=0;
+                }
+                if (event.key.keysym.sym == SDLK_s)
+                {
+                    glavniLik.brzinay=0;
+                }
+
+                if (event.key.keysym.sym == SDLK_a)
+                {
+                    glavniLik.brzinax=0;
+                }
+                if (event.key.keysym.sym == SDLK_d)
+                {
+                    glavniLik.brzinax=0;
+                }
+            }
+        }
+
+
+        ////////
+
+        SDL_FillRect(ekran, NULL, 0x221122);
+
+        SDL_Rect odrediste;
+        odrediste.x = slikaX;
+        odrediste.y = 0;
+        odrediste.w = 0;
+        odrediste.h = 0;
+
+        SDL_BlitSurface(slika, NULL,
+                        ekran, &odrediste);
+
+
+
+
+        paintGlavniLik(&glavniLik);
+
+
+        paintRaketa(&raketa);
+
+
+        for (int i = 0; i < MAX_PARTIKLA; i++)
+        {
+            paintParticle(&partikli[i]);
+        }
+
+
+
+        SDL_Flip(ekran);
+
+//////////////////////////////////////////////////////////////
+        float t = 1./60;
+        float dt = 1./300;
+
+        updateRaketa(&raketa, dt);
+        for (int i = 0; i < MAX_PARTIKLA; i++)
+        {
+            updateParticle(&partikli[i], dt);
+        }
+
+        slikaX ++;
+
+        updateGlavniLik(&glavniLik, t);
+
+    }
+
+    SDL_FreeSurface(particleSprite);
+    SDL_FreeSurface(slika);
+    SDL_Quit();
+
+    return 0;
+
+}
+
+void explodeRaketa(Particle *raketa)
+{
+	int dosadPopunio = 0;
+
+	for(int i = 0; i < MAX_PARTIKLA; i++ )
+	{
+		if(partikli[i].t <= 0)
+		{
+			Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096);
+			Mix_Music *pjesma = NULL;
+			pjesma=Mix_LoadMUS("pjesma.wav");
+			Mix_PlayMusic(pjesma,0);
+
+			float brzina = (rand () % 10000) / 100. - 50.;
+			float kut = (rand() % 180) * 3.14159 / 180.;
+
+
+
+			partikli[i].x = raketa->x + ((rand() % 100) / 100.) * 10 - 5;
+			partikli[i].y = raketa->y + ((rand() % 100) / 100.) * 10 - 5;
+			//partikli[i].vx = (rand () % 10000) / 100. - 50.;
+			//partikli[i].vy = -((rand () % 100) / 100.) * 50.;
+
+			partikli[i].vx = cos(kut) * brzina;
+			partikli[i].vy = sin(kut) * brzina;
+
+			partikli[i].t =((rand () % 100) / 100.) * 5 + 3;
+			dosadPopunio++;
+
+		}
+		if(dosadPopunio > 900)
+		{
+			break;
+		}
+
+	}
+
+
+}
+
+
+void spawnNewRaketa()
+{
+
+
+	//raketa->x = 200;
+	//raketa->y =700;
+	raketa.x = glavniLik.x;
+	raketa.y = glavniLik.y;
+	raketa.vx = 80;
+	raketa.vy =  -60;
+	raketa.t = 7;
+
+}
+
+void updateRaketa(Particle *raketa, float dt)
+{
+    if(raketa->t <=0)
+	{
+		explodeRaketa(raketa);
+		spawnNewRaketa();
+	}
+
+    raketa->x += raketa->vx * dt;
+    raketa->y += raketa->vy * dt;
+
+    raketa->vy += 60 * dt;
+
+
+	if(raketa->y < 50)
+	{
+		raketa->y = 50 + (50 - raketa->y);
+		raketa->vy *= -1;
+	}
+	if(raketa->y > 400)
+	{
+		raketa->y = 400 - (raketa->y - 400);
+		raketa->vy *= -1;
+	}
+	if(raketa->x < 30)
+	{
+		raketa->x = 30 + (30 - raketa->x);
+		raketa->vx *= -1;
+	}
+	if(raketa->x > 600)
+	{
+		raketa->x = 600 - (raketa->x - 600);
+		raketa->vx *= -1;
+	}
+
+	raketa->t -= dt;
+
+    {
+        int dosadPopunio = 0;
+
+        for(int i = 0; i < MAX_PARTIKLA; i++ )
+        {
+            if(partikli[i].t <= 0)
+            {
+                partikli[i].x = raketa->x;
+                partikli[i].y = raketa->y + raketaSprite->h/2;
+                partikli[i].vx = -raketa->vx * ((rand () % 100) / 100.);
+                partikli[i].vy = -raketa->vy * ((rand () % 100) / 100.);
+                partikli[i].t =  ((rand () % 100) / 100.) * 0.3 + 0.03;
+                partikli[i].t *= 2;
+                dosadPopunio++;
+
+            }
+            if(dosadPopunio > 3)
+            {
+                break;
+            }
+
+        }
+    }
+
+  }
+
+void updateParticle(Particle *partikl, float dt)
+{
+	if(partikl->t <= 0)
+		return;
+
+	partikl->x += partikl->vx * dt;
+	partikl->y += partikl->vy * dt;
+
+	partikl->vy += 10 * dt;
+
+	if(partikl->y < 50)
+	{
+		partikl->y = 50 + (50 - partikl->y);
+		partikl->vy *= -1;
+	}
+	if(partikl->y > 400)
+	{
+		partikl->y = 400 - (partikl->y - 400);
+		partikl->vy *= -1;
+	}
+	if(partikl->x < 30)
+	{
+		partikl->x = 30 + (30 - partikl->x);
+		partikl->vx *= -1;
+	}
+	if(partikl->x > 600)
+	{
+		partikl->x = 600 - (partikl->x - 600);
+		partikl->vx *= -1;
+	}
+
+	partikl->t -= dt;
+}
+
+void paintParticle(Particle *partikl)
+{
+	SDL_Rect odrediste;
+	odrediste.x = partikl->x;
+	odrediste.y = partikl->y;
+
+	if(partikl->t <= 0)
+		return;
+
+
+	SDL_BlitSurface(particleSprite, NULL, ekran, &odrediste);
+}
+
+
+void paintRaketa(Particle *partikl)
+{
+	SDL_Rect odrediste;
+	odrediste.x = partikl->x;
+	odrediste.y = partikl->y;
+
+	if(partikl->t <= 0)
+		return;
+
+	SDL_BlitSurface(raketaSprite, NULL, ekran, &odrediste);
+}
+

particle.bmp

Added
New image

pjesma.wav

Binary file added.

raketa.bmp

Added
New image

slika.bmp

Added
New image