Pac-Man Game in VB 2010
Pac-Man Game in VB 2010
Pac-Man Game in VB 2010
Pac-Man Game in VB 2010
Pac-Man Game in VB 2010
Pac-Man Game in VB 2010 Pac-Man Game in VB 2010 Pac-Man Game in VB 2010 Pac-Man Game in VB 2010 Pac-Man Game in VB 2010 Pac-Man Game in VB 2010 Pac-Man Game in VB 2010 Pac-Man Game in VB 2010
Pac-Man Game in VB 2010 Pac-Man Game in VB 2010
Pac-Man Game in VB 2010
Go Back  Xtreme Visual Basic Talk > > > Pac-Man Game in VB 2010


Reply
 
Thread Tools Display Modes
  #1  
Old 06-22-2010, 06:20 PM
HellfireXP's Avatar
HellfireXP HellfireXP is offline
Freshman
 
Join Date: May 2010
Location: South Carolina
Posts: 41
Default Pac-Man Game in VB 2010


Just something I put together in the last two days. Utilizes my DynamicBitmap heavily. I called it "Patman" but it's basically Pac-Man. The link below is the source code.

Edit by Moderator: LINK to .zip file containing binaries has been removed

Last edited by webbone; 06-23-2010 at 05:00 PM. Reason: removed link in violation of Posting Guidlines
Reply With Quote
  #2  
Old 06-23-2010, 03:39 PM
Qua's Avatar
QuaPac-Man Game in VB 2010 Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

Remove to executables from the package as well

The game looks cool and has quite the feel of the original one except for the game not pausing an instant when you eat a ghost. There is a little bug (or bug if you will) with the movement/collision when you turn around the corner. Looks like you can actually move diagonally past a corner and thus avoiding the cheese at the the corner position.

I had quite a little laught finding your pause method
Code:
  Public Sub Pause()
        Dim timeKeep As Long
        timeKeep = 0
        Do
            timeKeep += 1
            If timeKeep = 270000000 Then Exit Do
        Loop
    End Sub
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #3  
Old 06-23-2010, 03:50 PM
HellfireXP's Avatar
HellfireXP HellfireXP is offline
Freshman
 
Join Date: May 2010
Location: South Carolina
Posts: 41
Default

Yeah, it's a big unconventional, but works. Since I mostly just program for myself, I tend to find the easy ways to do things I want to get done.

The movement bug is small, I didn't worry about fixing it, and it doesn't interfere with the overall operation of the game. It's more like a prototype anyway - made it in 2 days. I'm going to work on another game that will be more like "Advance Wars" if you ever played that. It's going to be with space ships though and instead of grass, trees, roads, and cities it will be space, asteroids, nebulas, and planets.

Which executables should I take out? I don't want to remove anything that's essential to the program. I haven't uploaded many programs yet, so I haven't had to deal with sorting through the program files.
Reply With Quote
  #4  
Old 06-23-2010, 04:03 PM
Qua's Avatar
QuaPac-Man Game in VB 2010 Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

According to the forum posting guide lines it is strictly forbidden to directly link to executable files and assemblies. Thus you have to remove any .exe and .dll files in your zipped file.

If you want a simple way to pause the current thread I suggest using Thread.Sleep().
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #5  
Old 06-23-2010, 04:41 PM
HellfireXP's Avatar
HellfireXP HellfireXP is offline
Freshman
 
Join Date: May 2010
Location: South Carolina
Posts: 41
Default

I'll just adjust my zip file and remove the executable files. What do I need to keep then? Just the files under the editor and the resources?
Reply With Quote
  #6  
Old 06-23-2010, 05:04 PM
HellfireXP's Avatar
HellfireXP HellfireXP is offline
Freshman
 
Join Date: May 2010
Location: South Carolina
Posts: 41
Default

Ok, I'll fix it.

Last edited by HellfireXP; 06-23-2010 at 05:18 PM.
Reply With Quote
  #7  
Old 06-23-2010, 05:17 PM
HellfireXP's Avatar
HellfireXP HellfireXP is offline
Freshman
 
Join Date: May 2010
Location: South Carolina
Posts: 41
Default

Ok, fixed. No more executables. Enjoy!

http://www.mediafire.com/file/tyyokd3zydw/Pat-Man.zip
Reply With Quote
  #8  
Old 06-23-2010, 05:22 PM
AtmaWeapon's Avatar
AtmaWeaponPac-Man Game in VB 2010 AtmaWeapon is offline
Fabulous Florist

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

*sigh*
It's not generally wise to try and weasel your way out of a rule when someone explains it to you.

The rule really needs to be rewritten, but I'll try to word it the way it's been enforced as long as I have been around. The relevant line in the Posting Guidelines is as follows:
Quote:
Any code files not readable as default must be submitted as source code text instead.
"Attachments and links to projects containing source code are encouraged. Please remove all executables and libraries from the link. If the link is to a zip or other type of container file, please ensure that the zip file does not include any binary files."

