Hello there,
I may have bitten off more than I can chew with this one. Here’s the background, I’m an education major with close to no experience with programming taking an online elective course that basically involved following the getting started guide. I now have to create an educationally based game as my final assignment and although I completed the 8 chapter tutorials; I feel like I don’t know enough to accomplish this.
I’ve spent the whole weekend behind my computer attempting to make a simple game that I can submit as my final project. Here is what I am trying to do;
I took similar mechanics from the star explorer game and instead used a dart and three targets that will sit at the top of the screen. The goal is to have a game that places multiplication problems somewhere on the lower portion of the screen while three possible answers will be displayed above or on the three targets at the top. The player will then need to choose the correct target to hit and tap the dart to fire at one of the targets.
As it stands I have all images on the screen and the dart is able to fire up to the top. I have been searching all weekend with no success to find out how I can add in multiplication problems from #'s 1-10, and the answers that correlate with specific targets. I also need a collision event to occur when the dart hits a target because right now it just passes it by and flies off screen. Please if there is anyone out there that can give me some advice you would be my hero.
Here is a copy of the code I currently have in the main.lua
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- -- housekeeping stuff display.setStatusBar(display.HiddenStatusBar) local physics = require( "physics" ) physics.start() physics.setGravity( 0, 0 ) -- Initialize variables local background local dart local title local text local target local score = 0 local wrong = false -- Set up display groups local backGroup = display.newGroup() -- Display group for the background image local mainGroup = display.newGroup() -- Display group for the dart. local uiGroup = display.newGroup() -- Display group for UI objects like the score local background = display.newImageRect( backGroup, "bg.jpg", 620, 690 ) background.x = display.contentCenterX background.y = display.contentCenterY local dart = display.newImageRect( mainGroup, "dart.png", 37.5, 112.5 ) dart.x = display.contentCenterX dart.y = display.contentHeight-25 local title = display.newImageRect( backGroup, "title.png", 300, 100) title.x = display.contentCenterX title.y = display.contentHeight-325 local function createTarget() local newTarget = display.newImageRect( mainGroup, "target.png", 85, 85 ) target.x = display.contentWidth-265 target.y = display.contentHeight-420 end local target = display.newImageRect( mainGroup, "target.png", 85, 85 ) target.x = display.contentWidth-265 target.y = display.contentHeight-420 local target = display.newImageRect( mainGroup, "target2.png", 85, 85 ) target.x = display.contentWidth-159 target.y = display.contentHeight-420 local target = display.newImageRect( mainGroup, "target3.png", 85, 85 ) target.x = display.contentWidth-55 target.y = display.contentHeight-420 local function throwDart() local newDart = display.newImageRect( mainGroup, "dart.png", 37.5, 112.5 ) physics.addBody( newDart, "dynamic", { isSensor=true } ) newDart.isBullet = true newDart.myName = "Dart" newDart.x = dart.x newDart.y = dart.y newDart:toBack() transition.to( newDart, { y=-150, time=500, } ) onComplete = function() display.remove( dart ) end end dart:addEventListener( "tap", throwDart ) local function dragDart( event ) local dart = event.target local phase = event.phase if ( "began" == phase ) then -- Set touch focus on the dart display.currentStage:setFocus( dart ) -- Store initial offset position dart.touchOffsetX = event.x - dart.x elseif ( "moved" == phase ) then -- Move the dart to the new touch position dart.x = event.x - dart.touchOffsetX elseif ( "ended" == phase or "cancelled" == phase ) then -- Release touch focus on the dart display.currentStage:setFocus( nil ) end return true -- Prevents touch propagation to underlying objects end local function onCollision( event ) if ( event.phase == "began" ) then local obj1 = event.object1 local obj2 = event.object2 if ( ( obj1.myName == "dart" and obj2.myName == "target" ) or ( obj1.myName == "target" and obj2.myName == "dart" ) ) then -- Remove both the dart and target display.remove( obj1 ) display.remove( obj2 ) end end end dart:addEventListener( "touch", dragDart )
I tried starting a function to create each target but I don’t think I have enough knowledge and whatever I’ve watched or read over the past two days hasn’t helped me understand
here is a pic for reference