Pong

On your display
Classic Pong on a 32×8 LED matrix, featuring colorful independent paddles, a bouncing ball, and fully automatic gameplay.
- Works with
- AWTRIX NG
- Topic
- Gaming
- Includes
- Script
Choose your display in the next step.
Flow description
Sit back and enjoy a colorful game of Auto Pong! Two independent paddles automatically battle it out on your display. No icons, assets, or extra downloads needed. Just install the script and let the game begin!
ecMyAqvXDdhS.ax
# @name Auto Pong
# @desc Colorful self-playing Pong for AWTRIX NG by KODIMAX
# @version 1.0
# @author KODIMAX
import math
class AutoPong
var bx,by,dx,dy,lp,rp,last,lt,rt,ly,ry
def init()
self.reset()
end
def reset()
self.bx=16
self.by=3
self.lp=1
self.rp=4
self.dx=(math.rand()%2)*2-1
self.dy=(math.rand()%2)*2-1
self.ly=math.rand()%6
self.ry=math.rand()%6
self.last=now_ms()
self.lt=now_ms()
self.rt=now_ms()
end
def next()
var t=now_ms()
# Linker Spieler
if t-self.lt>=180
self.lt=t
if self.dx<0
self.ly=self.by-1
else
if math.rand()%4==0
self.ly=math.rand()%6
end
end
if self.ly<0 self.ly=0 end
if self.ly>5 self.ly=5 end
if self.lp<self.ly
self.lp+=1
elif self.lp>self.ly
self.lp-=1
end
end
# Rechter Spieler
if t-self.rt>=260
self.rt=t
if self.dx>0
self.ry=self.by-1
else
if math.rand()%3==0
self.ry=math.rand()%6
end
end
if self.ry<0 self.ry=0 end
if self.ry>5 self.ry=5 end
if self.rp<self.ry
self.rp+=1
elif self.rp>self.ry
self.rp-=1
end
end
# Ball bewegen
self.bx+=self.dx
self.by+=self.dy
# Oben / unten abprallen
if self.by<=0
self.by=0
self.dy=1
elif self.by>=7
self.by=7
self.dy=-1
end
# Linker Schlaeger
if self.dx<0 && self.bx==2
if self.by>=self.lp && self.by<=self.lp+2
self.dx=1
if self.by==self.lp
self.dy=-1
elif self.by==self.lp+2
self.dy=1
end
end
end
# Rechter Schlaeger
if self.dx>0 && self.bx==29
if self.by>=self.rp && self.by<=self.rp+2
self.dx=-1
if self.by==self.rp
self.dy=-1
elif self.by==self.rp+2
self.dy=1
end
end
end
# Punkt
if self.bx<0 || self.bx>31
self.bx=16
self.by=3
self.lp=math.rand()%6
self.rp=math.rand()%6
self.dx=-self.dx
self.dy=(math.rand()%2)*2-1
end
end
def draw()
var t=now_ms()
if t-self.last>=90
self.last=t
self.next()
end
clear(0)
# Mittellinie - dunkelgrau
for y:0..7
if y%2==0
pixel(15,y,0x303030)
end
end
# Linker Spieler - Cyan
pixel(1,self.lp,0x00C8FF)
pixel(1,self.lp+1,0x00C8FF)
pixel(1,self.lp+2,0x00C8FF)
# Rechter Spieler - Pink
pixel(30,self.rp,0xFF3C8E)
pixel(30,self.rp+1,0xFF3C8E)
pixel(30,self.rp+2,0xFF3C8E)
# Ball - Weiss
pixel(self.bx,self.by,0xFFFFFF)
end
def duration()
return 30000
end
end
return AutoPong()
Discussion 0
Ask a question, suggest a change or share how you use it.
No comments yet. Start the conversation.
More flows for AWTRIX NG Scripts or Gaming
Something wrong with this flow? Report it.
Have an idea?
Sign in to ask questions and join the conversation.