Post new topic    
Page «  1, 2, 3
Metal King Slime
Send private message
 
 PostThu Nov 08, 2012 1:21 pm
Send private message Reply with quote
I'm just going to clean this loop up to make it clearer. Ths the HUD sprite was changing every 300 * 100 ticks. There are about 18 ticks in a second. I replaced the wait(100) with wait(1). Now it changes every 300 ticks. Change both instances of 300 in the script below to tweak the hunger rate. You will also want to change the 50 to something like 5, depending on how many frames you draw.


Code:
include, plotscr.hsd
include, project1.hsi

# global variables with ID 1. IDs don't matter much, just make sure each variable has a different ID number
global variable (1, hunger)

plotscript,HudLoop,begin

  variable (hud, time)

  hunger:=0
  hud:=load medium enemy sprite (0)
  put sprite (hud, 0,0)

  #exit loop if you die of hunger
  while (hunger << 50) do, begin  # change this

    decrement(time)
    if (time == 0) then (
      increment(hunger)
      time := 300  # change this
    )
    replace medium enemy sprite(hud, hunger)

    wait(1)
  end

  gameover
end


Note that you can write "x -= 1" instead of "decrement(x)".

I made 'hunger' into a global variable. This allows you to change it from another script, like this one, which you can attach to a textbox (with a "Run script X Always"). Then attach the textbox to an item as the On Use action.

Code:
plotscript, decrease hunger by 2, begin
  hunger -= 2
  # don't allow negative hunger, it would break the script above
  if (hunger << 0) then (hunger := 0)
end
Slime
Send private message
 
 PostThu Nov 08, 2012 1:28 pm
Send private message Reply with quote
WOW. Thanks TMC

This is the code im currently using


Code:
include, plotscr.hsd
include, project1.hsi
include, scancode.hsi
 
plotscript,WelcomeBox,begin
   suspend player
   show text box (1)
   wait for text box
   resume player
end

plotscript,HudLoop,begin
   
   variable (hud,diedOfHunger,hunger,time)
   
   # init variables
   time := 300
   diedOfHunger := false
   hunger := 0
   
   # load our HUD sprite and place it on the screen
   hud:=load medium enemy sprite (0)   
   put sprite (hud, 0,0)
   
   # check if we're a new game
   if(check tag(tag:SeenIntro) == false) then (
      WelcomeBox()
      set tag(tag:SeenIntro,true)
   )   
   #--loop begin--   
   while (diedOfHunger == false) do (
   
      if (time==0) then (
         # timer expired, our hunger goes up
         increment (hunger)
         
         # replace the sprite since hunger level has changed         
         replace medium enemy sprite(hud, hunger)
         
         #reset hunger countdown timer
         time := 300
      )
   
      wait (10)
      decrement(time)
      
      if(hunger >= 50) then (
         diedOfHunger := true
      )
      
   if(check tag(tag:HUDOn) == true) then (
      # show hud stuff -
      setspritevisible (1, on)
   )
   else (
      # hide hud stuff -
      setspritevisible (1, off)
   )
   
   # if the key was just pressed (but not triggered by being held down)
   if(keyval(key:Tab) == 3) then (
      # toggle our HUD visibility
      set tag(tag:HUDOn, not(check tag(tag:HUDOn)))
   )
   )
   #--loop end--

   # free up the sprite we used for the HUD
   free sprite (hud)
   
   # game over! the player died
   game over
end


The WelcomeBox script is just a Text Box basicly saying that the project is still underway.

HUDloop is well the loop for the hud.

You will also see somehting in there about pressing Tab.
Im trying to make it at the moment that you can press and hold TAB and the HUD will show, let go of Tab it will go away.

It kinda works but if i keep Tab held down the hud just flashes. >.>

That is a lot cleaner, i might just put that as my code and add all the extra bits in.

but not before i say thank you to Minnek and Spoonweaver for doing the code i have now.

Thanks guys. Smile

Edit:

The wait time i have at the moment is pretty good.
It works well and is more realistic i guess.

Minnek worked it out to be roughly 2 hours before you died of Starvation
I thought that was fair enough considering in a zombie-pocolypes you wouldn't last longer then 2 weeks without food.

All the running and fighting and vomiting(If you have a weak stomach) you would be doing. 2 weeks would be stretching it.

Anyways. Thanks TMC

EDIT 2:

Well TMC you fixed that problem and you didn't even know it was there

By changing where the wait(1) command was. Thats all.

Thank you again.

EDIT 3:
Now the Welcomebox script isn't running and im unsure as to why.


EDIT 4:
This is getting a bit beyond stupid but.
I fixed that as well.
Im always on the IRC channel.
#Slimesalad

Come talk.

WARNING: Noob.
Metal King Slime
Send private message
 
 PostFri Nov 09, 2012 11:25 am
Send private message Reply with quote
Quote:
It kinda works but if i keep Tab held down the hud just flashes. >.>


Yes we need a keypress command that isn't affected by keyrepeat. Whenever-I-get-around-to-it.

Also, technically it's better to replace "keyval(key:Tab) == 3" with "keyval(key:Tab) >> 1". Using the former can cause you to miss very short keypresses.

I already pointed out in IRC that "setspritevisible (1, on)" should be "setspritevisible (hud, on)"
Display posts from previous:
Page «  1, 2, 3