Monsters Not Drawing..
Monsters Not Drawing..
Monsters Not Drawing..
Monsters Not Drawing..
Monsters Not Drawing..
Monsters Not Drawing.. Monsters Not Drawing.. Monsters Not Drawing.. Monsters Not Drawing.. Monsters Not Drawing.. Monsters Not Drawing.. Monsters Not Drawing.. Monsters Not Drawing..
Monsters Not Drawing.. Monsters Not Drawing..
Monsters Not Drawing..
Go Back  Xtreme Visual Basic Talk > > > Monsters Not Drawing..


Reply
 
Thread Tools Display Modes
  #1  
Old 07-08-2011, 11:48 PM
Exiled Exiled is offline
Newcomer
 
Join Date: Jun 2011
Posts: 10
Default Monsters Not Drawing..


Hello everybody! I am creating a top-down dungeon crawler where the maps are randomly generated using pre-made rooms I've created myself. I just recently found one of my early mistakes that slowed down my game VERY much. Monsters are also spawned randomly, and every time I hit a block that didn't have a monster, I drew a transparent tile... It's pretty much like drawing another tilemap over the one I have, so it was quite laggy. In my GetNPCRect sub (it's a sub to determine what source rectangle to get for a monster), 5 is a nothing tile. In my DrawAll() sub(a sub for drawing everything, pretty much), I have a For - Next loop drawing all the monsters on the screen at one time.

Code:
        For X = 0 To 14
            For Y = 0 To 14
                ' Get sRect
                GetNPCRect(MapX + X, MapY + Y, 50, 50)

                ' Set sRect and Draw
                dRect = New Rectangle((X * 50) + xPos, (Y * 50) + yPos, 50, 50)
                    G.DrawImage(mon, dRect, sRect, GraphicsUnit.Pixel)
            Next
        Next
So I simply added the following line of code, thinking it would work...

(NPC is the array that handles the drawing of monsters)

Code:
If NPC(X, Y, 0) <> 5 Then
      G.DrawImage(mon, dRect, sRect, GraphicsUnit.Pixel)
End If
However, unfortunately, it doesn't. No monsters draw at all. I've tried many different combinations of where the code was placed, etc... and I cannot seem to get it right. Help :|
Reply With Quote
  #2  
Old 07-09-2011, 10:26 AM
AtmaWeapon's Avatar
AtmaWeaponMonsters Not Drawing.. AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

It's important to know where this code is as well as where G comes from. If it's not the Paint event or the OnPaint() method, that's your answer. Otherwise, note the monster will only draw if NPC(X, Y, 0) <> 5; perhaps that's never true.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 07-09-2011, 07:07 PM
Exiled Exiled is offline
Newcomer
 
Join Date: Jun 2011
Posts: 10
Default

This code is inside of my DrawAll() function, where all of my drawing code is. In my enemy spawning sub, I have specific code that generates random numbers to determine the monster's location. While setting the monster's location, I also set that same space in the array NPC to a random number, so the type of monster can be randomly generated. I wonder if I made a mistake where the coordinates of the monster are things like X: 96, instead of X: 3. That could be a possibility.
Reply With Quote
  #4  
Old 07-09-2011, 07:48 PM
AtmaWeapon's Avatar
AtmaWeaponMonsters Not Drawing.. AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I can't tell you anything because the information you are giving me doesn't help. Where is DrawAll()? Are you sure it's being called? It sounds like you haven't verified the monster even *should* be drawing yet; do that before trying anything exotic.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 07-09-2011, 10:45 PM
Exiled Exiled is offline
Newcomer
 
Join Date: Jun 2011
Posts: 10
Default

I've already made the combat system, gotten to drawing monsters, and have done it fine. And yes, like I said, DrawAll() is the drawing function. It's it's own Sub, located under Form1_Load. It's the function that handles everything that's being drawn. It has to be called, or else my player and map wouldn't be drawn. This problem started when I started trying to speed up the game, not get it's basics down.
Reply With Quote
  #6  
Old 07-09-2011, 11:22 PM
AtmaWeapon's Avatar
AtmaWeaponMonsters Not Drawing.. AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

If you're calling it from Form1_Load(), it's only getting called once. That's why I'm trying to pry more information about when and how it's called. If it's not being called by OnPaint() or the Paint() event, there's no guarantees because those are the only places you should be drawing from.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #7  
Old 07-09-2011, 11:41 PM
Exiled Exiled is offline
Newcomer
 
Join Date: Jun 2011
Posts: 10
Default

It's not being called in Form1_Load, it's being called in Form1_Paint and every time the form is updated. Like I said, the game works perfectly... I'm just trying to speed it up. DrawAll() is it's own Sub.
Reply With Quote
  #8  
Old 07-10-2011, 02:15 AM
passel's Avatar
passelMonsters Not Drawing.. passel is offline
Sinecure Expert

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

