Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Highscore
- highscore = ini.read("scores.ini",highscore,0)
- math.randomseed(os.time())
- --Colors
- red = color.new(255,0,0)
- alpha = color.new(0,0,0,0)
- --Jugador
- player = { x = 200, y = 200}
- player.width = 21 --ancho
- player.height = 32 --altura
- playerlinks = image.load("playerl.png")
- playerrechts = image.load("playerr.png")
- --Regalo 1
- present = { x = math.random(22,354), y = 0 }
- present.width = 20 --ancho
- present.height = 20 --altura
- presentimg = image.load("present.png")
- --Regalo 2
- present2 = { x = math.random(22,354), y = 0 }
- present2.width = 20 --ancho
- present2.height = 20 --altura
- presentimg2 = image.load("present2.png")
- --Other Images
- bg = image.load("bg.png")
- --Other stuff
- speed = 1
- speed2 = 1.2
- level = 1
- presents = 0
- verloren = 0 --perdido
- leben = 10 --vidas
- zaehler = timer.new() --contador
- mode = "game" --modo
- counter = 0 --contador
- musica = sound.load("song.mp3")
- --Player movimientos
- function playerleft()
- modus = 1
- player.x = player.x - 4
- end
- function playerright()
- modus = 2
- player.x = player.x + 4
- end
- --Player en pantalla
- function blit_player()
- if modus == 1 then
- screen.blit(player.x,player.y,playerlinks)
- elseif modus == 2 then
- screen.blit(player.x,player.y,playerrechts)
- end
- end
- --Player limites pantalla
- function check_player_position()
- if player.x > 342 then
- player.x = 342
- end
- if player.x < 20 then
- player.x = 20
- end
- end
- --Regalos ( Objetos )
- function Presentcreate()
- x = present.x
- y = present.y
- screen.blit(present.x,present.y,presentimg,true)
- end
- function Presentcreate2()
- x = present2.x
- y = present2.y
- screen.blit(present2.x,present2.y,presentimg2,true)
- end
- function movepresents()
- present.y = present.y + speed
- present2.y = present2.y + speed2
- end
- --Level up
- function levelup()
- if not puffer then puffer = 1 end
- if presents == 5*puffer then
- speed = speed + 0.1
- level = level + 1
- puffer = puffer + 1
- end
- end
- --Si se olvida de un regalo
- function leave_present()
- if present.y > 255 then
- verloren = verloren + 1
- leben = leben - 1
- present.y = -20
- end
- end
- function leave_present2()
- if present2.y > 255 then
- verloren = verloren + 1
- leben = leben - 1
- present2.y = -20
- end
- end
- --Gameover
- function gameover()
- if leben == 0 then
- if level > highscore then
- screen.print(378,16,"Neuer Highscore!",red)
- highscore = level
- file = io.open("highscore.txt","w")
- file:write(level)
- file:close()
- end
- dofile("gameover.lua")
- end
- end
- --Compruebe si usted coge un regalo, si es asà reiniciar los regalos
- function check_for_present()
- if ( player.x + player.width >= present.x ) and ( player.x <= present.x + present.width ) and ( player.y <= present.y + present.height ) and ( player.y + player.height >= present.y ) then
- presents = presents + 1
- present.y = -20
- present.x = math.random(22,354)
- end
- end
- function check_for_present2()
- if ( player.x + player.width >= present2.x ) and ( player.x <= present2.x + present2.width ) and ( player.y <= present2.y + present2.height ) and ( player.y + player.height >= present2.y ) then
- presents = presents + 1
- present2.y = -20
- present2.x = math.random(22,354)
- end
- end
- while true do
- musica:play()
- bg:blit(0,0)
- screen.print(378,16,"Bannanen:"..presents,0.7 red,alpha)
- screen.print(378,25,"Level:"..level,0.7 red,alpha)
- screen.print(378,35,"Verpasst:"..verloren,0.7 red,alpha)
- screen.print(378,45,"Leben:"..leben,0.7 red,alpha)
- screen.print(378,65,"Highscore:"..highscore,0.7 red,alpha)
- controls.read()
- if mode == "game" and counter > 30 and controls.press("start") then
- mode = "pause"
- end
- if mode == "pause" and counter > 30 and controls.press("start") then
- mode = "game"
- end
- if mode == "pause" then
- screen.print(160,110,"Pause:",0.7 red,alpha)
- screen.print(130,120,"Start = Weiter",0.7 red,alpha)
- end
- blit_player()
- Presentcreate()
- if level >= 5 then
- Presentcreate2()
- leave_present2()
- end
- if mode == "game" then
- check_for_present()
- check_for_present2()
- movepresents()
- levelup()
- leave_present()
- gameover()
- check_player_position()
- if controls.left() then playerleft() end
- if controls.right() then playerright() end
- end
- counter = counter+1
- screen.flip()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement