Jump to content

[C#] Jumping ball


5061756C
 Share

Recommended Posts

Eşti o bilă saritoare, trebuie să eviţi o cutie ce vine spre tine.

Foloseşti săgeţi stânga / dreapta pentru a te mişca , F2 pentru joc nou, Escape pentru a ieşi din joc.

Când loveşti cutia pierzi jocul şi apare pe ecran textul " Ai pierdut : (" şi scorul reusit.

Ca să faci scor trebuie să sari peste cutie , la fiecare săritură primeşti 2000p în plus, de asemenea primeşti puncte şi pe timpul jucat.

 

Cu cât trece timpul cutia este mai rapidă.

 

Cum arată jocul ( gif ) :

http://puu.sh/19E7x

 

Random screenshots:

 

 

 

 

Jumping_Ball_2012_09_29_11_23_36_43.jpg

 

Jumping_Ball_2012_09_29_11_23_38_31.jpg

 

Jumping_Ball_2012_09_29_11_23_46_00.jpg

 

Jumping_Ball_2012_09_29_11_23_47_17.jpg

 

Jumping_Ball_2012_09_29_11_23_48_24.jpg

 

Jumping_Ball_2012_09_29_11_24_03_34.jpg

 

O_Minge_2012_09_29_11_06_21_67.jpg

 

 

 

 

 

 

 

 

 

 

 

 

Download

http://www.mediafire...2x6lkd9ukxl5bl0

Scan:

https://www.virustotal.com/file/89bfcbe73501348c91be5adf1a56cf22f218523d9b1dc03623d402b4f3d2ffb8/analysis/1348907309/

 

 

 

 

Cod:

 

 

 

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 O_Minge
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
SpriteFont font3;

Rectangle re_minge;
Rectangle re_box;
Texture2D b;
Vector2 bp;
Texture2D m;
Vector2 p;
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Color[] mingedata;
public Color[] boxdata;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.PreferredBackBufferHeight = 600;
graphics.PreferredBackBufferWidth = 800;

}

/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();
}

/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
/// sprite
/// sp
///
Texture2D stea_t;
Vector2 stea_v;
Rectangle stea_r;
Color[] stea_c;
SpriteFont font;
Texture2D str;
Vector2 strp;
Texture2D dun;
Vector2 dunp;
Texture2D d2;
Vector2 d2p;
int x;
int y;
Vector2 mp;
Texture2D mu;
SoundEffect bounce; Viewport viewport;


//
static bool Pix(Rectangle rect1,Color[] data1,Rectangle rect2,Color[] data2)
{
int Top = Math.Max(rect1.Top, rect2.Top);
int Bottom = Math.Min(rect1.Bottom, rect2.Bottom);
int Left = Math.Max(rect1.Left, rect2.Left);
int Right = Math.Min(rect1.Right, rect2.Right);

for (int y = Top; y < Bottom; y++)
for (int x = Left; x < Right; x++)
{
Color color1=data1[(x-rect1.Left) + (y- rect1.Top) * rect1.Width];
Color color2 = data2[(x - rect2.Left) + (y - rect2.Top) * rect2.Width];
if (color1.A != 0 && color2.A != 0)
return true;
}
return false;
}
bool stea_b = false;
protected override void LoadContent()
{


// minge
font3 = Content.Load<SpriteFont>("hua");


stea_t = Content.Load<Texture2D>("stea");
stea_v = new Vector2(823, 433);
stea_c = new Color[stea_t.Width * stea_t.Height];
stea_t.GetData(stea_c);
stea_r = new Rectangle((int)stea_v.X, (int)stea_v.Y, stea_t.Width, stea_t.Height);
viewport = graphics.GraphicsDevice.Viewport;
bounce = Content.Load<SoundEffect>("ba");
strp = new Vector2(-20, 500);
mp = new Vector2(-22, 107);
dunp = new Vector2(392, 530);
d2p = new Vector2(-195, 530);
str = Content.Load<Texture2D>("str");
mu = Content.Load<Texture2D>("munt");
dun = Content.Load<Texture2D>("dun");
d2 = Content.Load<Texture2D>("dun");
font=Content.Load<SpriteFont>("font");
x = 300;
y = 500;
bg = Content.Load<Texture2D>("b2");
bp = new Vector2(905, 500);
b = Content.Load<Texture2D>("box");
p = new Vector2(x, y);
m = Content.Load<Texture2D>("minge");
re_minge = new Rectangle((int)p.X, (int)p.Y, m.Width, m.Height);
gra = Content.Load<Texture2D>("gr");
re_box = new Rectangle((int)bp.X, (int)bp.Y, b.Width, b.Height);
minge = new Rectangle((int)p.X, (int)p.Y, m.Width,m.Height);
cutie = new Rectangle((int)bp.X, (int)bp.Y, b.Width,b.Height);
mingedata = new Color[m.Height * m.Width];
m.GetData(mingedata);
boxdata = new Color[b.Height * b.Width];
b.GetData(boxdata);
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
font2 = Content.Load<SpriteFont>("SpriteFont1");
// TODO: use this.Content to load your game content here
}

/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
///

int vit = 5;
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}


/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
///
bool jos = false;
bool aer = false;
int i = 1;
Texture2D bg;
int q = 0;
Rectangle minge;
Rectangle cutie;

int scor = 0;
bool gameover = false; bool mda =true;
bool text = false; int sw = 1;
float t1, t2; float dv;
int inaltime = 100;
Texture2D gra;

int ture = 0;
float tt1, tt2, dv2;
int sw2; bool gr = false; bool aha = true;
protected override void Update(GameTime gameTime)
{


if(Keyboard.GetState().IsKeyDown(Keys.F2))
{
gr = false;
mda = true;
inaltime = 100;

stea_b = false;
ture = 0;
i = 1;
gameover = false;
scor = 0;
LoadContent(); vit = 5;
}
re_minge = new Rectangle((int)p.X, (int)p.Y, m.Width, m.Height);
stea_r = new Rectangle((int)stea_v.X, (int)stea_v.Y, stea_t.Width, stea_t.Height);
re_box = new Rectangle((int)bp.X, (int)bp.Y, b.Width, b.Height);

if (Pix(re_minge, mingedata, re_box, boxdata))
{
gameover = true;
}



if (Keyboard.GetState().IsKeyDown(Keys.Escape))
this.Exit();


if (!gameover)
{







if (sw == 0)
{
dv = gameTime.TotalGameTime.Milliseconds;
t1 = gameTime.TotalGameTime.Seconds + dv / 1000;
sw = 1;


}

dv = gameTime.TotalGameTime.Milliseconds;
t2 = gameTime.TotalGameTime.Seconds + dv / 1000;

if (t1 + 1 == t2)
{
text = false;
}

scor += 1;

minge = new Rectangle((int)p.X, (int)p.Y, m.Width, m.Height);
cutie = new Rectangle((int)bp.X, (int)bp.Y, b.Width, b.Height);

if (minge.Left >= cutie.Right)
{
if (mda)
{
ture++;
if (ture == 3)
stea_b = true;
vit++;
sw = 0;
text = true;

scor += 1000;
mda = false;
}

}
#region aa
else
mda = true;


if (bp.X > -103)
bp.X -= vit;
else
bp.X = 803;

if (dunp.X > -418)
dunp.X -= 5;
else
dunp.X = 803;

if (d2p.X > -418)
d2p.X -= 5;
else
d2p.X = 803;


if (i == 1)
{
if (mp.X > -613)
mp.X -= 4;
else
{
i = 2;
mp.X = 803;
mp.Y = 185;
mu = Content.Load<Texture2D>("casa");

}

}

if (i == 2)
{
if (mp.X > -382)
mp.X -= 4;
else
{
i = 3;
mp.X = 812;
mp.Y = 128;
mu = Content.Load<Texture2D>("reclama");

}

}
if (i == 3)
{
if (mp.X > -541)
mp.X -= 4;
else
{
i = 1;
mp.X = 791;
mp.Y = 107;
mu = Content.Load<Texture2D>("munt");

}

}

#endregion
#region saritul

if (p.Y >= y)
{
jos = true;
p.Y = y;
aer = false;
}

if (jos)
{
if (q == 0)
{
bounce.Play();
q = 1;
}

if (p.Y < y - inaltime - 30 && p.Y > y - inaltime)
p.Y -= 2;
else
p.Y -= 5;

}

if (p.Y < y - inaltime)
{
aer = true; jos = false;
}

if (aer)
{
q = 0;
p.Y += 5;
}

#endregion
#region misc


if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
if (p.X > 0)
p.X -= 3;
}
if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
if (p.X < 755)
p.X += 3;
}
if (Keyboard.GetState().IsKeyDown(Keys.A))
{

stea_v.X -= 3;
}
if (Keyboard.GetState().IsKeyDown(Keys.D))
{

stea_v.X += 3;
}

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

stea_v.Y -= 3;
}
if (Keyboard.GetState().IsKeyDown(Keys.S))
{

stea_v.Y += 3;
}

#endregion

}
// TODO: Add your update logic here

base.Update(gameTime);
}

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
///

SpriteFont font2;
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();






spriteBatch.Draw(bg, new Vector2(1, 1), Color.White);spriteBatch.Draw(mu, mp, Color.White);
spriteBatch.Draw(str, strp, Color.White);
spriteBatch.Draw(dun, dunp, Color.White);

spriteBatch.Draw(d2, d2p, Color.White);

spriteBatch.Draw(m, p, Color.Wheat);
if(stea_b)
spriteBatch.Draw(stea_t, stea_v, Color.AliceBlue);
spriteBatch.Draw(b, bp, Color.Wheat);
spriteBatch.DrawString(font, "Scor: " + scor.ToString() , new Vector2(1, 1), Color.Violet);
if (text)
spriteBatch.DrawString(font3, "+1000p", new Vector2(p.X-45,p.Y-100), Color.Aqua);
if (gameover)
spriteBatch.DrawString(font2, "Ai pierdut  "+Environment.NewLine+"Scor: "+scor.ToString(), new Vector2(100, 100), Color.DarkBlue);

spriteBatch.End();
// TODO: Add your drawing code here

base.Draw(gameTime);
}

}
}
 

 

 

Păreri :D ?

Edited by eB Teodor
Link to comment
Share on other sites

Fă astfel încât după ce pierzi jocul dacă apeşi orice tastă să începi din nou.. E naşpa, prima mea tendinţă a fost să închid jocul şi să îl deschid la loc decât să apăs F2.

 

În rest felicitări, îmi place, şi se vede că ai muncit mult la el.

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.