Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Module Issue
#1
Since the code I had for my previous game was too messy and I didn't understand the half of it, I decided to start from scratch again and to try to understand the code snippets you gave me. I decided to use Modules to make Bullets and Enemies, but now I am facing a new problem. I cannot add the bullets and enemies to the screen since I cannot use Controls.Add(Bullet) method. I tried to declare a variable as Form1.ControlCollection, but that did not work. If that is not possible, please inform me.

Thank you!
Also known as Rocketalypse.
System.out.println("I prefer Java.");
#2
Well, a module is not what you want to use. Instead of using a module, you are going to want to use a class to create Bullets and Enemies. Inside of this class, you are going to store everything that pertains to these bullets and enemies. So, for example, I will outline the bullet class. In theory, each bullet should have an image, a position, a size, and a damage modifier. So, we could create a class for it with those properties. So, to start:
[code2=vbnet]Public Class Bullet
'Location
Private _x As Integer
Private _y As Integer

'Size
Private _width As Integer
Private _height As Integer

'Image
Private _image As Image

'Damage
Private _damage As Integer

End Class[/code2]

So, then you need to make a constructor, and property methods for those variables.
My Blog | My Setup | My Videos | Have a wonderful day.
#3
I thought the only difference between Class and Module was making an object to call the class from form. Alright. I will try to do what you told me.

Thank you!


EDIT #1:
I actually don't know where to start. I made a method Public Sub setLocation(ByVal x1 As Integer, ByVal x2 As Integer, ByVal y1 As Integer, ByVal y2 As Integer), but I am not sure if it is good since I am really confused. Could you give me an example? It would be much appreciated.
Also known as Rocketalypse.
System.out.println("I prefer Java.");
#4
You're definitely starting at the right point! So, here is a nice example of a somewhat completed Bullet class. If you have any questions, feel free to ask!

[code2=vbnet]Public Class Bullet
'Location
Private _x As Integer
Private _y As Integer

'Size
Private _width As Integer
Private _height As Integer

'Image
Private _image As Image

'Damage
Private _damage As Integer

Public ReadOnly Property X As Integer
Get
Return _x
End Get
End Property
Public ReadOnly Property Y As Integer
Get
Return _y
End Get
End Property

Public ReadOnly Property Width As Integer
Get
Return _width
End Get
End Property
Public ReadOnly Property Height As Integer
Get
Return _height
End Get
End Property

Public ReadOnly Property Image As Image
Get
Return _image
End Get
End Property

Public ReadOnly Property Damage As Integer
Get
Return _damage
End Get
End Property

Public Sub New(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal image As Image, ByVal damage As Integer)
'This is the constructor, all information needs to be set
_x = x
_y = y

_width = width
_height = height

_image = image

_damage = damage
End Sub

Public Sub SetLocation(ByVal x As Integer, ByVal y As Integer)
'This method sets the location
_x = x
_y = y
End Sub

Public Sub SetSize(ByVal width As Integer, ByVal height As Integer)
'This method sets the size
_width = width
_height = height
End Sub

Public Sub SetDamage(ByVal dmg As Integer)
'This method sets the damage
_damage = dmg
End Sub

Public Sub SetImage(ByVal image As Image)
'This method sets the image
_image = image
End Sub

Public Sub Move(ByVal direction As Integer)
If (direction = 1) Then
'The bullet moves up
Me._y -= 1
Else
'The bullet moves down
Me._y += 1
End If
End Sub
End Class[/code2]

Now, this is just for keeping track of information. If you want to actually add it to the form, you're going to want to have the class inherit a picturebox. If you have any questions on doing that, just ask! I may make a tutorial about doing something like this soon.
My Blog | My Setup | My Videos | Have a wonderful day.
#5
Well, the only thing I know is that I have to type Inherits Picturebox and then I get some warnings that I need to overload something.. duh. Haha.

I have two bullets with two separate images which are launched in the same time, so I have to make two bullets in one class, I guess.

I feel a bit embarrassed because I decided to make a game, but basically know nothing about making it. Mweh. Regarding the fact that this is my first 2D game, it is allowed, I guess.

EDIT #1:
I found out a simple way of shooting a bullet, but I would really like to know this way, through class. Although, in the first version of the game, I will use that simple way.
Also known as Rocketalypse.
System.out.println("I prefer Java.");
#6
That's alright! Making a game is complicated! I have never actually made a game in VB.NET, so I don't know what to do either, really. I just uploaded a tutorial on how to inherit a picturebox if you are having problems, still.

<!-- m --><a class="postlink" href="http://www.youtube.com/watch?v=rY3nDOaD878">http://www.youtube.com/watch?v=rY3nDOaD878</a><!-- m -->

We can figure this out!
My Blog | My Setup | My Videos | Have a wonderful day.
#7
Thank you for making this tutorial!

Since the simple way is limiting my options and creativity, I am going to follow your tutorial and hopefully I will succeed. Once again, thanks for the tutorial!

