I am almost done with this, it only needs a menu... and it needs a bug fixed. One bug, and its pesky.

It should display a line going up and down, and one going horizontal each time you hit the target. but instead, on the first time you hit the target, it only displays one line. i know the vertical one exists, though, because i have collided with it during gameplay, in which case it only shows up for a split second before quitting the program.

Code:

Code:

print("starting aspirin...")
--function variables
local drawRectFill = zmg.drawRectFill
local drawCircle = zmg.drawCircle
local fastCopy = zmg.fastCopy
local makeColor = zmg.makeColor
local drawPoint = zmg.drawPoint
local drawLine = zmg.drawLine
local clear = zmg.clear
local drawText = zmg.drawText
local keyDirectPoll = zmg.keyDirectPoll
local keyDirect = zmg.keyDirect
local floor = math.floor
local random = math.random

--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 = {bg=makeColor("black"),fg=makeColor("blue"),fg2=makeColor("red"),line=makeColor("lightblue")}
--lines={{x1,y1,direction(-1,1),direction(0=horiz,1=vert)},{...}}
local lines={}
local player={x=384/2,y=216/2,size=5,speed=2}
local target={x=384/2,y=216/4,size=10}
local linewidth=20
local linespeed=2

local score=0

--screen vars
local SCREEN_WIDTH = 384
local SCREEN_HEIGHT = 216

