Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:37:07+00:00 2026-06-03T07:37:07+00:00

So, basically I’m trying to use a char array for a character sprite for

  • 0

So, basically I’m trying to use a char array for a character sprite for my game prototype right now, but I cannot find a working way to read each element in the correct ‘row’ to print out the character (trying to find a way to draw the sprite by using fill rects line by line of arrays). Again, I’ve tried many ways such as if (i % 5 == 0) y_temp += 5; for “indenting” to fill rectangles of the sprite on a new row, but none of it is working.
Suggestions/help anyone?

Code:

import java.awt.*;
import java.awt.event.*;  
import javax.swing.*;

public class test extends JFrame {
    private int x_pos, y_pos;
    private JFrame frame;
    private draw dr;
    private char[] WARRIOR;
    private Container con;
    public test() {
        x_pos = y_pos = 200;
        frame = new JFrame("StixRPG");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(1000, 500);
        frame.setResizable(false);
        frame.setVisible(true);
        con = frame.getContentPane();
        con.setBackground(Color.black);
        dr = new draw();
        dr.setBackground(Color.black);
        con.add(dr);
        WARRIOR = (
      " " +
        "!!!!!" +
        "!!ooo" +
        "!!!!!" +
        "#####" +
        "#####" +
        "#####" +
        "** **").toCharArray();
    }
    public static void main(String[] args) {
        test tst = new test();
    }
    class draw extends JPanel { 
        public draw() {
        }
        public void paintComponent(Graphics g) {
            super.paintComponents(g);
             int y_temp = y_pos;
            for (int i = 0; i < WARRIOR.length; i++) {
                 if (WARRIOR[i] == '!') {
                     g.setColor(new Color(0, 0, 204));
                    g.fillRect(x_pos+i*5, y_temp, 5, 5);
                }
                else if (WARRIOR[i] == 'o') {
                    g.setColor(new Color(204, 0, 0));
                    g.fillRect(x_pos+i*5, y_temp, 5, 5);
                }
                else if (WARRIOR[i] == '#') {
                    g.setColor(new Color(0, 0, 102));
                    g.fillRect(x_pos+i*5, y_temp, 5, 5);
                }
                else if (WARRIOR[i] == '*') {
                    g.setColor(Color.black);
                     g.fillRect(x_pos+i*5, y_temp, 5, 5);
                }
            }
        }   
    }   
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:37:09+00:00Added an answer on June 3, 2026 at 7:37 am

    If I understand you correctly, you should get the right coordinates like this: x = i % 5; y = i / 5;. So then, you can fillRect(x*5, y*5, 5, 5);.

    EDIT: I just saw that additional space. This means you will have to subtract one first:
    x = (i-1) % 5; y = (i-1) / 5;

    EDIT 2: Yeah, and then of course you will have to add y_pos and x_pos: fillRect(x_pos + x*5, y_pos + y*5, 5, 5);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I'm trying to improve on the Ghosts in a Pacman game I'm making.
Basically, what I am trying to do is to find last section of PE
Basically i've a table for my users (it's nightclub website) and now i'm trying
Basically, what I'm trying to create is a page of div tags, each has
Basically what I'm trying to do is make a very simple vertical bullet projectile
Basically what I am trying to achieve is check if user is logged in
Basically I'm trying to make a web coding tutorial site (awesome that i cant
Basically i'm trying to build a comment system. The user looks at a photo
Basically I am trying to restart a service from a php web page. Here
Basically, I'm trying to tap into the Soap pipeline in .NET 2.0 - I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.