robs0271
robs0271
CC#
Created by robs0271 on 2/3/2024 in #help
Why targetRadius should be "43"?
public class Game1 : Game { Texture2D target; Vector2 targetPosition; MouseState mouseState; bool mouseReleased = true; int score = 0; const int targetRadius = 43; private GraphicsDeviceManager _graphics; private SpriteBatch _spriteBatch; public Game1() { _graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; IsMouseVisible = true; protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); target = Content.Load<Texture2D>("target"); } protected override void Update(GameTime gameTime) { mouseState = Mouse.GetState(); Vector2 mousePosition = mouseState.Position.ToVector2(); float mouseTargetDist = Vector2.Distance(targetPosition, mousePosition); if (mouseTargetDist < targetRadius && mouseState.LeftButton == ButtonState.Pressed && mouseReleased == true) { score++; mouseReleased = false; } if (mouseState.LeftButton == ButtonState.Released) { mouseReleased = true; } base.Update(gameTime); } protected override void Draw(GameTime gameTime) { Vector2 targetPosition = new Vector2(100, 100); _spriteBatch.Draw(target, new Vector2(targetPosition.X - targetRadius, targetPosition.Y - targetRadius), Color.Aquamarine); _spriteBatch.End(); base.Draw(gameTime); } } }
13 replies
CC#
Created by robs0271 on 2/3/2024 in #help
Why targetRadius should be "43"?
yeah, you are right, actually it is a circle, not a ball
13 replies
CC#
Created by robs0271 on 2/3/2024 in #help
Why targetRadius should be "43"?
No description
13 replies
CC#
Created by robs0271 on 1/30/2024 in #help
Undestand the "0" value on creation of an entity instance
No description
6 replies
CC#
Created by robs0271 on 1/27/2024 in #help
Explanation of the Value parameter in Class constructor
Great!!! Thank you so much @ABOUT ME explains my gameplay !!
16 replies
CC#
Created by robs0271 on 1/27/2024 in #help
Explanation of the Value parameter in Class constructor
No description
16 replies
CC#
Created by robs0271 on 1/27/2024 in #help
Explanation of the Value parameter in Class constructor
Thank you so much for the explanations! These are really useful to me! 🙂
16 replies