Jump to content

[C#] Joculet gen Space Invaders


5061756C
 Share

Recommended Posts

Dowload:

http://www.mediafire...izaccteaz4mzcw6

Virus scan:

https://www.virustot...sis/1348172485/

Cum e jocul ( screenshot ):

http://puu.sh/170oS

 

Ce trebuie să faci ?

 

Pai esti o cutie si niste troli cad spre tine. Viteza lor creşte in continuu, si sunt maxim 3.

Cand te atinge unul viaţa ta scade.

 

Te mişti cu săgeţiile.

 

Spuneţi ce scor aţi facut :P

 

Tot programul făcut in XNA.

 

*le sursa:

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Martienii
{
   public class Game1 : Microsoft.Xna.Framework.Game
   {
       GraphicsDeviceManager graphics;
       SpriteBatch spriteBatch;
       Texture2D background; // backgroundul
        Texture2D background2; // backgroundul
       Texture2D p_tex;
       Texture2D trol3;
       Vector2 p_poz;
       Texture2D trol2;
       Vector2 t2_poz;
       SpriteFont font1;
       Vector2 t1_poz;
       Texture2D trol1;
       Texture2D t2;
       Vector2 tpos;
       Texture2D viata;
       Vector2 vpos;
       private Vector2 origin;
       private Vector2 screenpos;
       Vector2 t3_poz;
       private float RotationAngle;
       public Game1()
       {
           graphics = new GraphicsDeviceManager(this);
           Content.RootDirectory = "Content";
           graphics.PreferredBackBufferHeight = 700;
           graphics.PreferredBackBufferWidth = 700;
       }
       int timp = 0;
       protected override void Initialize()
       {

           base.Initialize();
       }
       bool tr3 = false;
      int az=0;
       protected override void LoadContent()
       {
           viata = Content.Load<Texture2D>("viata");
           vpos = new Vector2(23,240);
           t2 = Content.Load<Texture2D>("tip");
           tpos = new Vector2(400, 400);
           trol3=Content.Load<Texture2D>("trol");
           Viewport viewport = graphics.GraphicsDevice.Viewport;
           origin.X = trol3.Width / 2;
           origin.Y = trol3.Height / 2;
           screenpos.X = viewport.Width / 2;
           screenpos.Y = viewport.Height / 2;


           t3_poz = new Vector2(r.Next(276, 600), 1);
           t1_poz = new Vector2(400, 1);
           trol1 = Content.Load<Texture2D>("trol");
           t2_poz = new Vector2(r.Next(276, 600), 1);
           trol2 = Content.Load<Texture2D>("troli");
           background = Content.Load<Texture2D>("bg");

           background2 = Content.Load<Texture2D>("bg2");
           p_poz = new Vector2(400, 400);
           p_tex = Content.Load<Texture2D>("tip");
           font1 = Content.Load<SpriteFont>("font1");
           spriteBatch = new SpriteBatch(GraphicsDevice);

       }
       int viteza1 = 0;
       int viteza2 = 1;
       int viteza3 = 2; 
       Random r = new Random();
       int scor = 0; int frame = 0;
       protected override void UnloadContent()
       {

       }
       bool tr2 = false;
       int ture3 = 0;

       int ture1 = 0; int ture2 = 0;
       float speed = 0.01f;
       bool over = false;
       protected override void Update(GameTime gameTime)
       {
           if (over == false)
           {

               if ((p_poz.X >= t1_poz.X - 30 && p_poz.X <= t1_poz.X + 30) && (p_poz.Y >= t1_poz.Y - 30 && p_poz.Y <= t1_poz.Y + 30))
                   vpos.X -= 5;

               if ((p_poz.X >= t2_poz.X - 30 && p_poz.X <= t2_poz.X + 30) && (p_poz.Y >= t2_poz.Y - 30 && p_poz.Y <= t2_poz.Y + 30))
                   vpos.X -= 5;

               if ((p_poz.X >= t3_poz.X - 30 && p_poz.X <= t3_poz.X + 30) && (p_poz.Y >= t3_poz.Y - 30 && p_poz.Y <= t3_poz.Y + 30))
                   vpos.X -= 5;
           }
           if (vpos.X <= -185)
           {
               over = true;
               az++;
               if (az == 1)
                   timp = gameTime.TotalGameTime.Seconds;
               vpos.X = -500;
           }

           if (over == false)
           {


               #region rotate
               float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

               // TODO: Add your game logic here.
               if ((int)gameTime.TotalGameTime.Seconds % 2 == 0)
                   speed += 0.01f;
               RotationAngle += speed;
               #endregion
               if (scor > 20)
                   tr2 = true;
               if (scor >= 50)
                   tr3 = true;

               if ((int)gameTime.TotalGameTime.Milliseconds % 100 == 0)
               {
                   frame++;
                   switch (frame)
                   {
                       case 1: trol2 = Content.Load<Texture2D>("trol");
                           break;
                       case 2: trol2 = Content.Load<Texture2D>("troli");
                           frame = 0;
                           break;
                   }
               }

               if (t1_poz.Y > 650)
               {
                   t1_poz.Y = 1;
                   ture1++;
                   if (ture1 > 5)
                   {
                       if (ture1 % 2 == 0)
                           viteza1 += 1;
                   }
                   else

                       viteza1 += 1;
                   t1_poz.X = r.Next(276, 600);
                   scor += 10;
               }
               t1_poz.Y += 1 + viteza1;

               if (tr2 == true)
               {

                   if (t2_poz.Y > 650)
                   {
                       t2_poz.Y = 1;
                       ture2++;
                       if (ture2 > 5)
                       {
                           if (ture2 % 2 == 0)
                               viteza2 += 1;
                       }
                       else

                           viteza2 += 1;
                       t2_poz.X = r.Next(276, 600);
                       scor += 15;
                   }


                   t2_poz.Y += 1 + viteza2;
               }
               if (tr3 == true)
               {

                   if (t3_poz.Y > 650)
                   {
                       t3_poz.Y = 1;
                       ture3++;
                       if (ture3 > 5)
                       {
                           if (ture3 % 2 == 0)
                               viteza3 += 1;
                       }
                       else

                           viteza3 += 2;
                       t3_poz.X = r.Next(276, 600);
                       scor += 15;
                   }


                   t3_poz.Y += 1 + viteza3;
               }
               if (Keyboard.GetState().IsKeyDown(Keys.Up))
               {
                   if (p_poz.Y >= 41)
                       p_poz.Y -= 2;
               }
               if (Keyboard.GetState().IsKeyDown(Keys.Down))
               {
                   if (p_poz.Y <= 628)
                       p_poz.Y += 2;
               }
               if (Keyboard.GetState().IsKeyDown(Keys.Right))
               {
                   if (p_poz.X <= 614)
                       p_poz.X += 2;
               }
               if (Keyboard.GetState().IsKeyDown(Keys.Left))
               {
                   if (p_poz.X >= 276)
                       p_poz.X -= 2;
               }

               if (Keyboard.GetState().IsKeyDown(Keys.W))
               {

                   vpos.Y -= 1;
               }
               if (Keyboard.GetState().IsKeyDown(Keys.S))
               {

                   vpos.Y += 1;
               }
               if (Keyboard.GetState().IsKeyDown(Keys.D))
               {

                   vpos.X += 1;
               }
               if (Keyboard.GetState().IsKeyDown(Keys.A))
               {

                   vpos.X -= 1;
               }


               base.Update(gameTime);
           } 
           if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                   this.Exit();
       }
       protected override void Draw(GameTime gameTime)
       {
           GraphicsDevice.Clear(Color.CornflowerBlue);
           // --------------- BG 1 ------------------
           spriteBatch.Begin();
           spriteBatch.Draw(viata, vpos, Color.White);
           spriteBatch.End();


           spriteBatch.Begin();
           spriteBatch.Draw(background, new Vector2(1, 1), Color.White);
           spriteBatch.End();

           if (over == false)
           {
               // -------------- TROL1 --------------
               spriteBatch.Begin();
               spriteBatch.Draw(trol1, t1_poz, Color.White);
               spriteBatch.End();
               // -------------- TROL2 --------------
               if (tr2 == true)
               {
                   spriteBatch.Begin();
                   spriteBatch.Draw(trol2, t2_poz, Color.White);
                   spriteBatch.End();
               }
               if (tr3 == true)
               {
                   spriteBatch.Begin();
                   spriteBatch.Draw(trol3, t3_poz, null, Color.White, RotationAngle,
                       origin, 1.0f, SpriteEffects.None, 0f);
                   spriteBatch.End();
               }
           }
           // --------------- BG 2 ------------------
           spriteBatch.Begin();
           spriteBatch.Draw(background2, new Vector2(1, 1), Color.White);
           spriteBatch.End();
           // ----------------------------------------
           if (over == false)
           {
               spriteBatch.Begin();
               spriteBatch.Draw(p_tex, p_poz, Color.White);
               spriteBatch.End();
           }

           // -------------- COORDONATELE -----------
           string a;
           if(over==false)
            a = "X: " + p_poz.X.ToString() + " Y: " + p_poz.Y.ToString() + Environment.NewLine + "Scor: " + scor.ToString();
           else
               a = "X: " + p_poz.X.ToString() + " Y: " + p_poz.Y.ToString() + Environment.NewLine + "Scor: " + scor.ToString()+Environment.NewLine+"Scor Final: "+scor.ToString()+Environment.NewLine+"Timp: "+timp.ToString()+" secunde.";

           spriteBatch.Begin();
           spriteBatch.DrawString(font1, a, new Vector2(1, 1), Color.White);
           spriteBatch.End();




           base.Draw(gameTime);
       }
   }
}
 

 

Edited by eB Teodor
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.