Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3332916
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:44:21+00:00 2026-05-17T23:44:21+00:00

Recently I’ve been working on a Space Invaders like game, to help me boost

  • 0

Recently I’ve been working on a Space Invaders like game, to help me boost my programming Skills. I’ve fallen into a few problems. I’ve been researching for a few days now, in how you would go about making a laser fire, on keyUp.

This is my attempt so far; I can get the laser to fire, but it has stumbled me why the laser doesn’t carry on moving up…

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace SpaceInvaders
{
    public partial class Form1 : Form
    {
        public int spriteX = 226;
        public int spriteY = 383;
        bool bulletFire = false;
        int fireTimer = 8;
        int laserFired;

        public Form1()
        {
            InitializeComponent();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public void laserFire()
        {       
            //on laser fire i wont the bulle to move up while bullet timer is enabled
            //moving up slowly with set intervals
            while (bulletTimer.Enabled == true)
            {
                PictureBox laser = new PictureBox();
                laser.BackColor = Color.Chartreuse;
                laser.Width = 5;
                laser.Height = 30;
                laserFired = spriteY;
                laserFired = laserFired - 10;
                this.Controls.Add(laser);
                laser.Location = new Point(spriteX, laserFired);
            }
       }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            //Fire bullet
            if (e.KeyCode == Keys.Up)
            {
                bulletFire = true;

                if (bulletFire == true)
                {
                    laserFire();
                    bulletTimer.Enabled = true;
                }
            }

            //Controls Right movement
            if (spriteX <448)
            {
                if (e.KeyCode == Keys.Right)
                {
                    spriteX = spriteX + 20;
                }
            }

            //Controls Left Movement
            if (spriteX > 0)
            {
                if (e.KeyCode == Keys.Left)
                {
                    spriteX = spriteX - 20;
                }
            }

            //Points sprite to new location
            pctSprite.Location = new Point(spriteX, spriteY);
        }

        private void bulletTimer_Tick(object sender, EventArgs e)
        {
            if (fireTimer == 0)
            {
                bulletTimer.Enabled = false;
            }
            else { fireTimer = fireTimer - 1; }
        }
    }
}

Help or advice would be much appreciated thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:44:21+00:00Added an answer on May 17, 2026 at 11:44 pm

    The problem you have is that on every iteration of the loop, you reset the y position of the bullet by writing laserFired = spriteY;

    However, once that is corrected, you will run into another problem: the while loop that moves the laser bullet is only executed in the laserFire method. This means that:

    • While the laser bullet moves, nothing else can move (because the loop only moves the laser)

    • Once the laser bullet stops moving, it will never start moving again (because you cannot go back into the loop without calling laserFire() again.

    You need to have a single game loop that moves everything in your game, instead of having one loop for every moving object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I ran into this error in my web application: java.lang.OutOfMemoryError: PermGen space It's
Recently I have been investigating the possibilities of caching in ASP.NET. I rolled my
Recently, I've been dealing with an error with accessing MAPI via the .NET framework
Recently our site has been deluged with the resurgence of the Asprox botnet SQL
Recently we've been having problems with our LAMP setup and we started to see
Recently Jeff has posted regarding his trouble with database deadlocks related to reading. Multiversion
Recently, I started changing some of our applications to support MS SQL Server as
Recently I had to develop a SharePoint workflow, and I found the experience quite
Recently we got a new server at the office purely for testing purposes. It
Recently, I read an article entitled SATA vs. SCSI reliability . It mostly discusses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.