Programming Games with Microsoft Small Basic by Philip Conrod & Lou Tylee
Author:Philip Conrod & Lou Tylee [Conrod, Philip]
Language: eng
Format: azw3
ISBN: 9781937161989
Publisher: Kidware Software LLC
Published: 2017-04-20T04:00:00+00:00
To detect mouse clicks, we need this line at the end of InitializeProgram:
GraphicsWindow.MouseDown = MouseDownSub
With this, each time a MouseDown event occurs, the subroutine named MouseDownSub is called. The code to perform the steps above will be in this subroutine.
Add this subroutine (MouseDownSub) to your program (this implements all the above steps):
Sub MouseDownSub
x = GraphicsWindow.MouseX
y = GraphicsWindow.MouseY
If (GameStatus = "Playing") Then
If (CarMoving = "false" And LoadVisible = "false") Then
DeliveryR = 1 + Math.Floor((y ‐ DeliveryGridY[1][1]) / GridW)
DeliveryC = 1 + Math.Floor((x ‐ DeliveryGridX[1][1]) / GridW)
If (DeliveryR < 1 Or DeliveryR > 20 Or DeliveryC < 1 Or DeliveryC > 20) Then
Goto LeaveMouseDownSub
EndIf
DeltaR = DeliveryR ‐ CarR
DeltaC = DeliveryC ‐ CarC
If (DeltaR <> 0 Or DeltaC <> 0) Then
Message1 = "Car Going To:"
Message2 = DeliveryR + " " + Text.GetCharacter(DeliveryC + 64)
DisplayMessage() CarMoving = "true"
EndIf
EndIf
EndIf
LeaveMouseDownSub:
EndSub
Look at the math that converts a clicked (x, y) coordinate to row and column values. We simply determine the distance of the clicked point from the grid border in each direction and divide that by the width of a grid square. The Math.Floor method knocks off any decimal result to give us a whole number result. It’s pretty cool!
Save and Run the game. Click Start Game, click Load. You should now be able to click the grid and have the clicked location appear in the message area. Here’s my window after I clicked the square in Row 14, Column R:
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9713)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9609)
The Mikado Method by Ola Ellnestam Daniel Brolund(9589)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8122)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7632)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7627)
Grails in Action by Glen Smith Peter Ledbrook(7540)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7357)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6256)
Windows APT Warfare by Sheng-Hao Ma(5707)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(5434)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(5286)
Kotlin in Action by Dmitry Jemerov(4900)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4200)
Functional Programming in JavaScript by Mantyla Dan(3913)
Solidity Programming Essentials by Ritesh Modi(3383)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3134)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3110)
The Ultimate iOS Interview Playbook by Avi Tsadok(3056)