Edit #1:
This simply won't work. I suppose I am doing something wrong.[code2=vbnet]Public Sub shootBulletL()
Dim b As System.Drawing.Image = My.Resources.Player_Left_Bullet
' Image has been already set inside the Left_Bullet class.
Dim Bullet(145, 400, b.Width, b.Height, 5, 1) As Left_Bullet
Me.Controls.Add(Bullet)
End Sub[/code2]
Microsoft Visual Studio Wrote:Error 5 Value of type '6-dimensional array of Windows_Forms_Application.Left_Bullet' cannot be converted to 'System.Windows.Forms.Control'. C:\Documents and Settings\Owner\my documents\visual studio 2010\Projects\Shooter\Shooter\Forms\Form1.vb 106 25 Shooter
Also known as Rocketalypse.
System.out.println("I prefer Java.");
#8
I think that you should be doing something like this:

[code2=vbnet]Dim Bullet As Left_Bullet = New Left_Bullet((145, 400, b.Width, b.Height, 5, 1))[/code2]

Please correct me if I am wrong!
My Blog | My Setup | My Videos | Have a wonderful day.
#9
This fixed an error. Now I have to figure out the rest. Thanks!

Edit #1:
The class is almost identical to the one you've written. However, the bullet doesn't shows up on the screen.[code2=vbnet]Public Sub shootBulletL()
Dim b As System.Drawing.Image = My.Resources.Player_Left_Bullet
Dim Bullet As Left_Bullet = New Left_Bullet((Me.ClientRectangle.Width / 2), (Me.ClientRectangle.Height / 2), b.Width, b.Height, 5, 1)
Bullet.Visible = True
Me.Controls.Add(Bullet)
End Sub[/code2]
Also known as Rocketalypse.
System.out.println("I prefer Java.");
#10
Hm, and the image that you have set for the picturebox itself is indeed My.Resources.Player_Left_Bullet?
My Blog | My Setup | My Videos | Have a wonderful day.
#11
Yes. I've set it in the middle of the screen for testing purposes and it doesn't work.
Also known as Rocketalypse.
System.out.println("I prefer Java.");
#12
Hm, well that's not good! Assuming that you are calling the right method and everything, it should work fine.. I don't know where the problem is! <!-- s:? --><img src="{SMILIES_PATH}/icon_e_confused.gif" alt=":?" title="Confused" /><!-- s:? -->
My Blog | My Setup | My Videos | Have a wonderful day.
#13
Alright. I will take a look at the code and try to make it to work. Hm.
Also known as Rocketalypse.
System.out.println("I prefer Java.");
#14
Alright. If need be, go ahead and upload your project here and I can take a detailed look at it.
My Blog | My Setup | My Videos | Have a wonderful day.
#15
Oh! Okay. I will upload it when I get home in about three hours maximum. <!-- sSmile --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt="Smile" title="Smile" /><!-- sSmile -->

Edit #1:
Not available anymore.
Also known as Rocketalypse.
System.out.println("I prefer Java.");
#16
The problem lies within your Left_Bullet class. Since the bullet inherits a picturebox, It already has the properties of Image, Width, and Height, so you do not need to make your own versions of those properties.

With that being said, you never actually set the image of the picturebox to be the bullet image. So in your constructor for the Left_Bullet class (Public Sub New()), you need to add this line of code:
[code2=vbnet]Me.Image = My.Resources.Player_Left_Bullet[/code2]
My Blog | My Setup | My Videos | Have a wonderful day.
#17
[code2=vbnet]Public Sub New(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal speed As Integer, ByVal damage As Integer)
_x = x
_y = y

_width = width
_height = height

Me.Image = My.Resources.Player_Left_Bullet ' Property 'Image' is 'ReadOnly'.

_speed = speed

_damage = damage
End Sub[/code2]
Microsoft Visual Studio Wrote:Error 4 Property 'Image' is 'ReadOnly'. C:\Documents and Settings\Owner\my documents\visual studio 2010\Projects\Shooter\Shooter\Custom Controls\Left_Bullet.vb 70 9 Shooter
Also known as Rocketalypse.
System.out.println("I prefer Java.");
#18
brandonio21 Wrote:It already has the properties of Image, Width, and Height, so you do not need to make your own versions of those properties.
Sorry, I should have specified further on the issue. You're going to need to delete the "Public ReadOnly Property"s for Width, Height, and Image that you have in your class.
My Blog | My Setup | My Videos | Have a wonderful day.
#19
brandonio21 Wrote:It already has the properties of Image, Width, and Height, so you do not need to make your own versions of those properties.
I didn't quite understood what you meant, but now I do.

Thanks!
Also known as Rocketalypse.
System.out.println("I prefer Java.");


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dual Menu Strip Issue Moldraxian 3 16,860 08-15-2012, 12:36 PM
Last Post: brandonio21
  MySQL Database Issue Moldraxian 7 29,070 08-13-2012, 08:58 PM
Last Post: brandonio21
  Remove Enemy [Game Issue] Vinwarez 3 14,548 07-14-2012, 02:15 PM
Last Post: brandonio21
  Launching Projectile [Game Issue] Vinwarez 11 33,525 07-13-2012, 03:29 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)