SHOW:
|
|
- or go back to the newest paste.
| 1 | - | print("starting aspirin...") |
| 1 | + | print("starting aspirin...")
|
| 2 | - | --function variables |
| 2 | + | --function variables |
| 3 | - | local drawRectFill = zmg.drawRectFill |
| 3 | + | local drawRectFill = zmg.drawRectFill |
| 4 | - | local drawCircle = zmg.drawCircle |
| 4 | + | local drawCircle = zmg.drawCircle |
| 5 | - | local fastCopy = zmg.fastCopy |
| 5 | + | local fastCopy = zmg.fastCopy |
| 6 | - | local makeColor = zmg.makeColor |
| 6 | + | local makeColor = zmg.makeColor |
| 7 | - | local drawPoint = zmg.drawPoint |
| 7 | + | local drawPoint = zmg.drawPoint |
| 8 | - | local drawLine = zmg.drawLine |
| 8 | + | local drawLine = zmg.drawLine |
| 9 | - | local clear = zmg.clear |
| 9 | + | local clear = zmg.clear |
| 10 | - | local drawText = zmg.drawText |
| 10 | + | local drawText = zmg.drawText |
| 11 | - | local keyDirectPoll = zmg.keyDirectPoll |
| 11 | + | local keyDirectPoll = zmg.keyDirectPoll |
| 12 | - | local keyDirect = zmg.keyDirect |
| 12 | + | local keyDirect = zmg.keyDirect |
| 13 | - | local floor = math.floor |
| 13 | + | local floor = math.floor |
| 14 | - | local random = math.random |
| 14 | + | local random = math.random |
| 15 | - | |
| 15 | + | |
| 16 | - | --variables |
| 16 | + | --variables |
| 17 | - | 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} |
| 17 | + | 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}
|
| 18 | - | local color = {bg=makeColor("black"),fg=makeColor("blue"),fg2=makeColor("red"),line=makeColor("lightblue")} |
| 18 | + | local color = {bg=makeColor("black"),fg=makeColor("blue"),fg2=makeColor("red"),line=makeColor("lightblue")}
|
| 19 | - | --lines={{x1,y1,direction(-1,1),direction(0=horiz,1=vert)},{...}} |
| 19 | + | --lines={{x1,y1,direction(-1,1),direction(0=horiz,1=vert)},{...}}
|
| 20 | - | local lines={} |
| 20 | + | local lines={}
|
| 21 | - | local player={x=384/2,y=216/2,size=5,speed=2} |
| 21 | + | local player={x=384/2,y=216/2,size=5,speed=2}
|
| 22 | - | local target={x=384/4,y=216/4,size=10} |
| 22 | + | local target={x=384/2,y=216/4,size=10}
|
| 23 | - | local linewidth=20 |
| 23 | + | local linewidth=20 |
| 24 | - | local linespeed=2 |
| 24 | + | local linespeed=2 |
| 25 | - | |
| 25 | + | |
| 26 | - | --screen vars |
| 26 | + | local score=0 |
| 27 | - | local SCREEN_WIDTH = 384 |
| 27 | + | |
| 28 | - | local SCREEN_HEIGHT = 216 |
| 28 | + | --screen vars |
| 29 | - | |
| 29 | + | local SCREEN_WIDTH = 384 |
| 30 | - | --game loop |
| 30 | + | local SCREEN_HEIGHT = 216 |
| 31 | - | keyDirectPoll() |
| 31 | + | |
| 32 | - | while exit~=1 do |
| 32 | + | --game loop |
| 33 | - | if keyDirect(key.Exit)>0 then |
| 33 | + | keyDirectPoll() |
| 34 | - | exit=1 |
| 34 | + | while exit~=1 do |
| 35 | - | end |
| 35 | + | if keyDirect(key.Exit)>0 then |
| 36 | - | --clear screen |
| 36 | + | exit=1 |
| 37 | - | drawRectFill(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,color.bg) |
| 37 | + | end |
| 38 | - | --keys |
| 38 | + | --clear screen |
| 39 | - | if keyDirect(key.Left)>0 and player.x>0 then player.x=player.x-player.speed |
| 39 | + | drawRectFill(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,color.bg) |
| 40 | - | elseif keyDirect(key.Right)>0 and player.x<SCREEN_WIDTH then player.x=player.x+player.speed |
| 40 | + | --display score |
| 41 | - | end |
| 41 | + | drawText(1,1,"SCORE: " .. score,color.fg2,color.bg) |
| 42 | - | if keyDirect(key.Up)>0 and player.y>0 then player.y=player.y-player.speed |
| 42 | + | --[[debug |
| 43 | - | elseif keyDirect(key.Down)>0 and player.y<SCREEN_HEIGHT then player.y=player.y+player.speed |
| 43 | + | drawText(1,20,"DEBUG: " .. #lines,color.fg2,color.bg) |
| 44 | - | end |
| 44 | + | --]] |
| 45 | - | |
| 45 | + | |
| 46 | - | --calculations |
| 46 | + | --keys |
| 47 | - | --check collision with target |
| 47 | + | if keyDirect(key.Left)>0 and player.x>0 then player.x=player.x-player.speed |
| 48 | - | if player.x<target.x+target.size and player.x>target.x-target.size |
| 48 | + | elseif keyDirect(key.Right)>0 and player.x<SCREEN_WIDTH then player.x=player.x+player.speed |
| 49 | - | and player.y-player.size<target.y+target.size and player.y+player.size>target.y-target.size then |
| 49 | + | end |
| 50 | - | target.x=random(0,SCREEN_WIDTH) |
| 50 | + | if keyDirect(key.Up)>0 and player.y>0 then player.y=player.y-player.speed |
| 51 | - | target.y=random(0,SCREEN_HEIGHT) |
| 51 | + | elseif keyDirect(key.Down)>0 and player.y<SCREEN_HEIGHT then player.y=player.y+player.speed |
| 52 | - | |
| 52 | + | end |
| 53 | - | if player.y>SCREEN_HEIGHT/2 then |
| 53 | + | |
| 54 | - | lines[#lines+1]={random(0,SCREEN_WIDTH/2),random(0,SCREEN_HEIGHT/2-player.size),1,0} |
| 54 | + | --calculations |
| 55 | - | else |
| 55 | + | --check collision with target |
| 56 | - | lines[#lines+1]={random(0,SCREEN_WIDTH/2),random(SCREEN_HEIGHT/2+player.size,SCREEN_HEIGHT),1,0} |
| 56 | + | if player.x<target.x+target.size and player.x>target.x-target.size |
| 57 | - | end |
| 57 | + | and player.y-player.size<target.y+target.size and player.y+player.size>target.y-target.size then |
| 58 | - | |
| 58 | + | target.x=random(0,SCREEN_WIDTH) |
| 59 | - | if player.x>SCREEN_WIDTH/2 then |
| 59 | + | target.y=random(0,SCREEN_HEIGHT) |
| 60 | - | lines[#lines+2]={random(0,SCREEN_WIDTH/2-player.size),random(0,SCREEN_HEIGHT/2),1,1} |
| 60 | + | score=score+100 |
| 61 | - | else |
| 61 | + | -- create lines |
| 62 | - | lines[#lines+2]={random(SCREEN_WIDTH/2+player.size,SCREEN_WIDTH),random(0,SCREEN_HEIGHT/2),1,1} |
| 62 | + | if player.y>SCREEN_HEIGHT/2 then |
| 63 | - | end |
| 63 | + | lines[#lines+1]={random(0,SCREEN_WIDTH/2),random(0,SCREEN_HEIGHT/2-player.size),1,0}
|
| 64 | - | end |
| 64 | + | else |
| 65 | - | |
| 65 | + | lines[#lines+1]={random(0,SCREEN_WIDTH/2),random(SCREEN_HEIGHT/2+player.size,SCREEN_HEIGHT),1,0}
|
| 66 | - | --lines |
| 66 | + | end |
| 67 | - | for i=1,#lines,1 do |
| 67 | + | |
| 68 | - | --if horizontal |
| 68 | + | if player.x>SCREEN_WIDTH/2 then |
| 69 | - | if lines[i][4]==0 then |
| 69 | + | lines[#lines+2]={random(0,SCREEN_WIDTH/2-player.size),random(0,SCREEN_HEIGHT/2),1,1}
|
| 70 | - | --reverse direction if hit edge |
| 70 | + | else |
| 71 | - | if lines[i][1]>SCREEN_WIDTH-linewidth or lines[i][1]<0 then |
| 71 | + | lines[#lines+2]={random(SCREEN_WIDTH/2+player.size,SCREEN_WIDTH),random(0,SCREEN_HEIGHT/2),1,1}
|
| 72 | - | lines[i][3]=lines[i][3]*-1 |
| 72 | + | fastCopy() |
| 73 | - | end |
| 73 | + | end |
| 74 | - | --check collisions |
| 74 | + | end |
| 75 | - | if lines[i][1]+linewidth>player.x-player.size and lines[i][1]<player.x+player.size |
| 75 | + | |
| 76 | - | and lines[i][2]>player.y-player.size and lines[i][2]<player.y+player.size then |
| 76 | + | --lines |
| 77 | - | print("you lose") |
| 77 | + | for i=1,#lines,1 do |
| 78 | - | exit=1 |
| 78 | + | --if horizontal |
| 79 | - | end |
| 79 | + | if lines[i][4]==0 then |
| 80 | - | --move it along |
| 80 | + | --reverse direction if hit edge |
| 81 | - | lines[i][1]=lines[i][1]+linespeed*lines[i][3] |
| 81 | + | if lines[i][1]>SCREEN_WIDTH-linewidth or lines[i][1]<0 then |
| 82 | - | --draw it |
| 82 | + | lines[i][3]=lines[i][3]*-1 |
| 83 | - | drawLine(lines[i][1],lines[i][2],lines[i][1]+linewidth,lines[i][2],color.line) |
| 83 | + | end |
| 84 | - | end |
| 84 | + | --check collisions |
| 85 | - | |
| 85 | + | if lines[i][1]+linewidth>player.x-player.size and lines[i][1]<player.x+player.size |
| 86 | - | --if vertical |
| 86 | + | and lines[i][2]>player.y-player.size and lines[i][2]<player.y+player.size then |
| 87 | - | if lines[i][4]==1 then |
| 87 | + | print("you lose")
|
| 88 | - | --reverse direction if hit edge |
| 88 | + | exit=1 |
| 89 | - | if lines[i][2]>SCREEN_HEIGHT-linewidth or lines[i][2]<0 then |
| 89 | + | end |
| 90 | - | lines[i][3]=lines[i][3]*-1 |
| 90 | + | --move it along |
| 91 | - | end |
| 91 | + | lines[i][1]=lines[i][1]+linespeed*lines[i][3] |
| 92 | - | --check collisions |
| 92 | + | --draw it |
| 93 | - | if lines[i][2]+linewidth>player.y-player.size and lines[i][2]<player.y+player.size |
| 93 | + | drawLine(lines[i][1],lines[i][2],lines[i][1]+linewidth,lines[i][2],color.line) |
| 94 | - | and lines[i][1]>player.x-player.size and lines[i][1]<player.x+player.size then |
| 94 | + | end |
| 95 | - | print("you lose") |
| 95 | + | |
| 96 | - | exit=1 |
| 96 | + | --if vertical |
| 97 | - | end |
| 97 | + | if lines[i][4]==1 then |
| 98 | - | --move it along |
| 98 | + | --reverse direction if hit edge |
| 99 | - | lines[i][2]=lines[i][2]+linespeed*lines[i][3] |
| 99 | + | if lines[i][2]>SCREEN_HEIGHT-linewidth or lines[i][2]<0 then |
| 100 | - | --draw it |
| 100 | + | lines[i][3]=lines[i][3]*-1 |
| 101 | - | drawLine(lines[i][1],lines[i][2],lines[i][1],lines[i][2]+linewidth,color.line) |
| 101 | + | end |
| 102 | - | end |
| 102 | + | --check collisions |
| 103 | - | end |
| 103 | + | if lines[i][2]+linewidth>player.y-player.size and lines[i][2]<player.y+player.size |
| 104 | - | |
| 104 | + | and lines[i][1]>player.x-player.size and lines[i][1]<player.x+player.size then |
| 105 | - | keyDirectPoll() |
| 105 | + | print("you lose")
|
| 106 | - | |
| 106 | + | exit=1 |
| 107 | - | --display |
| 107 | + | end |
| 108 | - | drawCircle(player.x,player.y,player.size,color.fg) |
| 108 | + | --move it along |
| 109 | - | drawCircle(target.x,target.y,target.size,color.fg2) |
| 109 | + | lines[i][2]=lines[i][2]+linespeed*lines[i][3] |
| 110 | - | fastCopy() |
| 110 | + | --draw it |
| 111 | - | |
| 111 | + | drawLine(lines[i][1],lines[i][2],lines[i][1],lines[i][2]+linewidth,color.line) |
| 112 | - | keyDirectPoll() |
| 112 | + | end |
| 113 | end | |
| 114 | ||
| 115 | keyDirectPoll() | |
| 116 | ||
| 117 | --display | |
| 118 | drawCircle(player.x,player.y,player.size,color.fg) | |
| 119 | drawCircle(target.x,target.y,target.size,color.fg2) | |
| 120 | fastCopy() | |
| 121 | ||
| 122 | keyDirectPoll() | |
| 123 | end |