1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;
namespace MonsterWorld
{
class homme
{ //propiétés statiques : tous les hommes utilisent les mêmes textures
static private Texture2D textureHomme1;
static private Texture2D textureHommeKO;
static private Texture2D textureMissile;
List<Vector2> listPosMissile = new List<Vector2>();
//chaque homme dispose des propriétés suivantes
private Rectangle posHomme;
//utilisée pour changer les images toutes les 8 exécutions de boucle de jeu
public Rectangle PosHomme
{
get
{ return posHomme; }
}
public homme()
{//constructeur par défaut
//taille du rectangle de l homme
posHomme = new Rectangle(200,0,98,58);
}
static public void LoadGraphicsContent(ContentManager monContent)
{
//charge les textures
textureHomme1 = monContent.Load<Texture2D>("images/homme/ManRight1") as Texture2D;
textureHommeKO = monContent.Load<Texture2D>("images/homme/ManKilled") as Texture2D;
textureMissile = monContent.Load<Texture2D>("images/objects/tire") as Texture2D;
}
public void Update(GamePadState EtatGamePad, KeyboardState EtatClavier, Rectangle ecran)
{//teste l'état du clavier
if (posHomme.X <= 0)//des que la position de l'homme disparait de l'ecran alors on le repositionne a droite
{
posHomme.X = ecran.Width;
}
for (int i = 0; i < listPosMissile.Count; i++)
{
Vector2 v = listPosMissile[i];
if (listPosMissile[i].X< 0) listPosMissile.RemoveAt(i);
v.X++;
listPosMissile[i] = v;
}
if (Keyboard.GetState().IsKeyDown(Keys.Space) && PosHomme.X > 20)
{//si on appuyé sur espace, le personnage fait un bond
listPosMissile.Add(new Vector2(posHomme.X, posHomme.Y));
}
if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
posHomme.X++;
}
if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
posHomme.X--;
}
//controle fleche haut
if (Keyboard.GetState().IsKeyDown(Keys.Down))
{
posHomme.Y++;
}
if (Keyboard.GetState().IsKeyDown(Keys.Up))
{
posHomme.Y--;
}
}
public void Draw(SpriteBatch monSpriteBatch, etatsJeu etat)
{
if (etat == etatsJeu.encours)
{
monSpriteBatch.Draw(textureHomme1, PosHomme, Color.White);
for (int i = 0; i < listPosMissile.Count; i++)
monSpriteBatch.Draw(textureMissile, listPosMissile[i], Color.White);
}
else
{
if (etat == etatsJeu.perdu)
{
monSpriteBatch.Draw(textureHommeKO, PosHomme, Color.White);
}
}
}
public bool collision(monstre lemonstre)
{// détecte une collision entre l'objet homme en cours et lemonstre passé en paramètre
return posHomme.Intersects(lemonstre.PosMonstre);
}
}
} |
Partager