Put a breakpoint on the line. Look at the values and see if it what you expect.
I assume if you remove the If condition, then the monsters are drawn, it is just the game is slower. You can comment the If, End If out. Run the game in the IDE, see where the monsters are, set the breakpoint by clicking on the vertical bar to the left, uncomment the If End If and step through the code to see what is going on. If you're running on a 64-bit operating system, then you may not be able to edit the code at a breakpoint. You will just have to have the code there.
If the monsters draw when the If..End If is not there, and don't when it is, then it definitely is something in the condition. Using the debugger is our friend.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #9  
Old 07-30-2011, 06:14 PM
Exiled Exiled is offline
Newcomer
 
Join Date: Jun 2011
Posts: 10
Default

I apologize for the late reply, been discouraged from programming recently. Anyway, both of your assumptions were correct. When the If statement is not there, the monsters are drawn but the game runs slower. And, according to you, it is something with the condition. I'm still confused, however, for my enemy spawning code clearly sets NPC(x, y, 0) to a value...

Enemy Spawning Sub:
Code:
    Private Sub EnemySpawning()
        Dim M4 As Integer

        For q As Integer = 0 To 10
            Mev(q) = New Monster()
        Next q

        While monstercount < smalldungeonsetting * 8
            M1 = RandomClass.Next(17, 100)
            M2 = RandomClass.Next(17, 100)
            M3 = RandomClass.Next(0, 5)
            M4 = RandomClass.Next(0, 500)
            DR = RandomClass.Next(0, level)
            LR = RandomClass.Next(level, level + 2)
            If Map(M1, M2, 0) = 0 Then
                NPC(M1, M2, 0) = M3
                Map(M1, M2, 0) = 4
                Mev(monstercount).x = M1
                Mev(monstercount).y = M2
                Mev(monstercount).level = LR
                Mev(monstercount).health = LR * 25
                Mev(monstercount).defense = DR
                monstercount = monstercount + 1
            End If
        End While

        enemiesspawned = True
        DrawAll()

    End Sub
Reply With Quote
  #10  
Old 07-31-2011, 02:25 PM
passel's Avatar
passelMonsters Not Drawing.. passel is offline
Sinecure Expert

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

Well, it would be easy to step through the code and verify it is doing what you exepect.
Is the right rectangle values being referenced, etc.
Since I don't have a complete picture of your logic it is hard to guess, and I can't step though your code, so you should do that.
But, consider this

GetNPCRect(MapX + X, MapY + Y, 50, 50)

Here, you're adding a MapX and MapY offset when you pass parameters to this, I presume, Sub.

Here, you don't offset X and Y by MapX and MapY.

If NPC(X, Y, 0) <> 5 Then

But, perhaps that is by design. In the first case perhaps you have different sets of monsters depending on level, so MapX and MapY just get you to the proper set and the level itself is alway a 15x15 grid set up each level.
I don't know.
If I were you, I get the impression, that I should spend some time learing how to use the debugger to step through code, set breakpoints, change things temporarily so I can see the drawing as I step through the code, etc...
Knowing how to work well with just the basic debugging features of your development environment can save you a great deal of time and frustration.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #11  
Old 08-03-2011, 01:50 PM
Exiled Exiled is offline
Newcomer
 
Join Date: Jun 2011
Posts: 10
Default

Alright, I figured out how to use the Watch + Breakpoint feature. It turns out, NO value on the NPC array is other than 5. I'm inspecting my enemy spawning code a bit more.
Reply With Quote
  #12  
Old 08-03-2011, 02:07 PM
AtmaWeapon's Avatar
AtmaWeaponMonsters Not Drawing.. AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

That makes me suspicious about something. What's RandomClass? Where is it created? Are the values in Mev(...).x all the same as well? There's ways to misuse random number generators that makes it likely the same number will be generated multiple times.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #13  
Old 08-03-2011, 02:56 PM
Exiled Exiled is offline
Newcomer
 
Join Date: Jun 2011
Posts: 10
Default

RandomClass is defined at the beginning of the Forms code.

Dim RandomClass As New Random()

This allows me to generate several different random numbers. I know for a fact that the generator works fine, for the map is generated perfectly. Mev's values are different, for they hold all of the monsters' stats. When I walk around the randomly generated dungeon, I run into random collision blocks. This means that there is a monster there. Each monster has it's own stats randomly generated according to the player's level. When I enter combat, I find that each invisible monster has different health, different strength, etc... So that is working fine. The only problem I'm having, after learning all of NPC's values are equal to 5, is finding out why they equal 5, and not another variable considering I give them each a value in my enemy spawning code.
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
Monsters Not Drawing..
Monsters Not Drawing..
Monsters Not Drawing.. Monsters Not Drawing..
Monsters Not Drawing..
Monsters Not Drawing..
Monsters Not Drawing.. Monsters Not Drawing.. Monsters Not Drawing.. Monsters Not Drawing.. Monsters Not Drawing.. Monsters Not Drawing.. Monsters Not Drawing..
Monsters Not Drawing..
Monsters Not Drawing..
 
Monsters Not Drawing..
Monsters Not Drawing..
 
-->