-
Sep 29th, 2014, 11:18 AM
#1
Thread Starter
New Member
Continuous movement in Pac-man in VB 2010
Hi, So I'm attempting to make a working version of Pac-man using visual basic express 2010 and I'm having an issue with movement of pac-man where I can get him to move left right or up and down perfectly but when I try and make him move continuously with one keypress he seems to go on forever or disappears (I assume he goes off in the direction the key was pressed in i.e UP)
Here is my code:
vb.net Code:
Select Case e.KeyCode Case Keys.Up 'Do Until e.KeyCode = Keys.Right Or e.KeyCode = Keys.Left Or e.KeyCode = Keys.Down ----- My attempt at continous movement----' If Not picturebox.Location.Y - 15 < 0 Then Loc = New Point(picturebox.Location.X, picturebox.Location.Y - 15) picturebox.Location = Loc 'Resets location if collision detected' If picturebox.Bounds.IntersectsWith(picturebox1.Bounds) Then Loc = New Point(picturebox.Location.X, picturebox.Location.Y + 15) picturebox.Location = Loc End If End If picturebox.Image = My.Resources.pac_up 'Loop' Case Keys.Down If Not picturebox.Location.Y + 15 < 0 Then Loc = New Point(picturebox.Location.X, picturebox.Location.Y + 15) picturebox.Location = Loc 'Resets location if collision detected' If picturebox.Bounds.IntersectsWith(picturebox1.Bounds) Or picturebox.Bounds.IntersectsWith(PictureBox3.Bounds) Then Loc = New Point(picturebox.Location.X, picturebox.Location.Y - 15) picturebox.Location = Loc End If picturebox.Image = My.Resources.pac_down End If Case Keys.Left If Not picturebox.Location.X - 15 < 0 Then Loc = New Point(picturebox.Location.X - 15, picturebox.Location.Y) picturebox.Location = Loc ' Resets location if collision detected' If picturebox.Bounds.IntersectsWith(picturebox1.Bounds) Or picturebox.Bounds.IntersectsWith(PictureBox6.Bounds) Or picturebox.Bounds.IntersectsWith(PictureBox7.Bounds) Then Loc = New Point(picturebox.Location.X + 15, picturebox.Location.Y) picturebox.Location = Loc End If picturebox.Image = My.Resources.pac_left End If Case Keys.Right If Not picturebox.Location.X + 15 < 0 Then Loc = New Point(picturebox.Location.X + 15, picturebox.Location.Y) picturebox.Location = Loc ' Resets location if collision detected' If picturebox.Bounds.IntersectsWith(picturebox1.Bounds) Or picturebox.Bounds.IntersectsWith(PictureBox4.Bounds) Or picturebox.Bounds.IntersectsWith(PictureBox5.Bounds) Then Loc = New Point(picturebox.Location.X - 15, picturebox.Location.Y) picturebox.Location = Loc End If End If picturebox.Image = My.Resources.pacman_completed_gif End Select
Last edited by dday9; Sep 29th, 2014 at 11:24 AM.
Reason: changed [php] to [highlight]
-
Sep 29th, 2014, 11:27 AM
#2
Re: Continuous movement in Pac-man in VB 2010
If you're using the Do loop to try and move pac-man continuously then that is the reason why it will go on forever or just disappear. What you need to do is use a game loop to update the location of pac-man. Here is my example while making it work like a timer. Place your code in the GameLoop's tick event and set the RefreshRate to whatever you desire(typically 60 FPS is the desired target).
-
Oct 1st, 2014, 02:22 AM
#3
Re: Continuous movement in Pac-man in VB 2010
Wouldn't Pac-man move if you have your finger on the button/key, why would you need a loop?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Oct 1st, 2014, 08:16 AM
#4
Re: Continuous movement in Pac-man in VB 2010
Originally Posted by Nightwalker83
Wouldn't Pac-man move if you have your finger on the button/key, why would you need a loop?
The game mechanics of pacman are that he is always moving, all you do is hit the direction you want him to go.
-
Oct 1st, 2014, 01:18 PM
#5
Re: Continuous movement in Pac-man in VB 2010
Correct. Pac-Man can't stop dead in the middle of a tunnel. He will go in the last direction he was told to go unless told to turn around, hits a wall, or told to go in another direction.
Thus, if you got a tunnel shaped like an "L", and Pac-Man starts at the top, all you need to do is tap "down" once and he'll hit the bottom of the "L". He'll sit there because he hit a wall. If you hold "right" even though he's moving "down" the tunnel, he won't suddenly stop and face the right wall, he'll KEEP moving down and when he hits that wall, immediately turn right and go down the bend.
-
Oct 1st, 2014, 01:47 PM
#6
Re: Continuous movement in Pac-man in VB 2010
If you want to do Pac-Man "right", I believe the PAC-MAN Dossier site is the most complete information about the classic Pac-Man game, with Ghost behavior, etc. It is an interesting read if you're into that sort of thing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|