Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("starting aspirin...")
- --function variables
- local drawRectFill = zmg.drawRectFill
- local drawCircle = zmg.drawCircle
- local fastCopy = zmg.fastCopy
- local makeColor = zmg.makeColor
- local drawPoint = zmg.drawPoint
- local drawLine = zmg.drawLine
- local clear = zmg.clear
- local drawText = zmg.drawText
- local keyDirectPoll = zmg.keyDirectPoll
- local keyDirect = zmg.keyDirect
- local floor = math.floor
- local random = math.random
- --variables
- local key = {F1=79, F2=69, F3=59, F4=49, F5=39, F6=29, Alpha=77, Exit=47, Optn=68, Up=28, Down=37, Left=38, Right=27}
- local color = {bg=makeColor("black"),fg=makeColor("blue"),fg2=makeColor("red"),line=makeColor("lightblue")}
- --lines={{x1,y1,direction(-1,1),direction(0=horiz,1=vert)},{...}}
- local lines={}
- local player={x=384/2,y=216/2,size=5,speed=2}
- local target={x=384/2,y=216/4,size=10}
- local linewidth=20
- local linespeed=2
- local score=0
- --screen vars
- local SCREEN_WIDTH = 384
- local SCREEN_HEIGHT = 216
- --game loop
- keyDirectPoll()
- while exit~=1 do
- if keyDirect(key.Exit)>0 then
- exit=1
- end
- --clear screen
- drawRectFill(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,color.bg)
- --display score
- drawText(1,1,"SCORE: " .. score,color.fg2,color.bg)
- --[[debug
- drawText(1,20,"DEBUG: " .. #lines,color.fg2,color.bg)
- --]]
- --keys
- if keyDirect(key.Left)>0 and player.x>0 then player.x=player.x-player.speed
- elseif keyDirect(key.Right)>0 and player.x<SCREEN_WIDTH then player.x=player.x+player.speed
- end
- if keyDirect(key.Up)>0 and player.y>0 then player.y=player.y-player.speed
- elseif keyDirect(key.Down)>0 and player.y<SCREEN_HEIGHT then player.y=player.y+player.speed
- end
- --calculations
- --check collision with target
- if player.x<target.x+target.size and player.x>target.x-target.size
- and player.y-player.size<target.y+target.size and player.y+player.size>target.y-target.size then
- target.x=random(0,SCREEN_WIDTH)
- target.y=random(0,SCREEN_HEIGHT)
- score=score+100
- -- create lines
- if player.y>SCREEN_HEIGHT/2 then
- lines[#lines+1]={random(0,SCREEN_WIDTH/2),random(0,SCREEN_HEIGHT/2-player.size),1,0}
- else
- lines[#lines+1]={random(0,SCREEN_WIDTH/2),random(SCREEN_HEIGHT/2+player.size,SCREEN_HEIGHT),1,0}
- end
- if player.x>SCREEN_WIDTH/2 then
- lines[#lines+2]={random(0,SCREEN_WIDTH/2-player.size),random(0,SCREEN_HEIGHT/2),1,1}
- else
- lines[#lines+2]={random(SCREEN_WIDTH/2+player.size,SCREEN_WIDTH),random(0,SCREEN_HEIGHT/2),1,1}
- fastCopy()
- end
- end
- --lines
- for i=1,#lines,1 do
- --if horizontal
- if lines[i][4]==0 then
- --reverse direction if hit edge
- if lines[i][1]>SCREEN_WIDTH-linewidth or lines[i][1]<0 then
- lines[i][3]=lines[i][3]*-1
- end
- --check collisions
- if lines[i][1]+linewidth>player.x-player.size and lines[i][1]<player.x+player.size
- and lines[i][2]>player.y-player.size and lines[i][2]<player.y+player.size then
- print("you lose")
- exit=1
- end
- --move it along
- lines[i][1]=lines[i][1]+linespeed*lines[i][3]
- --draw it
- drawLine(lines[i][1],lines[i][2],lines[i][1]+linewidth,lines[i][2],color.line)
- end
- --if vertical
- if lines[i][4]==1 then
- --reverse direction if hit edge
- if lines[i][2]>SCREEN_HEIGHT-linewidth or lines[i][2]<0 then
- lines[i][3]=lines[i][3]*-1
- end
- --check collisions
- if lines[i][2]+linewidth>player.y-player.size and lines[i][2]<player.y+player.size
- and lines[i][1]>player.x-player.size and lines[i][1]<player.x+player.size then
- print("you lose")
- exit=1
- end
- --move it along
- lines[i][2]=lines[i][2]+linespeed*lines[i][3]
- --draw it
- drawLine(lines[i][1],lines[i][2],lines[i][1],lines[i][2]+linewidth,color.line)
- end
- end
- keyDirectPoll()
- --display
- drawCircle(player.x,player.y,player.size,color.fg)
- drawCircle(target.x,target.y,target.size,color.fg2)
- fastCopy()
- keyDirectPoll()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement