-2

I took a computer science course this year (grade 10) and the final project is to make a game. For my game I want to add a hunger element where you start with 0 hunger and every minute you hunger goes up by 1 (in the game you buy food items to make your hunger go back down, but I will add that later). If your hunger reaches all the way to 10 (this would be after 11 minutes). You “die” and lose all your game progress - the program crashes (pygame.quit())

Can anyone help me with this doing this, I’m not really sure as I am extremely new to coding.

Thanks!

dremmy10
  • 21
  • 1
  • 5
  • Welcome to SO! Questions tend to get better responses if you provide examples of what you have tried, how it has failed, and specific questions about that process. – Savage Henry Jun 05 '20 at 21:27

2 Answers2

0

Have you tried generating any code for it yet? It is not really fair to ask people to give you code for your assessment without doing some real research and trying to get some code working for yourself first. Maybe update your question with anything you have attempted towards this question, to give a better explanation for what you are really needing help with? If you have not started yet, here is some guidance to get you started:

First of all you will need something that would generate a time counter for you, so you know when a minute passes. Check out: Countdown timer in Pygame for guidance on generating a timer and how to get how many seconds have passed. There is also a link in that question to the pygame timer documentation that would be very helpful.

Then, you just need to set up a "hunger" variable that gets added to every time 60 seconds have been reached. And once it hits 10, then have the game over method initiated.

  • Come on man, you don’t need to guilt me for asking for help:( in just a beginner. I’ll try looking it up. – dremmy10 Jun 05 '20 at 21:43
  • Not giving guilt at all! =) Just trying to get you to think and work for yourself a little, it will be more effective. Plus, I am a pretty much a newb too. – MakingRobots Jun 05 '20 at 21:54
0

Check out

http://www.pygame.org/docs/ref/time.html#pygame.time.get_ticks

Heres some code to get you going..

import pygame 

run_app = True
time_passed = 0
COUNTER = 60 # Set to 60 seconds / 1 minute.

pygame.init()

start_ticks=pygame.time.get_ticks()

# Begin game loop.
while run_app:

    # Convert to seconds.
    time = (pygame.time.get_ticks()) / 1000

    # True every 60 seconds / 1 minute.
    if time > (time_passed + COUNTER):
        time_passed = time
        print("Do something here regarding hunger, Increase by 1")
James
  • 247
  • 2
  • 6