Advertisement
Guest User

DTS NEAR ACHIVEVED

a guest
Mar 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. -----------------------------------------------------------------------------------------
  2. --
  3. -- main.lua
  4. --
  5. -----------------------------------------------------------------------------------------
  6.  
  7. -- Your code here
  8. -- constants.
  9. local fullw = display.contentWidth -- variable for the highest X value of the screen
  10. local fullh = display.contentHeight -- variable for the highest Y value of the screen
  11.  
  12. local centerX = display.contentCenterX -- variable for the center X value of the device you are coding for. changes device to device.
  13. local centerY = display.contentCenterY -- variable for the center Y value of the device you are coding for. changes device to device.
  14.  
  15. -------------------------------------------------------------------------------------------------------------------------------------------
  16.  
  17. local defaultField = native.newTextField(centerX, centerY + 230, 150,30) -- draws a text field on the screen. centerX being the X coordinate and centery being the Y coordinate. The other two numbers are the width and height of the field.
  18. defaultField.placeholder = "Enter your speed from 0,100"
  19. defaultField.size = 11
  20.  
  21. -- local widget = require( "widget" )
  22.  
  23. local speedText = display.newText("Speed = ", centerX-20, centerY+222,50 , 50 ,nil, 12) -- draws the text for which the speed will be shown. will update when another number is put into the textfield.
  24.  
  25. -- local function handleButtonEvent(event)
  26.  
  27. -- Checks field content
  28. -- if defaultField.text == "" then
  29. -- Check for content
  30. -- print ("Text Field Is Empty")
  31. -- local alert = native.showAlert ("Alert", "Please input your wanted speed (0,100) into the text box")
  32.  
  33. -- elseif tonumber(defaultField.text) then
  34. -- print ("All Good")
  35. -- local alert = native.showAlert("", "")
  36. -- elseif tonumber(defaultField.text) == nil then
  37. -- defaultField.text = ""
  38. -- local alert = native.showAlert ("Error", "Speed needs to be a number, not text.")
  39.  
  40. -- end
  41.  
  42. -- end
  43.  
  44. -- local buttonTable = {
  45. -- table with all the button ids(not including the stop button)
  46. -- it gives the button ids values for X,Y, rotation
  47. -- {"#CF",centerX,centerY-100},
  48. -- {"#CRF",centerX+95,centerY-100,},
  49. -- {"#CHR",centerX+95,centerY},
  50. -- {"#CRB",centerX+95,centerY+100},
  51. -- {"#CB",centerX,centerY+100},
  52. -- {"#CLB",centerX-95,centerY+100},
  53. -- {"#CHL",centerX-95,centerY},
  54. -- {"#CLF",centerX-95,centerY-100},
  55. -- }
  56.  
  57. local drawSpeedButton = display.newText("Set speed",centerX,centerY + 260)
  58.  
  59.  
  60. local function buttonListener(event) -- this function listens for the button id for when a button ID is pressed. it will then send a command to the console to print "event.target.id"
  61. local id = event.target.id -- sets a variable for the event.target.id to "id"
  62. if id == "#CF" then -- if button "#CF" is pressed, print out "#CF" into the console. Happens for all the buttons below.
  63. print(id)
  64. elseif id == "#CRF" then
  65. print(id)
  66. elseif id == "#CHR" then
  67. print(id)
  68. elseif id == "#CRB" then
  69. print(id)
  70. elseif id == "#CB" then
  71. print(id)
  72. elseif id == "#CLB" then
  73. print(id)
  74. elseif id == "#CHL" then
  75. print(id)
  76. elseif id == "#CLF" then
  77. print(id)
  78. elseif id == "#CS" then
  79. print(id)
  80. end
  81.  
  82. end
  83.  
  84.  
  85. local function drawButton(xValue,yValue,buttonID,buttonRot)-- function for displaying the arrows, calls for an xvalue, yvalue, button id(declared above), and the rotation of the button.
  86. local button = display.newImage("images/arrow.png", xValue, yValue) -- draws the arrow, using the values declared from the values of the function
  87. button:scale(0.35,0.35)-- scales the button down to 35% of original size.
  88. button.id = buttonID -- the id of the button, used by the event listener gets put into the variable.
  89. button:addEventListener("touch",buttonListener)--adds an event to make it so you can click on the button and it
  90. button.rotation = buttonRot -- sets the rotation of the arrow to the value declared with the function calls below.
  91. print(buttonRot)-- prints the rotation of the button
  92. end
  93.  
  94.  
  95. local function drawStopButton(xValue,yValue,buttonID)
  96. local stopButton = display.newImage("images/stop.png", centerX,centerY)
  97. stopButton:scale( 0.5, 0.5)
  98. stopButton.id = buttonID
  99. stopButton:addEventListener("touch",buttonListener)
  100. end
  101.  
  102. -- local button1 = widget.newButton(
  103. -- {
  104. -- defaultFile = "Images/Button.png",
  105. -- overFile = "Images/ButtonPressed.png",
  106. -- label = "button",
  107. -- onEvent = handleButtonEvent
  108.  
  109. -- }
  110. -- )
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. drawButton(centerX,centerY-100,"#CF",nil) -- need all these for the different buttons, havent made a for loop for it yet.
  118. drawButton(centerX+95,centerY-100,"#CRF",45)
  119. drawButton(centerX+95,centerY,"#CHR",90)
  120. drawButton(centerX+95,centerY+100,"#CRB",135)
  121. drawButton(centerX,centerY+100,"#CB",180)
  122. drawButton(centerX-95,centerY+100,"#CLB",225)
  123. drawButton(centerX-95,centerY,"#CHL",270)
  124. drawButton(centerX-95,centerY-100,"#CLF",315)
  125. drawStopButton(centerX,centerY,"#CS",nil) -- need a seperate function for the stop button for convience
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement