Bonjour,
Je n'ai c'est pas si je suis au bonne endroit mais j'ai un soucis je suis entrain de faire un jeux avec MonoGame est dans mon jeux mon Joueur doit tirer sauf que le soucis c'est que les balle ce dessine est ce créer mais elle ne bouge pas ça fait un jour que j'y suis deçu es ce que quelqu'un aurez une soulution
Player.cs
Bullet.cs
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace Human_VS_Alien_second_version { public class Player : EntityManager { // FIELDS float rotatePlayer; CollisionManager collision; List<Bullet> bullets; // CONSTRUCTOR public Player() : base(100,92,92,32,32,5.0f,"Player") { this.rotatePlayer = rotate; collision = new CollisionManager(); bullets = new List<Bullet>(); } // CONTENT public override void LoadContent(ContentManager content) { base.LoadContent(content); } // UPDATE & DRAW public override void Update(GameTime gameTime, InputManager input, Game1 game) { base.Update(gameTime, input, game); collision.CollisionWWidthE(this, game); Console.WriteLine("X : " + this.x + ";Y : " + this.y); rotate = input.GetMouseX() / 100; rotate = input.GetMouseY() / 100; float Circle = MathHelper.Pi * 2; rotate = rotate % Circle; if (input.IsKeyDown(Keys.Z) || input.IsKeyDown(Keys.W)) { y -= speed; } if (input.IsKeyDown(Keys.S)) { y += speed; } if (input.IsKeyDown(Keys.Q) || input.IsKeyDown(Keys.A)) { x -= speed; } if (input.IsKeyDown(Keys.D)) { x += speed; } foreach (Bullet bullets in new List<Bullet>(this.bullets)) { bullets.Update(gameTime, input); } if (input.IsKeyDown(Keys.Up)) { Console.WriteLine("TIRE HAUT"); this.bullets.Add(new Bullet(this.x + 3, this.y + 3, 9, 16, "HAUT", "_Haut")); } if (input.IsKeyDown(Keys.Down)) { Console.WriteLine("TIRE BAS"); this.bullets.Add(new Bullet(this.x + 3, this.y + 3, 9, 16, "DOWN", "_Bas")); } if (input.IsKeyDown(Keys.Left)) { Console.WriteLine("TIRE GAUCHE"); this.bullets.Add(new Bullet(this.x + 3, this.y + 3, 16, 9, "LEFT", "_Gauche")); } if (input.IsKeyDown(Keys.Right)) { Console.WriteLine("TIRE DROITE"); this.bullets.Add(new Bullet(this.x + 3, this.y + 3, 16, 9, "RIGHT", "_Droite")); } } public override void Draw(SpriteBatch spriteBatch) { foreach (Bullet bullets in this.bullets) { bullets.Draw(spriteBatch); } base.Draw(spriteBatch); } } }
InputManager.cs
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace Human_VS_Alien_second_version { public class Bullet : DropAndProjectilesBase { // FIELDS public Rectangle hitbox; private float x, y, w, h; string direction; int time; CollisionManager collision; public int X { get { return (int)this.x; } } public int Y { get { return (int)this.y; } } public int Width { get { return (int)this.w; } } public int Height { get { return (int)this.h; } } // CONSTRUCTOR public Bullet(float x, float y, float w, float h, string direction, string orient) : base(x,y,w,h,10.0f,"Bullets"+ orient) { this.hitbox = new Rectangle((int)x, (int)y, 16, 9); this.x = x; this.y = y; this.w = w; this.h = h; this.direction = direction; } // UPDATE & DRAW public override void Update(GameTime gameTime, InputManager input) { if (direction == "UP") { this.y -= speed; } else if (direction == "DOWN") { this.y += speed; } else if (direction == "LEFT") { this.x -= speed; } else if (direction == "RIGHT") { this.x += speed; } base.Update(gameTime, input); } public override void Draw(SpriteBatch spriteBatch) { base.Draw(spriteBatch); } } }
Merci pour vos réponse
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Human_VS_Alien_second_version { public class InputManager { // FIELDS private KeyboardState keyboard; private MouseState mouse; private KeyboardState oldKeyboard; private MouseState oldMouse; public float GetMouseX() { return this.mouse.X; } public float GetMouseY() { return this.mouse.Y; } public InputManager(KeyboardState keyboard, MouseState mouse, KeyboardState oldKeyboard, MouseState oldMouse) { this.mouse = mouse; this.keyboard = keyboard; this.oldMouse = oldMouse; this.oldKeyboard = oldKeyboard; } public bool IsKeyDown(Keys key) { return this.keyboard.IsKeyDown(key); } public bool IsKeyUp(Keys key) { return this.keyboard.IsKeyUp(key); } public bool IsKey(Keys key) { return this.oldKeyboard.IsKeyUp(key) && this.keyboard.IsKeyDown(key); } public bool IsLeftMouseDown() { return this.mouse.LeftButton == ButtonState.Pressed; } public bool IsLeftMousePressed() { return this.oldMouse.LeftButton == ButtonState.Pressed && this.mouse.LeftButton == ButtonState.Released; } public Point GetMousePosition() { return new Point(this.mouse.X, this.mouse.Y); } public Vector2 GetMousePositionv() { return new Vector2(this.mouse.X, this.mouse.Y); } } }
Partager