There's several reasons for this.
  • Binaries are big and don't compress well. My average demo project is ~17KB zipped with only source files. It's usually more than 50KB if I don't take out the binaries.
  • You can build binaries from source. The argument to the last point is "broadband is prevalent." This is a counter-argument. Why include an extra 30KB of binaries with your project if a user can easily build it themselves? The source code is what we care about here.
  • There's no guarantee the binaries are the result of building the source. A malicious member could build a virus and submit a project with the virus where the built executable should be. This could result in someone unwittingly installing the virus.

Unless you've messed with the settings, deleting any "bin" and "obj" folders are sufficient to satisfy the requirements of this rule. If you depend on third-party DLLs, then you're going to have to include instructions on acquiring them and where to put them. I don't like it either, but it's the best choice for a code-sharing forum.

*edit* Oh, you posted it while I was typing. I'm taking a look. Want an overall critique? (Fair warning: I'm known to be harsh ) *double edit* (The harsh warning may not need to apply, it's not that bad considering game code is usually quite messy.)
__________________
.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.

Last edited by AtmaWeapon; 06-23-2010 at 05:28 PM.
Reply With Quote
  #9  
Old 06-23-2010, 06:48 PM
TRSDOSBasic79's Avatar
TRSDOSBasic79 TRSDOSBasic79 is offline
Contributor
 
Join Date: Oct 2003
Location: Pennsylvania
Posts: 422
Default

Oh no HellfireXP, I'll bet Atma gives it a C+. I like it though. Wish it was a bit faster. Does remind me of the old pacman game. I wish I could code a "Galaxian" Game. Remember "Galaga"?
Reply With Quote
  #10  
Old 06-23-2010, 07:35 PM
HellfireXP's Avatar
HellfireXP HellfireXP is offline
Freshman
 
Join Date: May 2010
Location: South Carolina
Posts: 41
Default

You can speed it up by adjusting the SequenceTimer Interval or decreasing PATMAN_SPEED or GHOST_SPEED constant values.

Also, here is a better pause subroutine... pauses for x amount of milliseconds.

Code:
Public Sub Pause(ByVal milliseconds As Double)
        Dim stopWatch As Date
        stopWatch = Now.AddMilliseconds(milliseconds)

        Do
            If stopWatch <= Now Then Exit Do
        Loop
    End Sub

Last edited by HellfireXP; 06-23-2010 at 08:47 PM. Reason: *edit* It's better now - milliseconds pause instead of seconds
Reply With Quote
  #11  
Old 06-23-2010, 07:52 PM
HellfireXP's Avatar
HellfireXP HellfireXP is offline
Freshman
 
Join Date: May 2010
Location: South Carolina
Posts: 41
Default

Oooo... TRSDOSBasic79... I didn't remember that one until I looked it up. I could probably make a space invaders type game, but the math involved with Galaga making them fly down the screen in various patterns is abit above my mathematics skill level.

Please, AtmaWeapon... take a look at it and let me know what you think. Any critiques, please provide advice on improvement though.

Last edited by HellfireXP; 06-23-2010 at 07:58 PM.
Reply With Quote
  #12  
Old 06-24-2010, 01:03 AM
PlausiblyDamp's Avatar
PlausiblyDampPac-Man Game in VB 2010 PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Quote:
Originally Posted by HellfireXP View Post
You can speed it up by adjusting the SequenceTimer Interval or decreasing PATMAN_SPEED or GHOST_SPEED constant values.

Also, here is a better pause subroutine... pauses for x amount of milliseconds.

Code:
Public Sub Pause(ByVal milliseconds As Double)
        Dim stopWatch As Date
        stopWatch = Now.AddMilliseconds(milliseconds)

        Do
            If stopWatch <= Now Then Exit Do
        Loop
    End Sub
Any reason you aren't using Thread.Sleep() as suggested by Qua? Your loop is going to be very cpu intensive for no real reason.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #13  
Old 06-24-2010, 12:24 PM
AtmaWeapon's Avatar
AtmaWeaponPac-Man Game in VB 2010 AtmaWeapon is offline
Fabulous Florist

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

TRSDOSBasic79 is a bit too worried about my appraisal To be honest, I kind of *was* hoping that the code would be a horrible mess. I can't tell if I like tearing apart bad code because of a sadistic streak or a need to help the person that wrote it improve, but either way there's a chance for the user to improve their skill so it's a win-win. Unfortunately for me the worst parts of the code were prefixed with comments that essentially say "I could have done X instead but didn't care" and it's hard to criticize something that's already been called ugly Depending on how mean I feel that day I'd say that an overall rating would be B- or B+, and I'm a *very* hard grader.

I'm at work and have some stuff to do at home so it will probably be Friday evening or later when I can say what I have to say. I'll hold off an overall appraisal until then, but this pause routine is something I wanted to comment on early. It leads into a good topic that was going to take up space in the appraisal anyway.

This pause routine seems to be used mainly to try and stop the game from progressing while a sound is playing. It seems the best way to discuss why this is ugly is to start with how I went about deciding if it was even needed at all, then a discussion of its problems.

When I first saw the method, I figured that it existed due to the My namespace not having enough sophistication to notify you when a sound ended. Usually the stuff in the My namespace serves as an easy facade over other classes in the .NET framework; it sacrifices power and control for ease of use. In this case, the equivalent .NET class is System.Media.SoundPlayer. Unfortunately, it's not much more powerful than the My namespace's facade. The closest you can come to getting a notification when a sound finishes playing is to call PlaySync(), which will block the calling thread. It'd be *really* nice if there were an event the class raised when it finished playing the sound. Alas, if you want this you have to write it yourself. More on this later.

What's so wrong with the two methods used so far? The first method basically did nothing as it counted to some large number. This is a very unreliable way to pause for any amount of time on a computer because your user's computer will likely be different than yours and will count to the number either more quickly or more slowly. You'll either end up with users playing the game before the sound finishes, or stuck waiting for the counter to finish with no indication as to why the game is frozen. The second method is slightly more reliable. Computer system clocks are notoriously bad for precise time measurement, but if you're half a second off it won't really matter so much. The main problem with both methods is when a thread is executing a loop, it does so as fast as possible. Your pause method is going to use 100% of the CPU (or core) while it's running. That's silly on a PC and a serious drain on a laptop's battery.

So what's the solution? Thread.Sleep() is one of them. When you call this, you tell Windows that you won't be doing anything for a while and it stops assigning CPU cycles to your thread. This is a polite way to wait for some time.

It's still not quite the best solution in my opinion. Even if you're using Thread.Sleep(), you're blocking the UI thread. It's not a big deal for Pac-Man clones because the arcade game worked like this. However, in another game you might want to run an animation while playing the sound; this is impossible if you're sleeping on the UI thread.

The best solution to the problem would be to hack out your own wrapper around SoundPlayer that includes an event to indicate the sound is finished. This would cause you to change a few things related to how your program works. In particular, you tend to use this pattern:
Code:
' ... do some stuff
PlayTheSound()
PauseUntilSoundIsFinished()
' ... do some other stuff
This doesn't work if we use an event to indicate when the sound is finished; you'd end up using a pattern more like this:
Code:
Sub BeforeSound()
    ' ... Do some stuff
    PlayTheSound()
End Sub

Sub AfterSound()
    ' ... Do some stuff
End Sub

Sub SoundPlayer_WhenSoundIsFinished(...)
    AfterSound()
End Sub
It's a little disjointed, but fool around with event-driven programming in Windows Forms enough and you'll get very familiar with logic like this.

How do you make the SoundPlayer work this way? The easiest solution is to use a BackgroundWorker. I'll talk more about this when I get around to commenting on the application as a whole.

A real suggestion
It'd be hard to make a much better Pac-Man clone than this in Windows Forms, ignoring source code improvments. Performance sucks; even if you muck with the speed of the characters all you can manage to do is make their movement jerky. I found input to be unreliable, particularly moving up and down. Then there's the problem of waiting for sounds to complete. I'll repeat myself: Pac-Man gets a free ride for this because if you examine the arcade game closely you'll find that it too paused the game for major sound effects. But for other games this could be a dealbreaker.

There's not much you can do in code to fix this. Windows Forms was designed for static layouts. The concept of animation wasn't bolted on until Win2k, and the support that's there is limited only to "make this control fade/slide in/out". WinForms timers don't have enough precision to make a high-quality game. If you want to shoot for 60 FPS, you need the timer to tick every 16ms. The documentation points out that 55ms is the fastest the timer will tick; that's only good enough for 18 FPS. In game development frameworks, the game tends to run in a while(true) loop, but this is a bad choice in WinForms because it ties up the UI thread. (I'd like to experiment with a crazy idea for putting the game loop on another thread, but that's for much later.)

That's just a verbose way of saying, "Windows Forms was not made for writing games, and it's hard to hack it into a good gaming framework." I'm not going to say it's impossible because I have a couple of ideas, but I'm going to say it's hard because you'd have to lay a lot of foundation code down and I'm not sure if the overhead kills any benefit.

My suggestion? Decide if you're interested in writing applications or games. If you're interested in applications, continue fooling around with Windows Forms. If you think games are more up your alley, you're going to outgrow WinForms in a hurry. Look to XNA if you want to write games; for some reason it only supports C# but it's not that big a deal.
__________________
.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
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
Pac-Man Game in VB 2010
Pac-Man Game in VB 2010
Pac-Man Game in VB 2010 Pac-Man Game in VB 2010
Pac-Man Game in VB 2010
Pac-Man Game in VB 2010
Pac-Man Game in VB 2010 Pac-Man Game in VB 2010 Pac-Man Game in VB 2010 Pac-Man Game in VB 2010 Pac-Man Game in VB 2010 Pac-Man Game in VB 2010 Pac-Man Game in VB 2010
Pac-Man Game in VB 2010
Pac-Man Game in VB 2010
 
Pac-Man Game in VB 2010
Pac-Man Game in VB 2010
 
-->