0 Members and 1 Guest are viewing this topic.
print("starting...")print("defining functions")--function variableslocal drawRectFill = zmg.drawRectFilllocal fastCopy = zmg.fastCopylocal makeColor = zmg.makeColorlocal drawPoint = zmg.drawPointlocal keyMenuFast = zmg.keyMenuFastlocal clear = zmg.clearlocal drawText = zmg.drawTextlocal keyDirectPoll = zmg.keyDirectPolllocal keyDirect = zmg.keyDirectlocal floor = math.floorlocal random = math.randomprint("setting vars")--screen varslocal LCD_SCREEN_WIDTH = 384local LCD_SCREEN_HEIGHT = 216--game variableslocal 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 = {makeColor("limegreen"),makeColor("black")}local ball = {x=20, y=20, width=8, height=8}local dir = {x=1, y=1}local speed = {x=2, y=2}local paddle = {player=40, width=8, height=30, speed=4}local wall = {width=8}print("entering game loop")----game loop----while keyMenuFast() ~= key.Exit do----DRAW------draw backgrounddrawRectFill(0,0,LCD_SCREEN_WIDTH,LCD_SCREEN_HEIGHT,color[2])--draw balldrawRectFill(ball.x, ball.y, ball.width, ball.height, color[1])--draw player paddledrawRectFill(0, paddle.player, paddle.width, paddle.height, color[1])--draw walldrawRectFill(LCD_SCREEN_WIDTH-wall.width, 0, wall.width, LCD_SCREEN_HEIGHT, color[1])----CONTROLS------control paddleif keyMenuFast()==key.Up and paddle.player>0 then paddle.player = paddle.player - paddle.speedelseif keyMenuFast()==key.Down and paddle.player<LCD_SCREEN_HEIGHT - paddle.height then paddle.player = paddle.player + paddle.speedend----COLLISIONS------check for collisionsif ball.x < 0 + paddle.width and ball.y > paddle.player and ball.y < paddle.player + paddle.height then ball.x = 0 + paddle.width dir.x=1elseif ball.x < 0 then print("Game Over") breakendif ball.x>LCD_SCREEN_WIDTH - ball.width - wall.width then ball.x = LCD_SCREEN_WIDTH - ball.width - wall.width dir.x=-1endif ball.y<0 then ball.y=0 dir.y=1elseif ball.y>LCD_SCREEN_HEIGHT - ball.height then ball.y = LCD_SCREEN_HEIGHT - ball.height dir.y=-1end----ETC------make new varsball.x = ball.x + (dir.x * speed.x)ball.y = ball.y + (dir.y * speed.y)--refresh screenfastCopy()--[[----debugprint("ball.y:" .. ball.y)print("ball.x:" .. ball.x)--]]--endprint("exiting.")
"welcome to the world of computers, where everything seems to be based on random number generators"