Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rect = graydraw.rect
- local setColor = graydraw.setcolor
- local wait = misc.wait
- local line = graydraw.line
- local graytext = graydraw.text
- local fill = graydraw.fill
- local pixel = graydraw.pixel
- local random = misc.random
- car = {height = 8, width = 8, sprite = "\000\000<((f^fz(<V<(jvNnr8<V\000"}
- screenWidth = 128
- screenHeight = 64
- ai = {x = {}, y = {}, speed = {}, topspeed = {}, number = 3}
- continue = 0
- done = 0
- gDoorPosition = {0,0,0}
- gDoorText = {"Play", "Optn", "Help"}
- gDoorActive = 1
- i = 0
- invert = 0
- Key = 0
- key_alpha = 33
- key_left = 37
- key_right = 40
- key_down = 38
- key_up = 39
- key_exit = 36
- key_shift = 41
- player = {x = 0, y = 0, speed = 0, topspeed = 6}
- function main()
- setColor(1)
- menu()
- end
- function menu()
- clear nil
- while done ~= 1 do
- if key(key_left) then gDoorActive = gDoorActive - 1 wait(3) end
- if key(key_right) then gDoorActive = gDoorActive + 1 wait(3) end
- if key(key_exit) then done = 1 end
- if key(key_shift) then selection = gDoorActive continue = 1 end
- if gDoorActive < 1 then gDoorActive = 1 end
- if gDoorActive > 3 then gDoorActive = 3 end
- if selection == 1 then play()
- elseif selection == 2 then optn()
- elseif selection == 3 then help()
- end
- selection = 0
- for i = 1, 3, 1 do
- if i == gDoorActive and gDoorPosition[i] < 30 then gDoorPosition[i] = gDoorPosition[i] + 1
- elseif gDoorPosition[i] > 0 then gDoorPosition[i] = gDoorPosition[i] - 1 end
- end
- for ix = 1, 3, 1 do
- garageDoor(ix * 35 - 20, 25, 30, 30, gDoorPosition[ix], 5, gDoorText[ix], 5)
- end
- refresh2()
- wait(1)
- end
- continue = 0
- end
- function garageDoor(x, y, width, height, position, panelHeight, text, margin)
- buffer = height/2
- graytext(x + margin, y + buffer, text) --display text
- rect(x, y, x + width, y + height, 5, 5) --draw garage
- rect(x, y, x + width, y + height - position, 4, 0) --draw door
- --draw panels
- for iy = height - position, 0, -panelHeight do
- line(x, y + iy, x + width, y + iy, 4)
- end
- end
- function play()
- clear nil
- var = 0
- iy = 0
- for i=1, ai.number, 1 do
- ai.y[i] = 0
- ai.x[i] = i*8+1
- ai.topspeed[i] = 6
- if i == 1 then ai.speed[i] = ai.topspeed[i] else ai.speed = 1 + random(ai.topspeed[i]) end
- end
- player.y = 0
- --[[--
- graytext(5, 5, "Please Wait...")
- refresh2()
- clear nil
- for iy=1, screenHeight, 1 do
- for ix = 1, screenWidth, 1 do
- if i == 1 then pixel(ix, iy, 4) i = 0 else i = i + 1 end
- end
- if i==0 then i = 1 else i = 0 end
- end
- --]]--
- line(42, 0, 42, 64, 4)
- line(84, 0, 84, 64, 4)
- refresh2()
- --game loop
- while not key(key_exit) do
- rect(43, 0, 83, 64, 0, 0) --clears only the road
- if key(key_left) and player.x > 0 then player.x = player.x - 1
- elseif key(key_right) and player.x < 40 - car.width + 1 then player.x = player.x + 1
- elseif key(key_shift) then player.speed = player.speed + 1
- elseif key(key_alpha) then player.speed = player.speed - 1
- end
- if player.speed > player.topspeed then player.speed = player.topspeed
- elseif player.speed < 0 then player.speed = 0
- end
- aiRace()
- spritexy player.x + 43, screenHeight - car.height, car.sprite
- player.y = player.y + player.speed
- refresh2()
- end
- waitKey(key_exit)
- clear nil
- end
- function aiRace()
- for i=1, ai.number, 1 do
- --ai and collisions with ai
- for j=1, ai.number do
- --if car i is not the same as car j
- if i~=j then
- --if car j is in front or behind car i
- if ai.x[j] > ai.x[i] - 16 and ai.x[j] < ai.x[i] + 16 then
- --if car j is in front
- if ai.y[j] > ai.y[i] and ai.y[j] < ai.y[i] + 16 then
- if ai.speed[i] > 0 then ai.speed[i] = ai.speed[i] - 1 else ai.x[i] = ai.x[i] + 1 end
- end
- --if car j is behind
- if ai.y[j] < ai.y[i] and ai.y[j] > ai.y[i] - 16 then
- if ai.speed[i] < ai.topspeed[i] then ai.speed[i] = ai.speed[i] + 1 else ai.x[i] = ai.x - 1 end
- end
- end
- --if car j is left or right of car i
- if ai.y[j] > ai.y[i] - 16 and ai.y[j] < ai.y[i] + 16 then
- --if car j is to the right
- if ai.x[j] > ai.x[i] and ai.x[j] < ai.x[i] + 16 then
- --if the car i is not against the left wall
- if ai.x[i] > 0 then ai.x[i] = ai.x[i] - 1 elseif ai.speed > 0 then ai.speed[i] = ai.speed[i] - 1 end
- end
- --if car j is to the left
- if ai.x[j] < ai.x[i] and ai.x[j] > ai.x[i] - 16 then
- --if car i is not against right wall
- if ai.x[i] < 40 then ai.x[i] = ai.x[i] + 1 elseif ai.speed > 0 then ai.speed[i] = ai.speed[i] - 1 end
- end
- end
- end
- end
- --collisions with player
- if ai.y[i] > player.y and ai.y[i] < player.y + 8 and ai.x[i] > player.x and ai.x[i] < player.x + 8 then crash() end
- --display
- buffer = ai.y[i] - player.y
- spritexy ai.x[i] + 43, screenHeight - car.height - buffer, car.sprite
- ai.y[i] = ai.y[i] + ai.speed[i]
- end
- end
- function crash()
- clear nil
- graytext(1, 1, "You Died!")
- refresh2()
- wait(100)
- menu()
- end
- function optn()
- clear nil
- graytext(1, 1, "Options Menu")
- refresh2()
- waitKey(key_exit)
- clear nil
- end
- function help()
- clear nil
- graytext(1, 1, "How may I help you?")
- refresh2()
- waitKey(key_exit)
- clear nil
- end
- function bye()
- clear nil
- graytext(1, 1, "Bye!")
- refresh2()
- wait(100)
- end
- function waitKey(Key)
- while not key(Key) do wait(3) end
- wait(3)
- end
- function refresh2()
- --if invert == 1 then rect(0, 0, screenWidth, screenHeight) end
- if invert == 1 then fill(5) end
- refresh
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement