--[[ burnin ]]-- --speed stuff speed = 250 boostspeed = 290 curspeed = 0 boostfactor = .02 --[[ System.irdaWrite(string) hi = System.irdaRead() ]]-- carX=50 carY=152 oponX=310 oponY=152 System.usbDiskModeActivate() System.irdaInit() car = Image.load("car.png") bg = Image.load("bg.png") red = Color.new(255,0,0) white = Color.new(255,255,255) function collisionCheck(objectX, objectY, objectWidth, objectHeight, object2X, object2Y, object2Width, object2Height) ax1 = objectX ax2 = objectX + objectWidth ay1 = objectY ay2 = objectY + objectHeight bx1 = object2X bx2 = object2X + object2Width by1 = object2Y by2 = object2Y + object2Height if(ax1 > bx1 and ax1 < bx2 and ay1 > by1 and ay1 < by2) then return true -- the top left corner of object 1 is in object 2 if(ax2 > bx1 and ax2 < bx2 and ay1 > by1 and ay1 < by2) then return true -- the top right corner of object 1 is in object 2 if(ax1 > bx1 and ax1 < bx2 and ay2 > by1 and ay2 < by2) then return true -- the bottom left corner of object 1 is in object 2 if(ax2 > bx1 and ax2 < bx2 and ay2 > by1 and ay2 < by2) then return true -- the bottom right corner of object 1 is in object 2 return false end bgX = 0 carX = (480-car:width())/2 distance = 0 boost = 100 opon = car opondistance = -(272/2) input = Controls.read() while true do oldinput = input input = Controls.read() if input:select() then break end if input:r() then if math.floor(boost) > 0 then curspeed = curspeed + speed*boostfactor boost = boost - curspeed / 100 / 5 else boost = 0 end end if input:cross() and oldinput:cross() and curspeed < speed+1 and ((not input:r()) or (math.floor(boost) < 1 and input:r() )) then curspeed = curspeed + speed/5/(curspeed+1) if curspeed >= speed then curspeed = speed end else --boost has made the mph higher than max, but is not currently boosting curspeed = curspeed - speed/5/(curspeed+1)*3 end if not input:cross() and not input:r() then curspeed = curspeed - speed/5/(curspeed+1)*2 end if curspeed <0 then curspeed = 0 end if curspeed >= boostspeed then curspeed = boostspeed end distance = distance + curspeed / 5 bgX = bgX + curspeed / 15 analog = input:analogX() if analog < 25 and analog > -25 then analog = 0 end --[[ if input:left() then carX = carX - analogx/20 elseif input:right() then carX = carX + analogy/20 end ]]-- carX = carX + analog/20 screen:print(0,40,analog,Color.new(255,255,255)) if bgX<=-272 then bgX = 0 end if bgX>1 then bgX = bgX -271 end boost = boost + curspeed / 1000 / 5 if boost >100 then boost = 100 end if boost < 0 then boost = 0 end opondistance = opondistance +14 + curspeed/5/2 + math.random(-3,3) --[[ System.irdaWrite(distance) screen.waitVblankStart() --read the IrDa port, and backup the vars oldopondistance = opondistance opondistance = tostring(System.irdaRead()) screen.waitVblankStart() if opondistance == "nil" then opondistance = oldopondistance end opondistance = tonumber(opondistance) if opondistance == nil then opondistance = oldopondistance end ]]-- if carX + carY = oponX + oponY then curspeed=100 end if distance==100000 then screen:print(100, 100, "Collision!", red) end screen:clear() screen:blit(0,bgX,bg) screen:blit(0,bgX+bg:height(),bg) screen:blit(480/2+50,distance-opondistance+110,opon) screen:blit(carX,152,car) screen:print(0,0,"Distance Traveled: "..distance.." pixels",white) screen:print(0,10,"Current Speed: "..math.floor(curspeed).."km/h",white) screen:print(0,20,"Opponant at: "..math.floor(distance-opondistance).." Distance: "..opondistance,white) screen:print(1,271-5-10,math.floor(boost),white) screen:fillRect(1,271-5,boost,5,Color.new(255,0,0)) screen.waitVblankStart() screen.flip() end