Hi,
I am creating a 2D zombie adventure game and have never worked with coding Ai. I am looking for some help brainstorming code. Any help would be greatly appreciated.
Here is the code to my game if its any help.
local W = display.contentWidth local H = display.contentHeight local RIGHT\_BOUND = 3/4\*W local LEFT\_BOUND = 1/4\*W local physics = require("physics") physics.setDrawMode("hybrid") physics.start() local dpad = require("dpad") dpad.show(-250, H-92, 92) dpad.showButton(600, H-92, 92/2) level1 = display.newGroup( ) splashScreen = display.newGroup( ) sound1 = display.newGroup( ) sound2 = display.newGroup( ) grpHUD = display.newGroup() shop = display.newGroup( ) splashScreen.isVisible = true sound1.isVisible = true sound2.isVisible = false level1.isVisible = false grpHUD.isVisible = false shop.isVisible = false local splash = display.newImageRect( splashScreen, "assets/splashBG.jpg", W\*3.3, H) splash.x = W/2 splash.y = H/2 local catTxt = display.newImageRect(splashScreen, "assets/catsTXT.png", W, H) catTxt:scale(.9,.3) catTxt.x = -175 catTxt.y = 75 local vsTxt = display.newImageRect(splashScreen, "assets/VStxt.png", W, H) vsTxt:scale( .5, .2 ) vsTxt.x = -175 vsTxt.y = 185 local zomTxt = display.newImageRect(splashScreen, "assets/zomTXT.png", W, H) zomTxt:scale(1.2,.3) zomTxt.x = -164 zomTxt.y = 275 local start = display.newImageRect( splashScreen, "assets/start.png", W, H ) start:scale(.5,.15) start.x = 160 start.y = 180 local function sSwitch() if (sound1.isVisible == true) then sound1.isVisible = false sound2.isVisible = true else sound2.isVisible = false sound1.isVisible = true end end local sound1 = display.newImageRect(sound1,"assets/sound1.png", W, H ) sound1:scale(.15,.1) sound1.x = -200 sound1.y = 400 sound1:addEventListener( "tap", sSwitch ) local sound2 = display.newImageRect( sound2, "assets/sound2.png", W, H ) sound2:scale(.15,.1) sound2.x = -200 sound2.y = 400 sound2:addEventListener( "tap", sSwitch ) function startGame(tapHandlerFn) splashScreen.isVisible = false sound1.isVisible = false sound2.isVisible = false level1.isVisible = true grpHUD.isVisible = true dpad.dSwitch(true) end local bg = display.newImageRect( level1, "assets/background.png", W\*4, H) bg.x = W/2 bg.y = H/2 - 50 bg:scale(1.2,1.2) local bg = display.newImageRect( level1, "assets/background.png", W\*4, H) bg.x = W/2 - 1450 bg.y = H/2 - 50 bg:scale(1.2,1.2) local bg = display.newImageRect( level1, "assets/background.png", W\*4, H) bg.x = W/2 + 1450 bg.y = H/2 - 50 bg:scale(1.2,1.2)local house = display.newImageRect( level1, "assets/simHouse.png", W, H) house.x = W/2 + 50 house.y = H/2 + 50 house.xScale = 1.1 house.yScale = .8 local floor = display.newRect(level1, W/2, H, W\*100, 20) floor:setFillColor( 0, 0, 0 ) physics.addBody( floor, "static", {density=1.0, friction=0.02, bounce=0.2} ) local zombie = require("zombie") zombieShape = {-50,-90, 50,-90, 40, 95, -40,95} physics.addBody( zombie, {density=5.0, friction=.05, bounce=0.2, shape=zombieShape} ) zombie:scale(.5,.5) zombie.y = H/2 + 75 zombie.type = "zom" level1:insert(zombie) local player = require("player") playerShape = {-75,-75, 75,-75, -50, 90, 50, 90} physics.addBody( player, {density=1.0, friction = 0.02, bounce=0.2, shape=playerShape} ) player.x = W/2 - 300 player.y = H/2 + 100 player:scale(.4,.4) level1:insert(player) player.score = 0 local gun = display.newImageRect( level1, "assets/ak-47.png", 150, 50) grpHUD.score = display.newText( grpHUD, "score: 0", W/4 - 300, 40, "Arial", 30 ) local function changeScore(amt) local function updateHUD() grpHUD.score.text = "score: " .. player.score end player.score = player.score + amt updateHUD() end local function upgrade() level1.isVisible = false zombie.isVisible = false shop.isVisible = true local shop = display.newImageRect( shop, "assets/gunWall.jpg", W/2 , H/2 ) end local function keyHandler(event) if(event.keyName == "space") then if(event.phase == "down") then shoot() else end end if(event.keyName == "up" and player.x \< 300 and player.x \> 40) then upgrade() else end end function onRedraw(event) player.rotation = 0 print(player.x) local vx, vy = player:getLinearVelocity() local onGround = (vy \< 2) and (vy \> -2) player:applyForce( (dpad.x\_touch \* 50), 0, player.x, player.y ) if(dpad.x\_touch \> 0) then player.xScale = .4 gun.xScale = 1 elseif(dpad.x\_touch \< 0) then player.xScale = -.4 gun.xScale = -1 end if (onGround) then if((vx \> 2) or (vx \< -2)) then if(player.sequence~="walk") then player:setSequence("walk") player:play() end else if(player.sequence~="idle") then player:setSequence("idle") player:play() end end elseif(vy \> 10) then --falling player:setSequence("idle") player:play() else -- player is moving up -- do nothing because jump took care of it? end if (dpad.a\_touched) then -- jump button pressed if(onGround) then player:applyForce( 0, -5000, player.x, player.y ) if(player.sequence~="jump") then player:setSequence("jump") player:play() end end end local apparent\_x = player.x + level1.x if(apparent\_x \> RIGHT\_BOUND) then level1.x = level1.x - (apparent\_x - RIGHT\_BOUND) elseif(apparent\_x \< LEFT\_BOUND) then level1.x = level1.x + (LEFT\_BOUND - apparent\_x) end gun.x = player.x gun.y = player.y + 50 end function shoot() local function collided(event) local phase = event.phase local other = event.other local function listener() display.remove(other) changeScore(1000) end if other.type=="zom" and phase == "began" then other:setSequence("dead") other:play() timer.performWithDelay( 750, listener ) else end end local new\_bullet = display.newCircle( level1, gun.x, gun.y, 5 ) new\_bullet.x = gun.x + 80 new\_bullet.y = gun.y - 17 local function move\_bullet() new\_bullet.x = new\_bullet.x + 30 if(new\_bullet.y \< 0) then new\_bullet:removeSelf( ) else timer.performWithDelay( 30, move\_bullet , 1 ) end end physics.addBody( new\_bullet, "dynamic" ) new\_bullet.isSensor = true new\_bullet.gravityScale = 0 new\_bullet:addEventListener("collision", collided) timer.performWithDelay( 33, move\_bullet , 1 ) end Runtime:addEventListener( "enterFrame", onRedraw ) Runtime:addEventListener( "key", keyHandler ) start:addEventListener( "tap", startGame ) dpad.toFront()