SHOW:
|
|
- or go back to the newest paste.
1 | - | local code = [[--LIKO 12 Pong |
1 | + | local code = [[--LIKO 12 Pong AC |
2 | - | --By Watola |
2 | + | --By Watola, with physics accumulator added by Taehl |
3 | function _init() | |
4 | --Default values | |
5 | ball_x=24 | |
6 | ball_y=24 | |
7 | ball_r=3 | |
8 | ball_c=8 | |
9 | ball_sx=1.6 | |
10 | ball_sy=1.6 | |
11 | pad_x=85 | |
12 | pad_y=120 | |
13 | pad_w=30 | |
14 | pad_h=4 | |
15 | pad_sx=0 | |
16 | pad_c=8 | |
17 | score=0 | |
18 | lives=3 | |
19 | acc=0 | |
20 | - | function _update() |
20 | + | frame=1/120 --update at 120 FPS |
21 | end | |
22 | function _update(dt) | |
23 | acc = acc+dt | |
24 | if acc < frame then return end | |
25 | acc = acc-frame | |
26 | draw() | |
27 | movepaddle() | |
28 | bouncewall() | |
29 | bouncepaddle() | |
30 | loseball() | |
31 | end | |
32 | function draw() | |
33 | --Clear the screen | |
34 | clear(14) | |
35 | --Draw the score | |
36 | color(15) print("Score:",2,2) | |
37 | color(15) print(score,26,2) | |
38 | --Draw the lives | |
39 | color(15) print("Lives:",165,2) | |
40 | color(15) print(lives,189,2) | |
41 | --Draw the paddle | |
42 | rect(pad_x,pad_y,pad_w,pad_h,pad_c) | |
43 | --Draw the ball | |
44 | color(ball_c) circle(ball_x,ball_y,ball_r) | |
45 | end | |
46 | function movepaddle() | |
47 | --Left | |
48 | if (btn(0)) then | |
49 | if pad_x > 13 then | |
50 | pad_sx = pad_sx-1 | |
51 | end | |
52 | end | |
53 | --Right | |
54 | if (btn(1)) then | |
55 | if pad_x < 150 then | |
56 | pad_sx = pad_sx+1 | |
57 | end | |
58 | end | |
59 | --Speed | |
60 | pad_sx=pad_sx/1.3 | |
61 | pad_x=pad_x+pad_sx | |
62 | end | |
63 | function bouncewall() | |
64 | --Bouncing | |
65 | ball_x=ball_x+ball_sx | |
66 | ball_y=ball_y+ball_sy | |
67 | --Wall collision | |
68 | if ball_x > 190 or ball_x <2 then | |
69 | ball_sx = -ball_sx | |
70 | end | |
71 | if ball_y <2 then | |
72 | ball_sy = -ball_sy | |
73 | end | |
74 | end | |
75 | function bouncepaddle() | |
76 | --Ball collision with paddle | |
77 | if ball_x>=pad_x-4 and | |
78 | ball_x<=pad_x+pad_w+4 and | |
79 | ball_y>pad_y-4 then | |
80 | ball_sy = -ball_sy | |
81 | --Adding score | |
82 | score=score+1 | |
83 | end | |
84 | end | |
85 | function loseball() | |
86 | if ball_y > 117 then | |
87 | lives=lives-1 | |
88 | ball_y = 24 | |
89 | end | |
90 | if lives < 1 then | |
91 | ball_sy=0 | |
92 | ball_sx=0 | |
93 | ball_y=24 | |
94 | ball_x=24 | |
95 | pad_sx=-1000 | |
96 | color(15) print("GAME OVER",80,52) | |
97 | color(15) print("PRESS DOWN TO RESTART",58,62) | |
98 | color(15) print("CREATED BY WATOLA",66,72) | |
99 | end | |
100 | if lives < 1 then | |
101 | if (btn(3)) then | |
102 | - | local spritemap = 'iVBORw0KGgoAAAANSUhEUgAAAMAAAABgAgMAAAA2rpV6AAAACVBMVEUAAAD/8enDw8a4vf5CAAAAAXRSTlMAQObYZgAAADtJREFUeJzty6ERwCAABEEmDk8L6QcBM0hKoYn0mxpes6vvSkm1Hg5zhMO3wuHd4VBPODxhDwAAAHCNHyE6AwvViDPqAAAAAElFTkSuQmCC' |
102 | + | |
103 | end | |
104 | - | local tilemap = 'iVBORw0KGgoAAAANSUhEUgAAABgAAAAJAQAAAAAAhtFrAAAAAnRSTlMAAHaTzTgAAAALSURBVHicY2AgDAAAJAABtmbfBAAAAABJRU5ErkJggg==' |
104 | + | |
105 | end]] | |
106 | ||
107 | ||
108 | local spritemap = | |
109 | 'iVBORw0KGgoAAAANSUhEUgAAAMAAAABgAgMAAAA2rpV6AAAACVBMVEUAAAD/8enDw8a4vf5CAAAAAXRSTlMAQObYZgAAADtJREFUeJzty6ERwCAABEEmDk8L6QcBM0hKoYn0mxpes6vvSkm1Hg5zhMO3wuHd4VBPODxhDwAAAHCNHyE6AwvViDPqAAAAAElFTkSuQmCC' | |
110 | ||
111 | local tilemap = | |
112 | 'iVBORw0KGgoAAAANSUhEUgAAABgAAAAJAQAAAAAAhtFrAAAAAnRSTlMAAHaTzTgAAAALSURBVHicY2AgDAAAJAABtmbfBAAAAABJRU5ErkJggg==' | |
113 | ||
114 | return {code=code,spritemap=spritemap,tilemap=tilemap} |