Pong Clock

On your display
Self-playing Pong with a clock in the background. The right paddle misses when the minute changes, the left misses when the hour changes.
- Works with
- AWTRIX NG
- Topic
- Gaming
- Includes
- Script
Choose your display in the next step.
Flow description
Pong that tells the time! A fork of "Pong" by KODIMAX (https://awtrix.de/flow/ecMyAqvXDdhS) with a clock running behind the game.
What's new:
- Background clock (HH:MM) using the native AWTRIX font
- Right player loses when the minute changes, left player loses when the hour changes
- Paddles play independently: the receiving paddle predicts where the ball lands, the other one drifts to its own rest spot
- Ball speeds up with every paddle hit and resets after each point
- Clock colour configurable in the flow settings (default #808080)
No icons or extra downloads needed. Just install and enjoy.
Big thanks to KODIMAX for the original Auto Pong script. The game idea, colours and paddle design are his, and this fork wouldn't exist without it. Please check out and support the original flow!
ljWEjhYm9KcW.ax
# @name Auto Pong Clock
# @version 1.6
# @desc Self-playing Pong with background clock. Right misses on new minute, left misses on new hour. Ball speeds up each hit.
# @author KODIMAX (clock mod: TSA3000)
# @config clk_col color "Clock colour" default=#808080
import math
class AutoPong
var bx,by,dx,dy,lp,rp,last,tick,spd
var lo,ro,li,ri
var clk_col,time_str,last_min,last_hr,clk_x,miss
static SPD_START=90 # ms per step at serve
static SPD_STEP=6 # ms faster per paddle hit
static SPD_MIN=35 # fastest allowed
def init()
self.clk_col=store.get("clk_col")
if self.clk_col==nil || self.clk_col==0 || type(self.clk_col)!='int'
self.clk_col=0x808080
end
self.time_str="--:--"
self.last_min=-1
self.last_hr=-1
self.miss=nil
self.clk_x=(32-text_ink_width(self.time_str))/2
self.lp=2
self.rp=2
self.tick=0
self.reset()
end
def reset()
self.bx=16
self.by=3
self.dx=(math.rand()%2)*2-1
self.dy=(math.rand()%2)*2-1
self.lo=math.rand()%3
self.ro=math.rand()%3
self.li=math.rand()%6
self.ri=math.rand()%6
self.spd=self.SPD_START
self.last=now_ms()
end
# ---------- Clock ----------
def pad(n)
return n<10 ? "0"+str(n) : str(n)
end
def loop()
var m=minute()
if m==self.last_min return end
var h=hour()
if h>=0 && self.last_min>=0
if h!=self.last_hr
self.miss='L' # new hour -> left loses
elif self.miss!='L'
self.miss='R' # new minute -> right loses
end
end
self.last_min=m
self.last_hr=h
if h<0
self.time_str="--:--"
else
self.time_str=self.pad(h)+":"+self.pad(m)
end
self.clk_x=(32-text_ink_width(self.time_str))/2
end
# ---------- Helpers ----------
def clamp(v)
if v<0 return 0 end
if v>5 return 5 end
return v
end
def track(p,target)
target=self.clamp(target)
if p<target return p+1 end
if p>target return p-1 end
return p
end
def predict(col)
var x=self.bx
var y=self.by
var vy=self.dy
if (col-x)*self.dx<0 return y end
while x!=col
x+=self.dx
y+=vy
if y<=0
y=0
vy=1
elif y>=7
y=7
vy=-1
end
end
return y
end
def defl(o)
if o==0 return -1 end
if o==2 return 1 end
return (math.rand()%2)*2-1
end
def speed_up()
self.spd-=self.SPD_STEP
if self.spd<self.SPD_MIN self.spd=self.SPD_MIN end
end
def move_paddles()
# Left paddle
if self.dx<0
if self.tick%2==0
var py=self.predict(2)
var t=(self.miss=='L') ? (py<4 ? 5 : 0) : py-self.lo
self.lp=self.track(self.lp,t)
end
elif self.tick%4==0
if self.lp==self.li && math.rand()%3==0 self.li=math.rand()%6 end
self.lp=self.track(self.lp,self.li)
end
# Right paddle
if self.dx>0
if self.tick%2==0
var py=self.predict(29)
var t=(self.miss=='R') ? (py<4 ? 5 : 0) : py-self.ro
self.rp=self.track(self.rp,t)
end
elif self.tick%4==2
if self.rp==self.ri && math.rand()%3==0 self.ri=math.rand()%6 end
self.rp=self.track(self.rp,self.ri)
end
end
# ---------- Game ----------
def next()
self.tick+=1
self.move_paddles()
# Move ball
self.bx+=self.dx
self.by+=self.dy
# Bounce top/bottom
if self.by<=0
self.by=0
self.dy=1
elif self.by>=7
self.by=7
self.dy=-1
end
# Left paddle hit
if self.dx<0 && self.bx==2 && self.miss!='L'
if self.by<self.lp || self.by>self.lp+2
self.lp=self.clamp(self.by-1)
end
self.dx=1
self.dy=self.defl(self.by-self.lp)
self.ro=math.rand()%3
self.speed_up()
end
# Right paddle hit
if self.dx>0 && self.bx==29 && self.miss!='R'
if self.by<self.rp || self.by>self.rp+2
self.rp=self.clamp(self.by-1)
end
self.dx=-1
self.dy=self.defl(self.by-self.rp)
self.lo=math.rand()%3
self.speed_up()
end
# Point scored
if self.bx<0 || self.bx>31
self.miss=nil
self.reset()
end
end
def draw()
var t=now_ms()
if t-self.last>=self.spd
self.last=t
self.next()
end
clear()
# Background clock
text(self.clk_x,6,self.time_str,self.clk_col)
# Left player - cyan
pixel(1,self.lp,0x00C8FF)
pixel(1,self.lp+1,0x00C8FF)
pixel(1,self.lp+2,0x00C8FF)
# Right player - pink
pixel(30,self.rp,0xFF3C8E)
pixel(30,self.rp+1,0xFF3C8E)
pixel(30,self.rp+2,0xFF3C8E)
# Ball - white
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.