Jump to content




Fish "Game Simulator" 1.7! Now with more COLORS! :D

computer game

25 replies to this topic

#1 thewmatt

  • Members
  • 26 posts

Posted 28 August 2014 - 03:47 AM

Hello CC Fans!
This simulator is about fish roaming around in the water.
This program is open sourced so you can do whatever you please with it as long as you give me some sort of credit.
Controls: press K to kill the fish (Alternative to using CTRL + T)press F to add life to the fish. (feeding it), press R to reset the positions & orientations of the fish
Press space to make the fish move (takes .5 of your fish's life) now automated, thanks to flaghacker and KingofGamesYami for help with that.
  • Features:
  • Startup Screen
  • 3 fish (can be any color in the game with the exception of white and black)
  • Seaweed Background
  • 1 2 Ways to kill the fish (starvation, using the kill button or overfeeding)
  • 2 Controls now only one, as the fish now moves on its own.
  • 1 Health monitor
  • Infinite food
  • restart screen (uses latest version on pastebin)
Known Bugs:
  • there are currently no known bugs
Pastebin: http://pastebin.com/5x9Uu1pr OR:

pastebin get 5x9Uu1pr FishSimulator


Have a fun time with this! ;)
PS: I shortened the amount of lines from 629 to 461

Edited by thewmatt, 12 December 2014 - 02:24 AM.


#2 Saldor010

  • Members
  • 467 posts
  • LocationThe United States

Posted 28 August 2014 - 12:29 PM

Pretty neat! I can't wait for more to be added to this :)

#3 Agoldfish

  • Members
  • 451 posts
  • LocationSome Fish Bowl in Ohio.

Posted 28 August 2014 - 06:26 PM

Do I make a cameo appearance?

#4 thewmatt

  • Members
  • 26 posts

Posted 28 August 2014 - 09:25 PM

View PostJiloacom, on 28 August 2014 - 12:29 PM, said:

Pretty neat! I can't wait for more to be added to this :)
What should I add to this?

Edited by thewmatt, 28 August 2014 - 09:25 PM.


#5 Saldor010

  • Members
  • 467 posts
  • LocationThe United States

Posted 28 August 2014 - 09:56 PM

View Postthewmatt, on 28 August 2014 - 09:25 PM, said:

View PostJiloacom, on 28 August 2014 - 12:29 PM, said:

Pretty neat! I can't wait for more to be added to this :)
What should I add to this?

Hm.. Well, now that I think about it, I can't think of any suggestions for this..

#6 thewmatt

  • Members
  • 26 posts

Posted 28 August 2014 - 10:27 PM

View PostJiloacom, on 28 August 2014 - 09:56 PM, said:

View Postthewmatt, on 28 August 2014 - 09:25 PM, said:

View PostJiloacom, on 28 August 2014 - 12:29 PM, said:

Pretty neat! I can't wait for more to be added to this :)
What should I add to this?

Hm.. Well, now that I think about it, I can't think of any suggestions for this..
I could use help on making parallel work with this so you wouldnt need the space bar to update everything
;) when i tried the feeding wouldnt work

Edited by thewmatt, 28 August 2014 - 10:31 PM.


#7 flaghacker

  • Members
  • 655 posts

Posted 29 August 2014 - 09:47 AM

View Postthewmatt, on 28 August 2014 - 10:27 PM, said:

