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(9617)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9550)
The Mikado Method by Ola Ellnestam Daniel Brolund(9525)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8060)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7582)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7579)
Grails in Action by Glen Smith Peter Ledbrook(7485)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7308)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6202)
Windows APT Warfare by Sheng-Hao Ma(5126)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(4864)
Kotlin in Action by Dmitry Jemerov(4843)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(4706)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4167)
Functional Programming in JavaScript by Mantyla Dan(3873)
Solidity Programming Essentials by Ritesh Modi(3060)
Mastering Python for Finance by Weiming James Ma;(2972)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2959)
Learning Java by Patrick Niemeyer & Daniel Leuck(2951)