"Space Invader" game - problems with arrays..
"Space Invader" game - problems with arrays..
"Space Invader" game - problems with arrays..
"Space Invader" game - problems with arrays..
"Space Invader" game - problems with arrays..
"Space Invader" game - problems with arrays.. "Space Invader" game - problems with arrays.. "Space Invader" game - problems with arrays.. "Space Invader" game - problems with arrays.. "Space Invader" game - problems with arrays.. "Space Invader" game - problems with arrays.. "Space Invader" game - problems with arrays.. "Space Invader" game - problems with arrays..
"Space Invader" game - problems with arrays.. "Space Invader" game - problems with arrays..
"Space Invader" game - problems with arrays..
Go Back  Xtreme Visual Basic Talk > > > "Space Invader" game - problems with arrays..


Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2007, 08:48 AM
Qunic Qunic is offline
Newcomer
 
Join Date: Nov 2007
Posts: 3
Default "Space Invader" game - problems with arrays..


Hi
I have been starting to make a kind of "Space Invader" game. First I had alot of IF's but then I replaced most of them with arrays. But when I try to run the program I get an error message which sounds something like this: "The object reference has not been indicated to an authority of an object". Hope it makes sense, had to translate it.. But anyway, the part of the code that doesn't work is this:
Code:
Public Class Form1 Inherits System.Windows.Forms.Form Dim i, ii,ok, bossdirection As Integer Dim hit1, hit1s As String Dim life As Integer = 3 Dim points As String Dim countdown1 As Integer = 20 Dim sheepspeed As Decimal = 1 Dim level As Integer = 1 Dim PctSheep(10) As PictureBox Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Randomize() PctSheep(0) = Me.pctSheep1 PctSheep(1) = Me.pctSheep2 PctSheep(2) = Me.pctSheep3 PctSheep(3) = Me.pctSheep4 PctSheep(4) = Me.pctSheep5 PctSheep(5) = Me.pctSheep6 PctSheep(6) = Me.pctSheep7 PctSheep(7) = Me.pctSheep8 PctSheep(8) = Me.pctSheep9 PctSheep(9) = Me.pctSheep10 End Sub Private Sub SheepActivate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SheepActivate.Tick i = i + 1 'THIS PART WORKS ii = ii + 1 PctSheep(i).Enabled = True PctSheep(i).Visible = True PctSheep(i).Left = Int(Rnd() * 747 + 9) PctSheep(i).Top = -72 If i = 9 Then si = 0 End If If ii = 9 Then ii = 0 End If End Sub Private Sub Sheepfall_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Sheepfall.Tick If PctSheep(ii).Enabled = True Then 'BUT NOT THIS PctSheep(ii).Top = PctSheep(ii).Top + sheepspeed If PctSheep(ii).Top = 672 Then life = life - 1 Label1.Text = "Lifes: " & life If life = 0 Then MsgBox("You lost!") Sheepfall.Enabled = False Countdown.Enabled = False PointsTimer.Enabled = False End If PctSheep(ii).Enabled = False PctSheep(ii).Visible = False Else End If End If If (pctShot.Top + 35) < pctSheep(ii).Top Then hit1s = "False" ElseIf pctShot.Top > (pctSheep(ii).Top + 73) Then hit1s = "False" ElseIf (pctShot.Left + 5) < pctSheep(ii).Left Then hit1s = "False" ElseIf pctShot.Left > (pctSheep(ii).Left + 54) Then hit1s = "False" Else : hit1s = "True" End If If (pctSShip.Top + 72) < pctSheep(ii).Top Then hit1 = "False" ElseIf pctSShip.Top > (pctSheep(ii).Top + 73) Then hit1 = "False" ElseIf (pctSShip.Left + 126) < pctSheep(ii).Left Then hit1 = "False" ElseIf pctSShip.Left > (pctSheep(ii).Left + 54) Then hit1 = "False" Else : hit1 = "True" End If If hit1 = "True" Then pctSheep(ii).Enabled = False pctSheep(ii).Visible = False End If If hit1s = "True" Then pctSheep(ii).Enabled = False pctSheep(ii).Visible = False Shot.Enabled = False Shot2.Enabled = True End If End Sub
Can anyone see an obvious error? I've looked through the code several times but I can't see anything that's wrong...
/Qunic

Last edited by passel; 11-12-2007 at 07:54 PM. Reason: added [vb]..[/vb] tags
Reply With Quote
  #2  
