0

I am trying to write a Mario 3 level 1 clone in Java, and my inspiration is Łukasz Jakowski's SMB 1 clone. You can find the source code on Github; I cloned his repo and looked thru it, noticing that the Mario sprites are actually pink boxes with Mario in them, but no such pink ever shows up.

Here's my code:

public class Mario{
//all numbers multiplied by 2 from OG game
  protected MarioState state;
  protected int x, y;
  protected BufferedImage sprite;


  public Mario(){
    this.state = MarioState.SMALL;
    this.x = 54;
    this.y = 806;
    URL spriteAtLoc = getClass().getResource("sprites/Mario/SmallStandFaceRight.bmp");

    try{
      sprite = ImageIO.read(spriteAtLoc);

    } catch(IOException e){
      System.out.println("sprite not found");
      e.printStackTrace();
    }
  }
...
  public void draw(Graphics g){
    g.drawImage(sprite, this.x, this.y, null);
  }

and then in my MarioComponent class, I draw paint this way:

  public void paintComponent(Graphics g){
    marioSprite.draw(g);
  }

How can I get my program to omit colors in the OG sprite as Jakowski does? I know his is in C++ and mine in Java, and I'm making all the tiles objects rather than taking a whole level sheet (IDK if that's a good idea), but I ultimately plan to do this by making everything on the screen an object.

Derry
  • 371
  • 1
  • 13
  • Personally, I'd just PNG transparent . If you still want to use the BMP, you're going to need to filter out the pink, probably doing a pixel copy of the master image to transparent version – MadProgrammer Jul 24 '17 at 04:55
  • they are all bitmap images; for debugging I'd imagine having all boxes/squares is good, but for playing, not so much. Is there a simple, quick method in Java to filter out the pink? – Derry Jul 24 '17 at 04:58
  • Copy the pixel data to a transparent image, filtering out the pink color - Take a closer look at the `BufferedImage` class – MadProgrammer Jul 24 '17 at 05:15
  • but would that create more files in my program folder? It's not like every time you play Jakowski's game, there are more files than there were before. – Derry Jul 24 '17 at 05:18
  • No, you'd just do in memory - But, as I said, I'd take the time to convert the images to transparent PNGs to start with and use those instead from the get go – MadProgrammer Jul 24 '17 at 05:18
  • [Possible duplicate How to remove all color except a certain rgb value](https://stackoverflow.com/questions/16877152/how-to-remove-all-color-except-a-certain-rgb-value) – MadProgrammer Jul 24 '17 at 05:20
  • [Possible duplicate How to Delete the white pixels in an image in java](https://stackoverflow.com/questions/23980554/how-to-delete-the-white-pixels-in-an-image-in-java) – MadProgrammer Jul 24 '17 at 05:22
  • how much of my code that's there do I need to change as of now? Also, I see no reason everything has to be flagged for duplicates. I was asking a general question about how something specifically like a game like this does it, not other things. – Derry Jul 24 '17 at 05:22
  • *"How can I get my program to omit colors in the OG sprite as Jakowski does?"* - Is basically asking the question "How do I remove a color from an image", to which I can find at least three previous answers, two of which I've linked here - I'll leave it up to other people as to whether they are "actual" duplicates, but to my find, they are damn close – MadProgrammer Jul 24 '17 at 05:28
  • *"I was asking a general question about how something specifically like a game like this does it, not other things."* - So that statement makes no sense, you can't ask a specifically general question. First, you should avoid asking general questions on SO, as they are of topic. I took, from your question, that you wanted to remove the pink color from the BMPs you've obtained. How do the two linked answers not provide you that information? Am I miss reading your question? If so, you'll need to go back and clarify exactly what its is you'd like use to help you with - remember, 1 question – MadProgrammer Jul 24 '17 at 05:33
  • You may be seeing [this](https://stackoverflow.com/q/3432388/230513), [this](https://stackoverflow.com/q/26115851/230513) and [this](https://stackoverflow.com/q/17755036/230513). – trashgod Jul 24 '17 at 09:19

0 Answers0