I messed up my block moving and can’t fix the stupid mistake, can someone spot it?

This is not the whole code, but I know the error should be in here somewhere. I cut out all the stuff that works for readability (maybe spoiler tags so we can hide huge code chunks like this?) It seems MoveEnemy() does nothing at all. Even when I try to move the enemy manually with enemy.eX += 5; instead of the MoveEnemy() it does nothing. I'm still very new to this so please be gentle 😉

namespace FinalGame { public partial class FormView : Form { // Initialize enemy location variables private int eX, eY; // Initialize all actors Rectangle player, powerUp, enemyRectangle; static Random random = new Random(); // Make an enemy //int amountEnemies = 5; Enemy enemy = new Enemy(); // Choose random enemy x and y speed (moeten geen ints zijn) float enemyxSpeed = random.Next(1, 2); float enemyySpeed = random.Next(1, 2); public FormView() { InitializeComponent(); // Start the enemy location eX = 250; eY = 250; } private void FormView_Paint(object sender, PaintEventArgs e) { // Draw enemies as a red circle e.Graphics.FillRectangle(Brushes.Red, enemyRectangle); } private void tmrMoving_Tick(object sender, EventArgs e) { // Redraw actors enemyRectangle = enemy.getRectangle(eX,eY); // Move the enemy //enemy.MoveEnemy(enemyxSpeed,enemyySpeed); Invalidate(); } public class Enemy { public float eX, eY; public Rectangle enemy; public void MoveEnemy(float eXSpeed, float eYSpeed) { // Move the enemy (not working) eX += eXSpeed; eY += eYSpeed; // Keep the enemies inside the bounds and bounce him off walls if (eX <= 0 || eX >= 1280 - 41) { eXSpeed = -eXSpeed; } if (eY <= 0 || eY >= 720 - 64) { eYSpeed = -eYSpeed; } } public Rectangle getRectangle(int eX, int eY) { Rectangle enemy = new Rectangle(eX, eY, 25, 25); return enemy; } } } 

by feedabeast via /r/csharp

Leave a Reply