473,395 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Use of Bitmap.GetPixel function to determine near-collision

MetalMartian
I'm trying to write code for a game based on the original Pacman in Visual Basic .NET 2003, however I can't figure out how to make the character move around the screen and not go through the walls. I've tried using a Collide function, however this means I would need to use several labels as the boundaries. This also means the two objects must intersect, so the user has to reverse out of the wall before continuing the game. I tried using the Bitmap.GetPixel function to determine the colours in a bitmap (resembling the original Pacman map) that I drew in Flash 8, and this has had limited achievement. Sometimes the character can move, other times it can't. I'm not entirely sure why. And then in certain areas it displays an error message saying

"Invalid parameter used.
System.ArgumentException: Invalid parameter used.
at System.Drawing.Bitmap.GetPixel(Int32 x, Int32 y)
at Learn_To_Spell_With_Munchie.frmMunchieGame.tmrGame _Tick(Object sender, EventArgs e) in E:\IPT\Semester 3\Assignments\Major Programming Assignment\Learn To Spell With Munchie\frmMunchieGame.vb:line 972
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.DebuggableCallback(IntP tr hWnd, Int32 msg, IntPtr idEvent, IntPtr dwTime)"

The GetPixel part of my code is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub tmrGame_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrGame.Tick
  2.         picMunchie.Left = picMunchie.Left + DeltaX
  3.         picMunchie.Top = picMunchie.Top + DeltaY
  4.         Dim Background As Bitmap = picGameArea.Image
  5.         Dim TopPixel As Color = Background.GetPixel(picMunchie.Left + (picMunchie.Width / 2), picMunchie.Top - 1)
  6.         Dim LeftPixel As Color = Background.GetPixel(picMunchie.Left - 1, picMunchie.Top + (picMunchie.Height / 2))
  7.         Dim RightPixel As Color = Background.GetPixel(picMunchie.Left + picMunchie.Width + 1, picMunchie.Top + (picMunchie.Height / 2))
  8.         Dim BottomPixel As Color = Background.GetPixel(picMunchie.Left + (picMunchie.Width / 2), picMunchie.Top + picMunchie.Height + 1)
  9.         If TopPixel.ToArgb = -16776961 Or BottomPixel.ToArgb = -16776961 Or LeftPixel.ToArgb = -16776961 Or RightPixel.ToArgb = -16776961 Then
  10.             DeltaX = 0
  11.             DeltaY = 0
  12.         End If
  13.  
(N.B. picMunchie is the user's character they are moving around the screen)

If anyone could please give me some tips as to whether this is the right approach or not it would be much appreciated. Thanks.
May 20 '07 #1
0 1496

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: BC | last post by:
Hello, We are creating an Office add-in. We are able to display the add-in successfully. However, we followed a sample program, and it displays a FaceID = 1044 (which is not the bitmap of the...
3
by: Typpo | last post by:
Hi all, I'm trying to compare a color returned by a Bitmap's GetPixel method to a normal static color of the Color class. My problem: after setting a pixel to a certain color, the color...
7
by: chuck | last post by:
I load a bitmap using GDI+ now, I want to collect all the pixel values, (in RGB but without the A component) onto a color array, say... dim btmp1(,) as color is there a method that can help me...
1
by: Ron Dahl | last post by:
Thanks Robby and Bob Powell for excellent answers on yesterday's question about reversing coordinates in gdi+ I guess this is a new question. My first step is that my bitmap is an aerial...
2
by: Mad Scientist Jr | last post by:
I have a bitmap (32 pixels high, 8192 pixels wide) that contains 255 images, each 32 pixels wide, that I would like to chop up into individual 32x32 bitmap files. Rather than spending hours in...
3
by: johnb41 | last post by:
I need to use the bitmap.getpixel method to work on the pixel level of an image. But GetPixel will not work with Indexed images. The images that i work with are black & white text scans. I...
1
by: Depor | last post by:
I want to do some operations on pixels in bitmap. But method GetPixel() is slow. There is a function ScanLine() in Borland C++ Builder and it's possible to operate on all row of pixels at once. Do...
3
by: Iwanow | last post by:
Hello! My goal is to develop a program that opens a bitmap, copies its pixels to an ArrayList in order to perform some complex calculations (edge detection, Hough transform etc.), and save...
2
by: Peter Oliphant | last post by:
I want to create a new Bitmap which is a portion of an existing Bitmap. For example, if I have a Bitmap that is 100x100 in size I might want to create a new Bitmap that is equivalent to the one...
6
by: herzog | last post by:
Hi, I am using C# to a draw a graphic on a memory bitmap. I then extract the color information of every pixel of the bitmap. I do this with Bitmap.GetPixel(). The trouble I'm having is that I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.