Old 11-12-2007, 07:52 PM
passel's Avatar
passel&quot;Space Invader&quot; game - problems with arrays.. passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

In the future, post VB.Net questions in the VB.Net side of the forum.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 11-13-2007, 10:29 AM
John Murray's Avatar
John Murray John Murray is offline
Regular
 
Join Date: Oct 2005
Location: The Netherlands
Posts: 72
Default

I can't find anything here, but I think the problem isn't really here. Perhaps you could post your complete code, or send me your code by e-mail?
__________________
Divide et Impera
Reply With Quote
  #4  
Old 11-13-2007, 01:04 PM
Qunic Qunic is offline
Newcomer
 
Join Date: Nov 2007
Posts: 3
Default

Quote:
Originally Posted by John Murray View Post
I can't find anything here, but I think the problem isn't really here. Perhaps you could post your complete code, or send me your code by e-mail?
Sure, can I send you the whole project instead? I'm using Visual Studio .net 2003

*edit* I tried to run the program in school and it worked fine :S wonder what the problem could be?

Last edited by Qunic; 11-14-2007 at 07:39 AM.
Reply With Quote
  #5  
Old 11-21-2007, 12:09 PM
fixitchris's Avatar
fixitchris fixitchris is offline
Contributor
 
Join Date: Dec 2004
Posts: 418
Default

maybe you're running your project from a networked drive or a share?
Reply With Quote
  #6  
Old 11-28-2007, 02:32 AM
Son of Makuta Son of Makuta is offline
Newcomer
 
Join Date: Sep 2007
Posts: 19
Default

Vista?

On one note I did notice a typo:

Code:
If i = 9 Then si = 0 End If

I'm guessing that should be i = 0 as you don't have a variable called si.

Also, I didn't know you could put existing objects into arrays but maybe that's the problem. Personally I'd have copied and pasted the picture boxes when creating them, you can make an array more easily that way. Alternately you can generate the picture boxes at runtime, or better still use BitBlt or DirectX (you get better animation and efficiency, although you have to make some truly hideous-looking API calls!).

But, probably Vista, different versions of VB, or something similar. What VB edition/version do you have, and what does your school have?
Reply With Quote
  #7  
Old 11-28-2007, 05:49 AM
Qunic Qunic is offline
Newcomer
 
Join Date: Nov 2007
Posts: 3
Default

Quote:
Originally Posted by Son of Makuta View Post
Vista?

On one note I did notice a typo:

Code:
If i = 9 Then si = 0 End If

I'm guessing that should be i = 0 as you don't have a variable called si.

Also, I didn't know you could put existing objects into arrays but maybe that's the problem. Personally I'd have copied and pasted the picture boxes when creating them, you can make an array more easily that way. Alternately you can generate the picture boxes at runtime, or better still use BitBlt or DirectX (you get better animation and efficiency, although you have to make some truly hideous-looking API calls!).

But, probably Vista, different versions of VB, or something similar. What VB edition/version do you have, and what does your school have?
Yeah I saw that typo, it's fixed I don't have vista, and I'm not running it from a network share. But I deleted the timer I had problems with, made a new one and copied the code under the new one. And it worked.. But how do I generate the picturebox at runtime? And can I put it in an array then? And is it hard to use DirectX? Because the program is pretty slow when alot of pictureboxes comes out..
/Qunic
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
&quot;Space Invader&quot; game - problems with arrays..
&quot;Space Invader&quot; game - problems with arrays..
&quot;Space Invader&quot; game - problems with arrays.. &quot;Space Invader&quot; game - problems with arrays..
&quot;Space Invader&quot; game - problems with arrays..
&quot;Space Invader&quot; game - problems with arrays..
&quot;Space Invader&quot; game - problems with arrays.. &quot;Space Invader&quot; game - problems with arrays.. &quot;Space Invader&quot; game - problems with arrays.. &quot;Space Invader&quot; game - problems with arrays.. &quot;Space Invader&quot; game - problems with arrays.. &quot;Space Invader&quot; game - problems with arrays.. &quot;Space Invader&quot; game - problems with arrays..
&quot;Space Invader&quot; game - problems with arrays..
&quot;Space Invader&quot; game - problems with arrays..
 
&quot;Space Invader&quot; game - problems with arrays..
&quot;Space Invader&quot; game - problems with arrays..
 
-->