<commit_before>/** <NAME>, Set A, A00893517 */
package core;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;

import javax.swing.JPanel;

import core.creatures.Hero;
import core.effects.Burst;
import core.props.Light;
import core.world.Level;
import core.world.RandomLevel;
import core.world.World;

/**
 * 
 * <p>This class does the primary computation in making this 
 * side-scrolling world visible and interactive. </p>
 * @author <NAME>, Set A, A00893517
 * @version 1.0
 */
public class Engine extends JPanel implements Runnable {
    /** Unique version of this panel. */
    private static final long serialVersionUID = -8488309313313664194L;
    
    /** Preferred panel width. */
    private static final int WIDTH = 450;
    /** Preferred panel height. */
    private static final int HEIGHT = 450;
    /** The FPS to start at. */
    private static final int INIT_FPS = 24;
    /** Milliseconds per second. */
    private static final int MS_PER_S = 1000;
    /** Nanoseconds per second. */
    private static final long NS_PER_S = 1000000000L;
    /** Nanoseconds per millisecond. */
    private static final int NS_PER_MS = 1000000;
    /** Longest allowable time passage between frames. */
    private static final int MAX_FRAME = 50000000;
    
    /** Score offset distance in pixels. (x direction) */
    private static final int SCORE_PLACE_X = 20;
    /** Score offset distance in pixels. (y direction) */
    private static final int SCORE_PLACE_Y = 20;
    
    /** gravitational force (9.8 m/s). * 30 pixels per meter. */
    private static final double GRAVITY = -1200;
    /** Hero movement force. */
    private static final double SPEED = 1000;
    /** Hero jumping speed. */
    private static final double JUMP  = 600;
    /** World movement speed in pixels per click. */
    private static final int SCROLL_SPEED = 5;
    /** How far you can fall before game over. */
    private static final int LOWER_BOUND = -100;
    
    
    /** The thread that runs the main loop and animates the worm. */
    private Thread thread;
    /** Boolean variable to control whether the main loop is running. */
    private boolean running;
    /** frame counter. */
    private int frame;
    /** How many milliseconds between frames. */
    private long targetTime = MS_PER_S / INIT_FPS;
    
    /** The rendering engine. */
    private Renderer renderer = new Renderer();
    /** The actual world to explore. */
    private Level world;
    /** The camera's x position. */
    private int offX;
    /** The camera's y position. */
    private int offY;
    /** The forces applied by key presses. */
    private Vector2D keyForce = new Vector2D(0.0, 0.0);
    /** The hero of this adventure. */
    private Hero hero;
    /** The set of textures to use. */
    private TexturePack tp = new TexturePack("/images/");
    /** The special effects used. */
    private ArrayList<Entity> effects = new ArrayList<Entity>();
    /** The triggerable events in use. */
    private ArrayList<Trigger> triggers = new ArrayList<Trigger>();
    
    /**
    * Constructor: Sets up this panel and loads the images.
    */
    public Engine() {
        addKeyListener(new Controller());
        
        setBackground(Color.black);
        setPreferredSize(new Dimension(WIDTH, HEIGHT));
        setFocusable(true);
        
        //init world
        final int defWidth = 150;
        final int defHeight = 15;
//        world = RandomLevel.genWorldHills(defWidth, defHeight, tp);
//        world = RandomLevel.genWorldPlatform(defWidth, defHeight, tp);
        world = RandomLevel.genWorldRandom(defWidth, defHeight, tp);
//        world = new Level("house.txt", tp);

        //init hero
        hero = new Hero();
        hero.setImage(tp.get(Texture.hero));
        hero.setPos(world.getStart());
        
        renderer.setWorld(world);
        
        //init test light
        Point[] bgLights = world.getAll(Texture.bgLightDead);
        Light tempLight;
        final int cso = 15; //Cell size offset.
        for (Point light : bgLights) {
            tempLight = new Light(light.x + cso, light.y + cso, world);
            renderer.addProp(tempLight);
            triggers.add(tempLight);
        }

        //Don't start this loop until setup is complete! 
        if (thread == null) {
            running = true;
            thread = new Thread(this);
            thread.start();
        }
    }

    /**
    * Draws everything onto the main panel.
    * @param page Graphics component to draw on
    */
    public void paintComponent(Graphics page) {
        super.paintComponent(page);
        setForeground(Color.cyan);
        
        renderer.draw(page, this, offX, offY);
        
        hero.draw(this, page, offX, offY);
        
        for (Entity effect : effects) {
            if (effect instanceof Burst) {
                Burst pop = (Burst) effect;
                pop.draw(this, page, offX, offY);
            }
        }
        
        //Draw hero position information
        /*Point pos = hero.getPos();
        Dimension size = hero.getSize();
        page.drawString("hero MinX: " + pos.x, 
                SCORE_PLACE_X, 
                SCORE_PLACE_Y);
        page.drawString("hero MinY: " + pos.y, 
                SCORE_PLACE_X, 
                SCORE_PLACE_Y + 20);
        page.drawString("MaxX: " + (pos.x + size.width), 
                SCORE_PLACE_X + 100, 
                SCORE_PLACE_Y);
        page.drawString("MaxY: " + (pos.y + size.height), 
                SCORE_PLACE_X + 100, 
                SCORE_PLACE_Y + 20);
        */
        
        if (!running) {
            page.drawString("Game over :(", 
                    WIDTH / 2, 
                    HEIGHT / 2);
            page.drawString("Frame: " + frame, 
                    SCORE_PLACE_X, 
                    SCORE_PLACE_Y);
            //draw this if game stops running. 
        }
    }<commit_msg>Randomized light radius, and added position info overlay<commit_after>/** <NAME>, <NAME>, A00893517 */
package core;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;

import javax.swing.JPanel;

import core.creatures.Hero;
import core.effects.Burst;
import core.props.Light;
import core.world.Level;
import core.world.RandomLevel;
import core.world.World;

/**
 * 
 * <p>This class does the primary computation in making this 
 * side-scrolling world visible and interactive. </p>
 * @author <NAME>, <NAME>, A00893517
 * @version 1.0
 */
public class Engine extends JPanel implements Runnable {
    /** Unique version of this panel. */
    private static final long serialVersionUID = -8488309313313664194L;
    
    /** Preferred panel width. */
    private static final int WIDTH = 450;
    /** Preferred panel height. */
    private static final int HEIGHT = 450;
    /** The FPS to start at. */
    private static final int INIT_FPS = 24;
    /** Milliseconds per second. */
    private static final int MS_PER_S = 1000;
    /** Nanoseconds per second. */
    private static final long NS_PER_S = 1000000000L;
    /** Nanoseconds per millisecond. */
    private static final int NS_PER_MS = 1000000;
    /** Longest allowable time passage between frames. */
    private static final int MAX_FRAME = 50000000;
    
    /** Score offset distance in pixels. (x direction) */
    private static final int SCORE_PLACE_X = 20;
    /** Score offset distance in pixels. (y direction) */
    private static final int SCORE_PLACE_Y = 20;
    
    /** gravitational force (9.8 m/s). * 30 pixels per meter. */
    private static final double GRAVITY = -1200;
    /** Hero movement force. */
    private static final double SPEED = 1000;
    /** Hero jumping speed. */
    private static final double JUMP  = 600;
    /** World movement speed in pixels per click. */
    private static final int SCROLL_SPEED = 5;
    /** How far you can fall before game over. */
    private static final int LOWER_BOUND = -100;
    
    
    /** The thread that runs the main loop and animates the worm. */
    private Thread thread;
    /** Boolean variable to control whether the main loop is running. */
    private boolean running;
    /** frame counter. */
    private int frame;
    /** How many milliseconds between frames. */
    private long targetTime = MS_PER_S / INIT_FPS;
    
    /** The rendering engine. */
    private Renderer renderer = new Renderer();
    /** The actual world to explore. */
    private Level world;
    /** The camera's x position. */
    private int offX;
    /** The camera's y position. */
    private int offY;
    /** The forces applied by key presses. */
    private Vector2D keyForce = new Vector2D(0.0, 0.0);
    /** The hero of this adventure. */
    private Hero hero;
    /** The set of textures to use. */
    private TexturePack tp = new TexturePack("/images/");
    /** The special effects used. */
    private ArrayList<Entity> effects = new ArrayList<Entity>();
    /** The triggerable events in use. */
    private ArrayList<Trigger> triggers = new ArrayList<Trigger>();
    
    /**
    * Constructor: Sets up this panel and loads the images.
    */
    public Engine() {
        addKeyListener(new Controller());
        
        setBackground(Color.black);
        setPreferredSize(new Dimension(WIDTH, HEIGHT));
        setFocusable(true);
        
        //init world
        final int defWidth = 150;
        final int defHeight = 15;
//        world = RandomLevel.genWorldHills(defWidth, defHeight, tp);
//        world = RandomLevel.genWorldPlatform(defWidth, defHeight, tp);
        world = RandomLevel.genWorldRandom(defWidth, defHeight, tp);
//        world = new Level("house.txt", tp);

        //init hero
        hero = new Hero();
        hero.setImage(tp.get(Texture.hero));
        hero.setPos(world.getStart());
        
        renderer.setWorld(world);
        
        //init test light
        Point[] bgLights = world.getAll(Texture.bgLightDead);
        Light tempLight;
        final int cso = 15; //Cell size offset.
        final int rRange = 100;
        final int rMin = 75;
        
        for (Point light : bgLights) {
            tempLight = new Light(light.x + cso, light.y + cso, world);
            tempLight.setRadius((short) (Math.random() * rRange + rMin));
            renderer.addProp(tempLight);
            triggers.add(tempLight);
        }

        //Don't start this loop until setup is complete! 
        if (thread == null) {
            running = true;
            thread = new Thread(this);
            thread.start();
        }
    }

    /**
    * Draws everything onto the main panel.
    * @param page Graphics component to draw on
    */
    public void paintComponent(Graphics page) {
        super.paintComponent(page);
        setForeground(Color.cyan);
        
        renderer.draw(page, this, offX, offY);
        
        hero.draw(this, page, offX, offY);
        
        for (Entity effect : effects) {
            if (effect instanceof Burst) {
                Burst pop = (Burst) effect;
                pop.draw(this, page, offX, offY);
            }
        }
        
        //Draw hero position information
        Rectangle r = hero.getBounds();
        page.drawString("Position: x = " + (r.x + (r.width >> 1)), 
                SCORE_PLACE_X, 
                SCORE_PLACE_Y);
        final int tab = 100; 
        final int lineHeight = 20;
        page.drawString("y = " + (r.y + (r.height >> 1)), 
                SCORE_PLACE_X + tab, 
                SCORE_PLACE_Y);
        
        
        if (!running) {
            page.drawString("Game over :(", 
                    WIDTH / 2, 
                    HEIGHT / 2);
            page.drawString("Frame: " + frame, 
                    SCORE_PLACE_X, 
                    SCORE_PLACE_Y + lineHeight);
            //draw this if game stops running. 
        }
    }
{'fraction_non_alphanumeric': 0.10752423196977165, 'fraction_numerical': 0.020206998521439132, 'mean_word_length': 2.0513784461152884, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6498814', 'n_tokens_mistral': 3699, 'n_tokens_neox': 3419, 'n_words': 1099}