Jump to content



Photo
- - - - -

Pong++ (Luazm)

LuaZM pong pong++ game

  • Please log in to reply
1 reply to this topic

#1 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 19 September 2012 - 08:26 PM

I have started a project I am calling pong++. It is based on pong but will have lots of different modes.

So far I have this:

print("starting...")

print("defining functions")
--function variables
local drawRectFill = zmg.drawRectFill
local fastCopy = zmg.fastCopy
local makeColor = zmg.makeColor
local drawPoint = zmg.drawPoint
local keyMenuFast = zmg.keyMenuFast
local clear = zmg.clear
local drawText = zmg.drawText
local keyDirectPoll = zmg.keyDirectPoll
local keyDirect = zmg.keyDirect
local floor = math.floor
local random = math.random

print("setting vars")
--screen vars
local LCD_SCREEN_WIDTH = 384
local LCD_SCREEN_HEIGHT = 216

--game variables
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}
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 background
drawRectFill(0,0,LCD_SCREEN_WIDTH,LCD_SCREEN_HEIGHT,color[2])

--draw ball
drawRectFill(ball.x, ball.y, ball.width, ball.height, color[1])

--draw player paddle
drawRectFill(0, paddle.player, paddle.width, paddle.height, color[1])

--draw wall
drawRectFill(LCD_SCREEN_WIDTH-wall.width, 0, wall.width, LCD_SCREEN_HEIGHT, color[1])


----CONTROLS----
--control paddle
if keyMenuFast()==key.Up and paddle.player>0 then paddle.player = paddle.player - paddle.speed
elseif keyMenuFast()==key.Down and paddle.player<LCD_SCREEN_HEIGHT - paddle.height then paddle.player = paddle.player + paddle.speed
end


----COLLISIONS----
--check for collisions
if 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=1
elseif ball.x < 0 then print("Game Over") break
end

if ball.x>LCD_SCREEN_WIDTH - ball.width - wall.width then ball.x = LCD_SCREEN_WIDTH - ball.width - wall.width dir.x=-1
end

if ball.y<0 then ball.y=0 dir.y=1
elseif ball.y>LCD_SCREEN_HEIGHT - ball.height then ball.y = LCD_SCREEN_HEIGHT - ball.height dir.y=-1
end

----ETC----
--make new vars
ball.x = ball.x + (dir.x * speed.x)
ball.y = ball.y + (dir.y * speed.y)

--refresh screen
fastCopy()

--[[--
--debug
print("ball.y:" .. ball.y)
print("ball.x:" .. ball.x)
--]]--

end
print("exiting.")

As you can see I have a basic pong game set up there. It is totally playable, just paste it into notepad or whatever, save it, and send it to your calc. If you get errors, please post them.



The main reason I am posting this is because I have not come up with many ideas for different modes. The ideas I have come up with are:

* Slug: Make the paddle move very slowly. I will probably make this something that happens in-game as a penalty or whatever, not as an actual game mode.

* Spread: have two player paddles that move away from each other symmetrically from the center.

* Obstacles: Have obstacles in the middle of the screen.

* Multiple balls: self-explanatory, I think. Have more than one ball to keep track of.

Please post your ideas!


EDIT:
If you can give me tips on optimization, by all means do! :)

I think that there may be a faster way of clearing the screen than drawing the background every frame, but I am too lazy right now to figure that out. :P


#2 MicroPro

MicroPro

    Casio Overlord

  • Deputy
  • PipPipPipPipPipPipPip
  • 640 posts
  • Gender:Male
  • Location:Iran

  • Calculators:
    Casio ClassPad 300

Posted 25 September 2012 - 01:29 PM

I can't test it, but anyway games are fun. :D

If you can give me tips on optimization, by all means do! Posted Image

Yes make the game so fast-paced that becomes nearly unplayable :)

I think that there may be a faster way of clearing the screen than drawing the background every frame ... [snip] ...

Drawing a 'white' ball (i.e same as background color) in the previous position of the ball could help, but I'm not sure if any kind of drawing can be faster than another...



Also tagged with one or more of these keywords: LuaZM, pong, pong++, game

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users