I could use help on making parallel work with this so you wouldnt need the space bar to update everything
;)/> when i tried the feeding wouldnt work
Pseudo code (I'm on mobile):
start timer
while true do
  os.pullEvent
  if timer
    move
    start new timer
  if feed key
    feed
  end
end
No need to use the parallel API.

#8 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 29 August 2014 - 12:27 PM

View Postflaghacker, on 29 August 2014 - 09:47 AM, said:

View Postthewmatt, on 28 August 2014 - 10:27 PM, said:

I could use help on making parallel work with this so you wouldnt need the space bar to update everything
;)/> when i tried the feeding wouldnt work
Pseudo code (I'm on mobile):
start timer
while true do
  os.pullEvent
  if timer
	move
	start new timer
  if feed key
	feed
  end
end
No need to use the parallel API.
Let me clean up that code...
local id = os.startTimer()
while true do
  local event = {os.pullEvent()}
  if event[ 1 ] == "timer" and event[ 2 ] == id then
    --#move
    id = os.startTimer()
  elseif event[ 1 ] == "key" and event[ 2 ] == "feed" then
    --#feed
  end
end


#9 flaghacker

  • Members
  • 655 posts

Posted 29 August 2014 - 12:48 PM

View PostKingofGamesYami, on 29 August 2014 - 12:27 PM, said:

View Postflaghacker, on 29 August 2014 - 09:47 AM, said:

Let me clean up that code...
local id = os.startTimer()
while true do
  local event = {os.pullEvent()}
  if event[ 1 ] == "timer" and event[ 2 ] == id then
    --#move
    id = os.startTimer()
  elseif event[ 1 ] == "key" and event[ 2 ] == "feed" then
    --#feed
  end
end

Thanks, typing symbols is a pain on my phone. Scrolling even more...

#10 thewmatt

  • Members
  • 26 posts

Posted 29 August 2014 - 11:58 PM

View Postflaghacker, on 29 August 2014 - 12:48 PM, said:

View PostKingofGamesYami, on 29 August 2014 - 12:27 PM, said:

View Postflaghacker, on 29 August 2014 - 09:47 AM, said:

Let me clean up that code...
local id = os.startTimer()
while true do
  local event = {os.pullEvent()}
  if event[ 1 ] == "timer" and event[ 2 ] == id then
	--#move
	id = os.startTimer()
  elseif event[ 1 ] == "key" and event[ 2 ] == "feed" then
	--#feed
  end
end

Thanks, typing symbols is a pain on my phone. Scrolling even more...
thanks guys! ill implement this in the program ASAP

#11 thewmatt

  • Members
  • 26 posts

Posted 30 August 2014 - 12:17 AM

View Postthewmatt, on 29 August 2014 - 11:58 PM, said:

View Postflaghacker, on 29 August 2014 - 12:48 PM, said:

View PostKingofGamesYami, on 29 August 2014 - 12:27 PM, said:

View Postflaghacker, on 29 August 2014 - 09:47 AM, said:

Let me clean up that code...
local id = os.startTimer()
while true do
  local event = {os.pullEvent()}
  if event[ 1 ] == "timer" and event[ 2 ] == id then
	--#move
	id = os.startTimer()
  elseif event[ 1 ] == "key" and event[ 2 ] == "feed" then
	--#feed
  end
end

Thanks, typing symbols is a pain on my phone. Scrolling even more...
thanks guys! ill implement this in the program ASAP
Dang it! the feeding Still wont work...
--Variables
local fishX = 10
local fishY = 10
local fishHealth = 20
local space = 57
local feed = 33
local h = colors.green
local fishLook = true -- true means left false means right
--Functions
function fishFeed()
    if key == feed then
    term.setCursorPos(5,5)
    term.setBackgroundColor(colors.lightBlue)
    print("Feeding Your Fish!")
    sleep(.50)
    fishHealth = fishHealth+1
if fishY > 18 then
fishY = 2
elseif fishY < 2 then
fishY = 18
end
end
--Health ColorChangers
if fishHealth < 5 then
h = colors.red
elseif fishHealth < 10 then
h = colors.orange
    elseif fishHealth > 15 then
h = colors.green
elseif fishHealth > 9 then
h = 1
elseif fishHealth < 5 then
h = colors.red
end
if fishHealth > 20 then
init()
term.setCursorPos(5,5)
term.setBackgroundColor(colors.lightBlue)
    print("Your Fish Was Overfed!")
    sleep(1)
    term.setBackgroundColor(colors.black)
    term.clear()
    error()
    end
    if fishHealth < .5 then
init()
    term.setCursorPos(5,5)
    term.setBackgroundColor(colors.lightBlue)
    print("Your Fish Starved To Death!")
    sleep(1)
    term.setBackgroundColor(colors.black)
    term.clear()
    error()
    end
end
function fishMove()
  term.setBackgroundColor(colors.lightBlue)
  term.clear()
  term.setCursorPos(1,1)
  term.setTextColor(1)
  term.write("Fish's Life: ")
  term.setTextColor(h)
  term.write(fishHealth)
  term.setCursorPos(fishX,fishY)
  term.setTextColor(colors.black)
  term.setBackgroundColor(colors.orange)
  if fishLook then
    print("(O<")
    else if fishLook == false then
	  print(">O)")
    end
  end
    move = math.random(4)
    fishHealth = fishHealth - .5
    if move == 1 then
	  fishX = fishX-1
	  fishLook = true
	  elseif move == 2 then
	  fishX = fishX+1
	  fishLook = false
	  elseif move == 3 then
	  fishY = fishY-1
	  elseif move == 4 then
	  fishY = fishY+1
  
   end
  end
local id = os.startTimer(1)
while true do
  local event = {os.pullEvent()}
  if event[ 1 ] == "timer" and event[ 2 ] == id then
    fishMove()
    id = os.startTimer(1)
  elseif event[ 1 ] == "key" and event[ 2 ] == feed then
   
  end
end


#12 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 30 August 2014 - 12:52 AM

while true do
  local event = {os.pullEvent()}
  if event[ 1 ] == "timer" and event[ 2 ] == id then
    fishMove()
    id = os.startTimer(1)
  elseif event[ 1 ] == "key" and event[ 2 ] == feed then
    --#nothing, absolutely nothing is shown happening here...
  end
end


#13 thewmatt

  • Members
  • 26 posts

Posted 30 August 2014 - 05:07 PM

View PostKingofGamesYami, on 30 August 2014 - 12:52 AM, said:

while true do
  local event = {os.pullEvent()}
  if event[ 1 ] == "timer" and event[ 2 ] == id then
	fishMove()
	id = os.startTimer(1)
  elseif event[ 1 ] == "key" and event[ 2 ] == feed then
	--#nothing, absolutely nothing is shown happening here...
  end
end
thanks for that... the program now automatically moves the fish without making it so you cant feed it. thanks guys!!!

#14 thewmatt

  • Members
  • 26 posts

Posted 02 September 2014 - 02:26 AM

Ideas anyone? :P
EDIT: I have an idea in mind.

Edited by thewmatt, 02 September 2014 - 02:27 AM.


#15 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 05 September 2014 - 04:01 AM

You shouldn't be using sleep() when you're capturing os.timer events. If you feed your fish at the wrong time the sleep event captures and I think ignores the os.timer that fires, meaning the fish will be stationary and cannot be overfed.

I reckon you should add some more fish and maybe some seaweed. Feels a bit like a virtual aquarium which could be a nice thing to leave running on a monitor on a server for people to occasionally feed.

#16 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 05 September 2014 - 02:22 PM

As nitro said, you shouldn't use sleep as it ignores timers.
That's because the sleep function is basically something like this
Spoiler

And I have a suggestion, since you posted a pastebin link you might as well remove the code in the post or put it in a spoiler.
Could you also post some screenshots? It would be nice to see how it looks without having to download it first.

#17 thewmatt

  • Members
  • 26 posts

Posted 11 September 2014 - 04:04 AM

View PostTheOddByte, on 05 September 2014 - 02:22 PM, said:

As nitro said, you shouldn't use sleep as it ignores timers.
That's because the sleep function is basically something like this
Spoiler

And I have a suggestion, since you posted a pastebin link you might as well remove the code in the post or put it in a spoiler.
Could you also post some screenshots? It would be nice to see how it looks without having to download it first.
good idea... but i dont really have a way to substitute sleep...

Edited by thewmatt, 11 September 2014 - 04:05 AM.


#18 nitrogenfingers

    Lua Professor

  • Members
  • 551 posts
  • LocationAustralia

Posted 11 September 2014 - 09:02 AM

I agree in your code it's quite hard- in future you should isolate drawing and updates in your program to make event handling like this easier.
This would be a very quick and dirty fix:

print("Feeding Your Fish!")
fishHealth = fishHealth+1.5
sleep(.50)
id = os.startTimer(1)

But I'd recommend isolating the draw and updates. That way you can fire separate timer events (wherever you would use a sleep call) and handle each one individually.

#19 cdel

  • Banned
  • 496 posts
  • LocationMelbourne, Australia

Posted 14 September 2014 - 09:46 AM

really awesome, however its a bit annoying when the fish swims over the life meter, after a minute of feeding and whatnot the fish and life meter completely froze.

#20 thewmatt

  • Members
  • 26 posts

Posted 16 September 2014 - 04:35 AM

View Postnitrogenfingers, on 11 September 2014 - 09:02 AM, said:

I agree in your code it's quite hard- in future you should isolate drawing and updates in your program to make event handling like this easier.
This would be a very quick and dirty fix:

print("Feeding Your Fish!")
fishHealth = fishHealth+1.5
sleep(.50)
id = os.startTimer(1)

But I'd recommend isolating the draw and updates. That way you can fire separate timer events (wherever you would use a sleep call) and handle each one individually.
How do you recommend i do that?
also i might make it so the food lasts longer and the food cap is doubled lol

Edited by thewmatt, 16 September 2014 - 04:35 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users