Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- client.pause()
- client.SetGameExtraPadding(0,0,240-client.bufferwidth(),160-client.bufferheight())
- client.setwindowsize(2)
- local gameName="Platformer"
- local gameVersion="v0.13"
- local debugMode=false
- local debugPause=false
- local debugWallCollision={}
- local debugHitCollision={}
- local mode=0
- local frames=0
- local background=nil
- local foreground=nil
- local image=nil
- local fadeFrames=0
- local currentRoom=0
- local gamescreen=nil
- local reachedIngame=false
- local tileSize=27
- local currentDisplayWidth=10 --tiles
- local currentDisplayHeight=7 --tiles
- local Camera = {
- X = 0,
- Y = 0,
- Xcap = 0,
- Ycap = 0
- }
- local MapOffset = {
- X = 0,
- Y = 0
- }
- local Actor = {
- [1] = { HP=0,
- X=0,
- Y=0,
- width=20,
- height=38,
- dir=0, -- -1: left, 1: right},
- spd=0, --horizontal speed
- verticalspd=0, --vertical speed
- moves=false, --for horizontal movement
- grounded=false, --for vertical movement
- jumps=false
- },
- [2] = { HP=0},
- [3] = { HP=0},
- [4] = { HP=0},
- [5] = { HP=0},
- [6] = { HP=0},
- [7] = { HP=0},
- [8] = { HP=0}
- }
- local Map = {
- [1] = { {1,1,1,0,0,1,0,0,1,1,1,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
- {1,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,1,1,1,1,0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0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}
- }
- local Mouse = {
- X = 0,
- Y = 0,
- XBefore = 0,
- YBefore = 0,
- clickedFrames = 0,
- clicked = false
- }
- local Color = {
- Selected = 0xB0A0A0A0,
- Normal = 0xA0404040,
- Grey = 0xA0C0C0C0
- }
- local game = {
- [0]= function()
- mode=11 -- remove later
- foreground=0xFFFFFFFF
- fadeFrames=60
- console.clear()
- if frames>20 then mode=1 end
- end,
- [1]= function()
- image = "files/intro.dat"
- fadeIn()
- if frames>80 then mode=2 end
- end,
- [2]= function()
- fadeFrames=60
- if frames>300 then mode=3 end
- end,
- [3]= function()
- fadeOut()
- if frames>360 then mode=4 end
- end,
- [4]= function()
- fadeFrames=60
- mode=5
- end,
- [5]= function()
- image = "files/title.dat"
- fadeIn()
- if frames>420 then mode=6 end
- end,
- [6]= function()
- image = "files/title.dat"
- getMouse()
- button(80,70,80,16," PLAY",Color.Normal,true,function() mode=11
- frames=0 end)
- button(80,90,80,16,"BEST TIMES",Color.Normal,true,function() mode=10
- frames=0 end)
- --todo:actual highscore list
- button(80,110,80,16," OPTIONS",Color.Normal,true,function() mode=10
- frames=0 end)
- --todo:actual options functionality
- button(80,130,80,16," QUIT",Color.Normal,true,function() mode=7
- frames=0 end)
- text(206,145,gameVersion,0xFFFFFFFF)
- end,
- [7]= function()
- fadeFrames=60
- mode=8
- end,
- [8]= function()
- fadeOut()
- if frames>60 then mode=9 end
- end,
- [9]= function()
- foreground=nil
- background=nil
- image=nil
- client.SetGameExtraPadding(0,0,0,0)
- client.unpause()
- --todo:save times to file
- end,
- [10]= function()
- getMouse()
- image = nil
- text(20,20,"TEST SCREEN.\nNOTHING TO SEE HERE YET.\nGO BACK?",0xFFFFFFFF)
- button(20,70,40,16,"YES!",Color.Grey,false,function() mode=6 end)
- end,
- [11]= function()
- if reachedIngame then
- drawMap()
- debugMode=false
- debugPause=false
- end
- fadeFrames=60
- frames=0
- background=nil
- mode=12
- end,
- [12]= function()
- if reachedIngame then
- drawMap()
- end
- fadeOut()
- if frames>60 then mode=13 end
- end,
- [13]= function()
- prepareRoom()
- gui.clearImageCache()
- fadeFrames=60
- mode=14
- end,
- [14]= function()
- image = "files/sky.dat"
- drawMap()
- fadeIn()
- if frames>120 then
- mode=15
- frames=0
- reachedIngame=true
- end
- end,
- [15]= function() -- MAIN INGAME LOOP
- drawMap()
- drawPlayer()
- if not debugPause then
- if frames%2==0 then
- assertMapPosition()
- --enemyHitCollision()
- else
- --enemyMove()
- --enemyWallCollision()
- end
- playerWallCollision()
- getInput()
- playerMove()
- assertCameraScroll()
- end
- --remove this section later
- getMouse()
- if debugMode then debugColor=Color.Selected
- else debugColor=Color.Normal end
- if debugPause then pauseColor=Color.Selected
- else pauseColor=Color.Normal end
- button(170,8,58,16," Debug ",debugColor,false,function() debugMode=not debugMode end)
- button(170,26,58,16," Pause ",pauseColor,false,function() debugPause=not debugPause end)
- button(170,44,58,16," Reset ",Color.Normal,false,function() mode=11 end)
- -- -- -- -- -- -- --
- end
- }
- function img(x,y,path)
- gui.drawImage(path,x,y)
- end
- function text(x, y, text, color)
- gui.drawText(x, y, text,color,0x00000000,12,"Arial")
- end
- function button(posx,posy,width,height,label,color,mainmenu,clickedfunction)
- if Mouse.X>posx and Mouse.X<posx+width and Mouse.Y>posy and Mouse.Y<posy+height then
- if Mouse.clicked and Mouse.clickedFrames%8==1 then
- clickedfunction()
- end
- gui.drawBox(posx,posy,posx+width,posy+height,0xFFFFFFFF,color+0x30303030)
- if mainmenu then
- for a=0,10 do
- gui.drawLine(posx+1+a,posy+1,posx+1+a,posy+height-1,0xFFFFFFFF-0x18000000*a)
- gui.drawLine(posx+width-1-a,posy+1,posx+width-1-a,posy+height-1,0xFFFFFFFF-0x18000000*a)
- end
- end
- else
- gui.drawBox(posx,posy,posx+width,posy+height,color-0x00303030,color)
- if mainmenu then
- for a=0,10 do
- gui.drawLine(posx+1+a,posy+1,posx+1+a,posy+height-1,0xFF303030-0x18000000*a)
- gui.drawLine(posx+width-1-a,posy+1,posx+width-1-a,posy+height-1,0xFF303030-0x18000000*a)
- end
- end
- end
- text(posx+3,posy+1,label,0xFFFFFFFF)
- end
- function fadeIn()
- if fadeFrames>=0 then
- foreground=string.format("%x",math.floor(255/60*fadeFrames)) .. "FFFFFF"
- foreground=tonumber(foreground,16)
- fadeFrames=fadeFrames-1
- else
- foreground=nil
- end
- end
- function fadeOut()
- if fadeFrames>=0 then
- foreground=string.format("%x",math.floor(255/60*(60-fadeFrames))) .. "FFFFFF"
- foreground=tonumber(foreground,16)
- fadeFrames=fadeFrames-1
- else
- foreground=nil
- end
- end
- function prepareRoom()
- --todo, change this so it's not just for newgame but new rooms in general
- currentRoom=1
- Actor[1].HP=1000
- Actor[1].X=110
- Actor[1].Y=70
- Actor[1].dir=1
- Actor[1].spd=0
- Actor[1].verticalspd=0
- Actor[1].jumps=false
- Actor[1].grounded=true
- Actor[1].moves=false
- Actor[2].HP=nil
- Actor[3].HP=nil
- Actor[4].HP=nil
- Actor[5].HP=nil
- Actor[6].HP=nil
- MapOffset.X=0
- MapOffset.Y=0
- Camera.Xcap = (table.getn(Map[currentRoom][1])-currentDisplayWidth+1)*tileSize
- Camera.Ycap = (table.getn(Map[currentRoom])-currentDisplayHeight)*tileSize
- assertCameraScroll()
- end
- function getInput()
- Actor[1].moves=false
- keys = input.get()
- if keys.LeftArrow then --LEFT
- Actor[1].moves=true
- Actor[1].dir=-1
- elseif keys.RightArrow then --RIGHT
- Actor[1].moves=true
- Actor[1].dir=1
- end
- if keys.UpArrow then --JUMP
- if Actor[1].grounded then
- Actor[1].grounded=false
- Actor[1].verticalspd=-6
- end
- end
- end
- function getMouse()
- Mouse.X = input.getmouse().X
- Mouse.Y = input.getmouse().Y
- Mouse.clicked = input.getmouse().Left
- if Mouse.clicked then Mouse.clickedFrames = Mouse.clickedFrames + 1
- else Mouse.clickedFrames = 0 end
- end
- function drawMap()
- for a=MapOffset.Y+1,MapOffset.Y+currentDisplayHeight do
- for b=MapOffset.X+1,MapOffset.X+currentDisplayWidth do
- tilex=-Camera.X+tileSize*(b-1)
- tiley=-Camera.Y+tileSize*(a-1)
- if Map[currentRoom][a][b]==0 then -- nothing
- -- img(tilex,tiley,"files/mapTest0.dat")
- elseif Map[currentRoom][a][b]==1 then --wall
- img(tilex,tiley,"files/mapTest1.dat")
- end
- if debugMode then
- text(tilex,tiley,Map[currentRoom][a][b],0xFFFFFFFF)
- end
- end
- end
- if debugMode then
- for i=1,table.getn(debugWallCollision) do
- if table.getn(debugWallCollision)>0 then
- img(debugWallCollision[i][1],debugWallCollision[i][2],"files/mapTestC.dat")
- end
- end
- if not debugPause then
- debugWallCollision={}
- end
- end
- end
- function drawPlayer()
- PlayerX = Actor[1].X-Camera.X
- PlayerY = Actor[1].Y-Camera.Y
- --left
- gui.drawBox(PlayerX,PlayerY,PlayerX+Actor[1].width,PlayerY+Actor[1].height,0xFFFFFF00)
- end
- function playerMove()
- --apply speed, player gains distance
- Actor[1].X = Actor[1].X+Actor[1].spd
- Actor[1].Y = Actor[1].Y+Actor[1].verticalspd
- --moves right or left, runs to 0 if no button held
- if Actor[1].moves then
- Actor[1].spd = Actor[1].spd+Actor[1].dir
- elseif Actor[1].spd ~= 0 then
- if frames%3==0 then
- Actor[1].spd = Actor[1].spd-1*Actor[1].dir
- end
- end
- --moves up or down, gains distance
- if not Actor[1].grounded then
- if Actor[1].verticalspd < 5 then
- if frames%2==0 then
- Actor[1].verticalspd = Actor[1].verticalspd+1
- end
- end
- end
- --speed cap
- if Actor[1].spd>2 then Actor[1].spd=2
- elseif Actor[1].spd<-2 then Actor[1].spd=-2 end
- end
- function playerWallCollision()
- local empty
- local playerX = math.ceil(Actor[1].X/tileSize) -- this is where the player sits in terms of tile units
- local playerY = math.ceil(Actor[1].Y/tileSize)
- local collisionCheckRangeX = math.ceil((Actor[1].X+Actor[1].width)/tileSize) - playerX -- amount of tiles your hitbox extends into
- local collisionCheckRangeY = math.ceil((Actor[1].Y+Actor[1].height)/tileSize) - playerY
- local function moveLeft()
- Actor[1].X = (playerX+collisionCheckRangeX-1)*tileSize-Actor[1].width-1
- Actor[1].spd=0
- end
- local function moveRight()
- Actor[1].X = playerX*tileSize+1
- Actor[1].spd=0
- end
- local function moveBottom()
- Actor[1].Y = playerY*tileSize
- Actor[1].verticalspd=1
- end
- local function moveTop()
- Actor[1].Y= (playerY+collisionCheckRangeY-1)*tileSize - Actor[1].height-1 -- else, put character to the top
- Actor[1].verticalspd=0
- Actor[1].grounded=true
- end
- if Actor[1].spd ~=0 or Actor[1].verticalspd ~=0 then
- for a=0,collisionCheckRangeY do
- for b=0,collisionCheckRangeX do
- if debugMode then
- table.insert(debugWallCollision, {tileSize*(playerX+b-1)-Camera.X, (tileSize*(playerY+a-1))-Camera.Y})
- end
- if Map[currentRoom][playerY+a][playerX+b]==1 then
- --wall collision detected
- if b==0 and a==0 then -- TOP LEFT CORNER
- if (tileSize-(Actor[1].X-1)%tileSize) < (tileSize-(Actor[1].Y-1)%tileSize) then -- shortest distance is rightwards
- empty=true
- for z=1,math.max(1,collisionCheckRangeX) do -- if right is empty,
- if Map[currentRoom][playerY+a][playerX+b+z]==1 then
- empty=false
- break
- end
- end
- if empty then
- moveRight()
- else
- moveBottom()
- end
- else -- shortest distance is bottom
- empty=true
- for z=1,math.max(1,collisionCheckRangeY) do -- if bottom is empty,
- if Map[currentRoom][playerY+a+z][playerX+b]==1 then
- empty=false
- break
- end
- end
- if empty then
- moveBottom()
- else
- moveRight()
- end
- end
- elseif b==collisionCheckRangeX and a==0 then --TOP RIGHT CORNER
- if ((Actor[1].X+Actor[1].width)%tileSize) < (tileSize-(Actor[1].Y-1)%tileSize) then -- shortest distance is leftwards
- empty=true
- for z=1,math.max(1,collisionCheckRangeX) do -- if left is empty,
- if Map[currentRoom][playerY+a][playerX+b-z]==1 then
- empty=false
- break
- end
- end
- if empty then
- moveLeft()
- else
- moveBottom()
- end
- else -- shortest distance is bottom
- empty=true
- for z=1,math.max(1,collisionCheckRangeY) do -- if bottom is empty,
- if Map[currentRoom][playerY+a+z][playerX+b]==1 then
- empty=false
- break
- end
- end
- if empty then
- moveBottom()
- else
- moveLeft()
- end
- end
- elseif b==0 and a==collisionCheckRangeY then --BOTTOM LEFT CORNER
- if (tileSize-(Actor[1].X-1)%tileSize) < ((Actor[1].Y+Actor[1].height-1)%tileSize) then -- shortest distance is rightwards
- empty=true
- for z=1,math.max(1,collisionCheckRangeX) do -- if right is empty,
- if Map[currentRoom][playerY+a][playerX+b+z]==1 then
- empty=false
- break
- end
- end
- if empty then
- moveRight()
- else
- moveTop()
- end
- else -- shortest distance is top
- empty=true
- for z=1,math.max(1,collisionCheckRangeY) do -- if top is empty,
- if Map[currentRoom][playerY+a-z][playerX+b]==1 then
- empty=false
- break
- end
- end
- if empty then
- moveTop()
- else
- moveRight()
- end
- end
- elseif b==collisionCheckRangeX and a==collisionCheckRangeY then --BOTTOM RIGHT CORNER
- if ((Actor[1].X+Actor[1].width)%tileSize) < ((Actor[1].Y+Actor[1].height)%tileSize) then -- shortest distance is leftwards
- empty=true
- for z=1,math.max(1,collisionCheckRangeX) do -- if left is empty,
- if Map[currentRoom][playerY+a][playerX+b-z]==1 then
- empty=false
- break
- end
- end
- if empty then
- moveLeft()
- else
- moveTop()
- end
- else -- shortest distance is top
- empty=true
- for z=1,math.max(1,collisionCheckRangeY) do -- if top is empty,
- if Map[currentRoom][playerY+a-z][playerX+b]==1 then
- empty=false
- break
- end
- end
- if empty then
- moveTop()
- else
- moveLeft()
- end
- end
- end
- end
- end
- end
- end
- -- if no wall below, make character fall
- if Map[currentRoom][playerY+collisionCheckRangeY+1][playerX] == 0
- and Map[currentRoom][playerY+collisionCheckRangeY+1][playerX+collisionCheckRangeX] == 0
- and Map[currentRoom][playerY+collisionCheckRangeY][playerX] == 0
- and Map[currentRoom][playerY+collisionCheckRangeY][playerX+collisionCheckRangeX] == 0
- then
- Actor[1].grounded=false
- end
- end
- function assertCameraScroll()
- if Actor[1].X<120 then
- Camera.X=0
- else
- Camera.X=Actor[1].X-120
- end
- if Actor[1].Y<80 then
- Camera.Y=0
- else
- Camera.Y=Actor[1].Y-80
- end
- if Camera.X>Camera.Xcap then Camera.X=Camera.Xcap end
- if Camera.Y>Camera.Ycap then Camera.Y=Camera.Ycap end
- end
- function assertMapPosition()
- MapOffset.X = math.floor(Camera.X / tileSize)
- MapOffset.Y = math.floor(Camera.Y / tileSize)
- end
- while true do
- if not client.ispaused() then client.pause() end
- if image~=nil then
- img(0,0,image)
- end
- if background~=nil then
- gui.drawBox(-1,-1,240,160,0x00000000,background)
- end
- game[mode]()
- if foreground~=nil then
- gui.drawBox(-1,-1,240,160,0x00000000,foreground)
- end
- if client.ispaused() then
- gui.DrawNew("emu")
- emu.yield()
- else
- emu.frameadvance()
- end
- frames=frames+1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement