0,ÿ±>Sï}WÿÍu§ğpº}%qyÚª}ò¾A¦ösï÷ôôô‘ÆòVl†3 SCREEN_WIDTH -(15+32) then px = SCREEN_WIDTH-(15+32) score = score - 20 if score <0 then score = 0 end end --x=x-curvature*2 distance=distance+.5 ti = ti + 10 -- Accumulate track curvature trackCurvature =trackCurvature+ (curvature * .00000005) moveParticles() drawRoad() --print(getTargetCurvature(),5,15,12) --print("DeltaT:"..frameDelta,5,5,12) drawDunes() drawParticles() --drawParticles() drawCar() if gameState == STATE_DEAD then local particleVelocity = { speed = (math.random()+14)/2, direction = -up+math.random(-1,1) } local spawnPosition = {x=px+25,y=py+(modVal)*2+50} --function spawnParticle(position, velocity, maxLifetime,colours, maxSize, deceleration, type) spawnParticle(spawnPosition, particleVelocity,20, bloodColours, 3, 0.04, 3) spr(6,px,py+(modVal)*2,0,3,0,0,2,2) else spr(modVal,px,py+(modVal)*2,0,3,0,0,2,2) end print("SCORE:"..score.."m",5,5,12) end function doDead() if deadDone == false then music(1,0,0,0,0,60,2) deadDone = true end print("ROADKILL!",65,60,1,1,2) if btn(4) then music(0,0,0,1,0,60,2) sfx(48,'F-1',170,3,15,0) gameState = STATE_PLAY deadDone = false carY = carStartY carI=0 score = 0 end --sfx(0,"B-6",30,0,12) end print("Press 'Z' to Restart",105,130,1) end function getCurrentTrack() -- local dCount = 0 -- for i,v in ipairs(trackSections) do -- dCount = dCount+v[2] -- if dCount >= distance then return i end -- end -- --distance = 0 if distance > 5500 then distance=0 end return (distance//300)+1 end function getCurrentCurvature() --curvature=curvature+getTargetCurvature() return (getTargetCurvature() - curvature)*0.000001 end function getTargetCurvature() return trackSections[getCurrentTrack()][1] end function getDistance ( x1, y1, x2, y2 ) local dx = x1 - x2 local dy = y1 - y2 return math.sqrt ( dx * dx + dy * dy ) end function drawCar() local carModVal = (carI%120//30)+1 local perspective = carY/SCREEN_HEIGHT/2.0 local perspective2 = .5 local midPoint = 0.5 +(curvature)*math.pow((1.0-perspective*4),4)/2.0 local staticMidPoint = 0.5 +(curvature)*math.pow((1.0-perspective2*4),4)/2.0 -- print("carModVal= "..carModVal,20,20,12) local row = SCREEN_HEIGHT/2+carY --y = 32 - 0.5*x + 0.5*x^2 local currentSpr = 32--32-0.5*carModVal+((carModVal*carModVal)*.5) if carModVal==1 then currentSpr = 32 end if carModVal == 2 then currentSpr = 33 end if carModVal == 3 then currentSpr = 35 end if carModVal == 4 then currentSpr = 38 end --y = 0.25 + 0.45*x + 0.25*x^2 -- sprite size local sprSize = 0.3 + 0.45*carModVal + 0.25*(carModVal*carModVal) carX=((midPoint+(perspective*(lane*3)))*SCREEN_WIDTH)-(sprSize*8) if carModVal == 4 then --if the car is at the bottom of the screen then check for player collision if getDistance(carX+40,0,px,0)<25 then gameState = STATE_DEAD sfx(49,'F-3',30,3,15,0) end end -- print("currentSprSize= "..sprSize,20,60,12) --spr(currentSpr,carX+(curvature*120)-(sprSize*4)+20,carY-(sprSize*4),0,2,0,0,sprSize,sprSize) spr(currentSpr,carX,row-(sprSize*8),0,2,0,0,sprSize,sprSize) carI = carI+3 -- print("midPoint= "..midPoint*SCREEN_WIDTH,20,80,12) if carI> 110 then carY = 500 carX = 500 end if carI > 200 then sfx(48,'F-1',170,3,15,0) carY = carStartY carI=0 lane = nextLane nextLane= math.random(0,1) if lane == 0 then lane = -1 end -- if lane < .5 then lane = 3 end end carY = carY + carModVal/3 -- if lane == - 1 then --CAR PARTICLES local spawnPosition = {x=(midPoint+(perspective*(lane*3)))*SCREEN_WIDTH,y=(SCREEN_HEIGHT/2)+5} for particle = 1, 5 do direction = up+(math.random(-10,10)/10.0) --direction = keepAngleInRange(direction) particleVelocity = { speed = (math.random()+4)/2, direction = direction } spawnParticle(spawnPosition, particleVelocity,30, smokeColours, 3, 0.03, math.random(1,3)) end -- for --NEXT CAR PARTICLES local particleVelocity = { speed = (math.random()+4)/2, direction = up+(math.random(-10,10)/10.0) } local spawnPosition = {x=(staticMidPoint*SCREEN_WIDTH)+(nextLane*20)-5,y=(SCREEN_HEIGHT/2)} --function spawnParticle(position, velocity, maxLifetime,colours, maxSize, deceleration, type) spawnParticle(spawnPosition, particleVelocity,20, smokeColours, 2, 0.03, 2) particleVelocity = { speed = (math.random()+4)/2,direction = up+(math.random(-10,10)/10.0) } spawnParticle(spawnPosition, particleVelocity,20, smokeColours, 12, 0.03, 1) -- end end function drawRoad() for y = 0, SCREEN_HEIGHT/2.0,2 do for x = 0, SCREEN_WIDTH,2 do local perspective = y/SCREEN_HEIGHT/2.0 local currentCurve = getCurrentCurvature() curvature=curvature+currentCurve local midPoint = 0.5 +curvature*math.pow((1.0-perspective*4),4)/2.0 local roadWidth = 0.05 + perspective*4 local clipWidth = roadWidth * 0.15 roadWidth = roadWidth*.5 local leftGrass = (midPoint-roadWidth-clipWidth)*SCREEN_WIDTH local leftClip = (midPoint-roadWidth)*SCREEN_WIDTH local rightGrass = (midPoint+roadWidth+clipWidth)*SCREEN_WIDTH local rightClip = (midPoint+roadWidth)*SCREEN_WIDTH local row = SCREEN_HEIGHT/2+y local sinVal= math.sin(20.0*math.pow(1.2-(perspective*5),3)+distance*.1) local grassColour if sinVal > 0.0 then grassColour = 08 clipColour =06 else grassColour = 09 clipColour =05 end if x>0 and x< leftGrass then drawPix(x,row,grassColour) elseif x>leftGrass and x< leftClip then drawPix(x,row,clipColour) elseif x>leftClip and x< rightClip then drawPix(x,row,04) elseif x>rightClip and x< rightGrass then drawPix(x,row,clipColour) elseif x>rightGrass and x< SCREEN_WIDTH then drawPix(x,row,grassColour) end end end end function drawPix(x,y,colour) pix(x,y,colour) pix(x-1,y,colour) pix(x,y-1,colour) pix(x-1,y-1,colour) pix(x+1,y,colour) pix(x+1,y-1,colour) end function drawDunes() local duneHeight = 0 local currentCurve = trackCurvature for dx = 0,SCREEN_WIDTH do duneHeight = math.abs(math.sin(dx*0.01+currentCurve*700000.0)*16.0) for dy = (SCREEN_HEIGHT/2.0)-duneHeight,SCREEN_HEIGHT/2.0 do pix(dx,dy,03) end end end function spawnParticle(position, velocity, maxLifetime, colours, maxSize, deceleration, type) local particle = { position = { x = position.x, y = position.y }, velocity = { speed = velocity.speed, direction = velocity.direction }, lifeTimer = (maxLifetime / 2) + (math.random() * maxLifetime / 2), colours = colours, size = math.random(1, maxSize), deceleration = deceleration, type = type } table.insert(particles, particle) end -- spawnParticle function moveParticles() for index, particle in ipairs(particles) do particle.lifeTimer = particle.lifeTimer - 1 if particle.lifeTimer < 0 then table.remove(particles, index) else particle.position = movePointByVelocity(particle) end --if particle.velocity.speed = particle.velocity.speed - particle.deceleration if particle.velocity.speed < 0 then particle.velocity.speed = 0 end --gravObject(particle) end -- for end function drawParticles() local particleColour = 0 for index, particle in ipairs(particles) do particleColour = particle.colours[ math.random(1, #particle.colours) ] if particle.type == 2 then circ(particle.position.x, particle.position.y, particle.size, particleColour) elseif particle.type == 1 then pix(particle.position.x, particle.position.y, particleColour) else rect(particle.position.x, particle.position.y, particle.size, particle.size, particleColour) end -- if end -- for end function movePointByVelocity(object) components = getVectorComponents(object.velocity) local newPosition = { x = object.position.x + components.xComp, y = object.position.y + components.yComp} return newPosition end -- movePointByVelocity function getVectorComponents(vector) local xComp = vector.speed * math.cos(vector.direction) local yComp = vector.speed * math.sin(vector.direction) local components = { xComp = xComp, yComp = yComp } return components end -- getVectorComponents