Xtreme
02-05-2002, 11:18 AM
I am programming a mario type game and am at the point of putting enemies on scree. Well i want to do it so that first the map is read into an array. When the map is being read if it comes accross the symbol for an enemy it creates a new class object with the starting coordinates and the starting direction of the enemy. Now this object will be called within my main game loop to tell all the enemies that have been created to move and so on.
Now here's my goal: I needs each new enemy to be a seperate object so that each one has their own x, y, direction, speed and so on variables that will be affected differently for each one. Here is my code ---symplified
''This is in a module
Public BadGuy(100) As Enemy
Public bcounter as integer
'''Now when i read the file and come to the symbol representing an enemy then ''''''''''''''''''''''
Set BadGuy(bcounter) = New Enemy
BadGuy(bcounter).Initialize_Values (i * 32), (P * 32), 2
bcounter = bcounter + 1
'''Now in my main sub after i draw all of the tiles on screen i
Dim i As Integer
For i = 0 To bcounter
BadGuy(i).go
Next i
''''alright I hope everyone still understands what is going on. Now for the actual class!
Private x As Single
Private y As Single
Private direction As Byte
Private jumping As Boolean
Private speed As Integer
Sub Initialize_Values(user_x As Single, user_y As Single, user_speed As Integer)
speed = user_speed
x = user_x
y = user_y
direction = 0
jumping = False
End Sub
Private Sub Move(tile_map As tile)
Debug.Print y
If tile_map.map(Int(y / 32) + 1, Int(x / 32)).solid = False And tile_map.map(Int(y / 32) + 1, Int(x / 32)).platform = False And jumping = False Then
y = y + speed
End If
If tile_map.map(Int((y + 2) / 32), Int(x / 32)).solid = True Then
direction = 1
End If
If tile_map.map(Int((y + 2) / 32), Int((x / 32) + 1)).solid = True Then
direction = 0
End If
If direction = 1 Then
x = x + speed
End If
If direction = 0 Then
x = x - speed
End If
draw_enemy
End Sub
Public Sub go()
Move game
End Sub
Public Sub draw_enemy()
extraRECT.Top = 32
extraRECT.Bottom = 64
extraRECT.left = 0
extraRECT.right = 32
''clipper is a function that blts the character to the screen
Clipper extra, BackBuffer, extraRECT, (x - 320) - lowerxoff, (y) - loweryoff, True, True
End Sub
''''This is the end of the modual
Ok my problem is that if I put more than one enemy in the map that is read then only the last one that is read is created?
What am i doing wrong?
Thanks
Now here's my goal: I needs each new enemy to be a seperate object so that each one has their own x, y, direction, speed and so on variables that will be affected differently for each one. Here is my code ---symplified
''This is in a module
Public BadGuy(100) As Enemy
Public bcounter as integer
'''Now when i read the file and come to the symbol representing an enemy then ''''''''''''''''''''''
Set BadGuy(bcounter) = New Enemy
BadGuy(bcounter).Initialize_Values (i * 32), (P * 32), 2
bcounter = bcounter + 1
'''Now in my main sub after i draw all of the tiles on screen i
Dim i As Integer
For i = 0 To bcounter
BadGuy(i).go
Next i
''''alright I hope everyone still understands what is going on. Now for the actual class!
Private x As Single
Private y As Single
Private direction As Byte
Private jumping As Boolean
Private speed As Integer
Sub Initialize_Values(user_x As Single, user_y As Single, user_speed As Integer)
speed = user_speed
x = user_x
y = user_y
direction = 0
jumping = False
End Sub
Private Sub Move(tile_map As tile)
Debug.Print y
If tile_map.map(Int(y / 32) + 1, Int(x / 32)).solid = False And tile_map.map(Int(y / 32) + 1, Int(x / 32)).platform = False And jumping = False Then
y = y + speed
End If
If tile_map.map(Int((y + 2) / 32), Int(x / 32)).solid = True Then
direction = 1
End If
If tile_map.map(Int((y + 2) / 32), Int((x / 32) + 1)).solid = True Then
direction = 0
End If
If direction = 1 Then
x = x + speed
End If
If direction = 0 Then
x = x - speed
End If
draw_enemy
End Sub
Public Sub go()
Move game
End Sub
Public Sub draw_enemy()
extraRECT.Top = 32
extraRECT.Bottom = 64
extraRECT.left = 0
extraRECT.right = 32
''clipper is a function that blts the character to the screen
Clipper extra, BackBuffer, extraRECT, (x - 320) - lowerxoff, (y) - loweryoff, True, True
End Sub
''''This is the end of the modual
Ok my problem is that if I put more than one enemy in the map that is read then only the last one that is read is created?
What am i doing wrong?
Thanks