--game loop
keyDirectPoll()
while exit~=1 do
   if keyDirect(key.Exit)>0 then
      exit=1
   end
   --clear screen
   drawRectFill(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,color.bg)
   --display score
   drawText(1,1,"SCORE: " .. score,color.fg2,color.bg)
   --[[debug
   drawText(1,20,"DEBUG: " .. #lines,color.fg2,color.bg)
   --]]
   
   --keys
   if keyDirect(key.Left)>0 and player.x>0 then player.x=player.x-player.speed
      elseif keyDirect(key.Right)>0 and player.x<SCREEN_WIDTH then player.x=player.x+player.speed
   end
   if keyDirect(key.Up)>0 and player.y>0 then player.y=player.y-player.speed
      elseif keyDirect(key.Down)>0 and player.y<SCREEN_HEIGHT then player.y=player.y+player.speed
   end
   
   --calculations
   --check collision with target
   if player.x<target.x+target.size and player.x>target.x-target.size
      and player.y-player.size<target.y+target.size and player.y+player.size>target.y-target.size then
      target.x=random(0,SCREEN_WIDTH)
      target.y=random(0,SCREEN_HEIGHT)
      score=score+100
      -- create lines
      if player.y>SCREEN_HEIGHT/2 then
         lines[#lines+1]={random(0,SCREEN_WIDTH/2),random(0,SCREEN_HEIGHT/2-player.size),1,0}
         else
         lines[#lines+1]={random(0,SCREEN_WIDTH/2),random(SCREEN_HEIGHT/2+player.size,SCREEN_HEIGHT),1,0}
      end
      
      if player.x>SCREEN_WIDTH/2 then
         lines[#lines+2]={random(0,SCREEN_WIDTH/2-player.size),random(0,SCREEN_HEIGHT/2),1,1}
         else
         lines[#lines+2]={random(SCREEN_WIDTH/2+player.size,SCREEN_WIDTH),random(0,SCREEN_HEIGHT/2),1,1}
         fastCopy()
      end
   end
   
   --lines
   for i=1,#lines,1 do
      --if horizontal
      if lines[i][4]==0 then
         --reverse direction if hit edge
         if lines[i][1]>SCREEN_WIDTH-linewidth or lines[i][1]<0 then
            lines[i][3]=lines[i][3]*-1
         end
         --check collisions
         if lines[i][1]+linewidth>player.x-player.size and lines[i][1]<player.x+player.size
            and lines[i][2]>player.y-player.size and lines[i][2]<player.y+player.size then
            print("you lose")
            exit=1
         end
         --move it along
         lines[i][1]=lines[i][1]+linespeed*lines[i][3]
         --draw it
         drawLine(lines[i][1],lines[i][2],lines[i][1]+linewidth,lines[i][2],color.line)
      end
      
      --if vertical
      if lines[i][4]==1 then
         --reverse direction if hit edge
         if lines[i][2]>SCREEN_HEIGHT-linewidth or lines[i][2]<0 then
            lines[i][3]=lines[i][3]*-1
         end
         --check collisions
         if lines[i][2]+linewidth>player.y-player.size and lines[i][2]<player.y+player.size
            and lines[i][1]>player.x-player.size and lines[i][1]<player.x+player.size then
            print("you lose")
            exit=1
         end
         --move it along
         lines[i][2]=lines[i][2]+linespeed*lines[i][3]
         --draw it
         drawLine(lines[i][1],lines[i][2],lines[i][1],lines[i][2]+linewidth,color.line)
      end
   end
   
   keyDirectPoll()
   
   --display
   drawCircle(player.x,player.y,player.size,color.fg)
   drawCircle(target.x,target.y,target.size,color.fg2)
   fastCopy()
   
   keyDirectPoll()
end

http://pastebin.com/MtPfiagb

EDIT:
seems like it always happens at 600 points, which makes me think it has to do with the pseudorandom number generator.

EDIT2:
fixed it by changing

Code:

lines[#lines+2]={random(SCREEN_WIDTH/2+player.size,SCREEN_WIDTH),random(0,SCREEN_HEIGHT/2),1,1}

to

Code:

lines[#lines+1]={random(SCREEN_WIDTH/2+player.size,SCREEN_WIDTH),random(0,SCREEN_HEIGHT/2),1,1}


EDIT:

Ok, its released Smile

http://dl.dropbox.com/u/63621708/calcs/progs/luaZM/aspirin.zip

(its in the queue, but it hasnt been accepted yet) Wink
New version, same link.

Changelog:

  • changed "You Died" to "Game Over"
  • added a status bar at the top so that the game is no longer overlaid on the score display.
  • added a session high score



Download

EDIT:

Can't figure out how to update a file, and I dont want to have to entries in the archives, so please help me admins.
flyingfisch wrote:
EDIT:

Can't figure out how to update a file, and I dont want to have to entries in the archives, so please help me admins.


Go to your file and scroll to the bottom where it says Author Options. It should say Upload New Version.

I like this game. It's fun. Smile My highest score so far is 1000. Razz
Spenceboy98 wrote:
flyingfisch wrote:
EDIT:

Can't figure out how to update a file, and I dont want to have to entries in the archives, so please help me admins.


Go to your file and scroll to the bottom where it says Author Options. It should say Upload New Version.

I like this game. It's fun. Smile My highest score so far is 1000. Razz


On this page? http://www.cemetech.net/programs/index.php?mode=folder&path=/prizm/games/lua/

Also, if anyone has a prizm and a camera, could they take screenshots for me?

And I'm glad you like it! Smile
flyingfisch wrote:


No, here:
http://www.cemetech.net/programs/index.php?mode=file&id=858

flyingfisch wrote:

Also, if anyone has a prizm and a camera, could they take screenshots for me?


If I had a decent camera, I would, but I don't. Razz Maybe someone else.
Spenceboy98 wrote:

If I had a decent camera, I would, but I don't. Razz Maybe someone else.


OK, that's fine, I understand. Smile

Of course, I wouldn't have to be pleading for people to take pictures if KermM would just give us that beta he's hiding. *Hint, hint* Very Happy

EDIT:
I just did a few bug fixes in the last few minutes, so redownload the game if you have weird stuff happening. Wink
Major Update:

Changelog:
  • Added a welcome screen
  • Added 5 custom color schemes
  • Fixed a lot of bugs






Download (same link)

EDIT:
Surprise! Screenshots!

I discovered a workaround.

MLP1:


My personal fav:



Note: colors look better on calc.
Please re-encode these screenshots as PNG instead of BMP. Bitmaps are a really terrible format to use for pretty much anything.
done Smile
flyingfisch wrote:
done Smile
Looks great! I guess with your next Aspirin update in the Archives, you should add those screenshots. Smile
KermMartian wrote:
flyingfisch wrote:
done Smile
Looks great! I guess with your next Aspirin update in the Archives, you should add those screenshots. Smile


Oh, right thanks for reminding me Smile
I do not like that exit during the gameplay axtually exits. It is too close to arrow keys and i hit it accidentally a few times. Besides, it is not like it is so difficult to end the game that you need special key for it.
nsg wrote:
I do not like that exit during the gameplay axtually exits. It is too close to arrow keys and i hit it accidentally a few times. Besides, it is not like it is so difficult to end the game that you need special key for it.


should i have a confirmation message, or should i not have it at all?
Not having it makes a program shorter, so my vote is for not having it.
OK, done, same link. Smile

Download
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement