100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

Object Oriented Programming Wall Collision Guide

Rating
5.0
(1)
Sold
1
Pages
1
Uploaded on
10-07-2022
Written in
2018/2019

This document contains a guide to create a wall collision piece of code in preparation for the assignment.

Institution
Course








Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Study Level
Examinator
Subject
Unit

Document information

Uploaded on
July 10, 2022
Number of pages
1
Written in
2018/2019
Type
Class notes
Professor(s)
N/a
Contains
All classes

Subjects

Content preview

Detecting collisions with ‘walls’ made of labels

Here’s a quick way to detect if your player is colliding
with ‘walls’ made of labels



1. Open a new project – call it- MazeWallCollisions
2. Add a panel to the form

3. Add several labels, size them, set autosize =
false, and set backcolor = black as shown
{there’s no need to change the names of these
labels!}
4. Add a picturebox for the player, backcolor red
[or put in an image], name it picMan
5. Now we’ll create our own function to test the collision and prevent the player from going
throught the wall [type in the highlighted code]
Private Function CollidesWithWall(pic As PictureBox) As Boolean
Dim ctl As Control
For Each ctl In Me.Panel1.Controls 'loop through all controls in the panel
If TypeOf ctl Is Label Then 'if they are labels then
If ctl.Bounds.IntersectsWith(pic.Bounds) Then 'test for collision
Return True 'pic has collided with walls so return TRUE
End If
End If
Next
Return False 'no collision with walls so return FALSE
End Function


6. Finally we’ll add the code to move the player using Key_Up event…[type in the highlighted
code]
Private Sub Form1_KeyUp(sender As Object, _
e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Dim locB4Move As Point = picMan.Location

'move man according to key press direction
Select Case e.KeyCode
Case Keys.Up
picMan.Top -= 10
Case Keys.Down
picMan.Top += 10
Case Keys.Left
picMan.Left -= 10
Case Keys.Right
picMan.Left += 10
End Select

If CollidesWithWall(picMan) = True Then
'man has collide with wall reposition to before move
picMan.Location = locB4Move
End If
End Sub
Free
Get access to the full document:
Download

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
ItsKenzie
5.0
(9)

Reviews from verified buyers

Showing all reviews
3 year ago

5.0

1 reviews

5
1
4
0
3
0
2
0
1
0
Trustworthy reviews on Stuvia

All reviews are made by real Stuvia users after verified purchases.

Get to know the seller

Seller avatar
ItsKenzie University
Follow You need to be logged in order to follow users or courses
Sold
20
Member since
6 year
Number of followers
10
Documents
78
Last sold
2 year ago
IT and Cyber Security Notes For Computing Students

I prepare and sell top quality notes and essays that are concise and easy to understand to fellow computing students. It can be overwhelming when you get your first few projects or assignments, using my notes and essays can help you to better understand the modules and hopefully help you get the grades you want. Thanks for visiting my profile, feedback is always appreciated.

5.0

9 reviews

5
9
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions