Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Best way to program PacMan  (Read 2822 times)

0 Members and 1 Guest are viewing this topic.

joaosausen

  • Newbie
  • *
  • Posts: 10
    • View Profile
Best way to program PacMan
« on: May 11, 2012, 11:28:08 pm »
So, i created pacman in a way where I print a map that i read from a txt file, I'm using tiles to build the map, then I do a CopyScreen to render all the map in only one image. My problem is what I do about the food, there is a way to modify a image without printing? If I can do that, i will just print a floor tile over the food tile.

Or there is a better way to handle this?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Best way to program PacMan
« Reply #1 on: May 12, 2012, 02:46:18 am »
First, don't use copy screen. It is a very expensive operation. As for drawing your map, draw whatever doesn't change like the map walls and background to a RenderTexture. Then draw the RenderTexture every frame.

As for food, simple loop through an array of food where it is spawned and redraw a sprite for every location every frame.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

joaosausen

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Best way to program PacMan
« Reply #2 on: May 12, 2012, 04:08:19 am »
RenderTexture, hmm
I will take a look at this, this is what Im doing in some way..

Anyway, im trying to not use loops inside the main while to print images, anyway, thanks for the help

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Best way to program PacMan
« Reply #3 on: May 12, 2012, 11:20:52 am »
Anyway, im trying to not use loops inside the main while to print images, anyway, thanks for the help
Well, loops is how programs work, so deciding not to use them it not going to help you  ;)

If you don't want to clutter up the main with a lot of code then split your code up into classes. Throwing everything together in one subroutine or function is not the best of ideas anyways.
« Last Edit: May 12, 2012, 11:22:58 am by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10913
    • View Profile
    • development blog
    • Email
Re: Best way to program PacMan
« Reply #4 on: May 13, 2012, 12:45:50 am »
RenderTexture, hmm
I will take a look at this, this is what Im doing in some way..

Why do you need an off-screen image/texture?
Okay it makes sense for the map but the rest, just draw it to the screen.
For example:
  • Application start
  • Load map from file
  • Render map to RenderTexture and extract texture
  • for each frame: draw map texture, fruits and monsters
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/