Projects >> projectbulletspray >>a7462a938c35b597faaebcc43a48cd5354383218

Chunk
Conflicting content
    	alive = false; 

    protected boolean alive; //is the entity alive? (dead entities get removed)
    public boolean alive() { return this.alive; }
<<<<<<< HEAD
    
    public void kill(){ 
    	setActivation(false); 
=======
    public void kill(){ 
	alive = false; 
	setActivation(false);
>>>>>>> e71a7142fa54281887aee6309fe662fcbb56f870
    }
    
    protected int hp; //hit points left, hitting zero turns alive to false
Solution content
    protected boolean alive; //is the entity alive? (dead entities get removed)
    public boolean alive() { return this.alive; }

    public void kill(){ 
	alive = false; 
	setActivation(false);
    }
    
    protected int hp; //hit points left, hitting zero turns alive to false
File
Entity.java
Developer's decision
Version 1
Kind of conflict
Attribute
Method invocation
Method signature
Chunk
Conflicting content
public class Level {

<<<<<<< HEAD
	public static final String SPRITE_SHEET = "resources/pbs-spritesheet.png";
=======
    public static final String SPRITE_SHEET = "resources/pbs-spritesheet.png";

    public static enum Layer { 
	BACKGROUND, 
	    TRIGGERS,
	    STATIC, 
	    FX,
	    HOSTILE, 
	    ENEMY, 
	    FRIENDLY, 
	    PLAYER, 
	    FOREGROUND,
	    HUD }
    
    public static int NUM_LAYERS = Layer.values().length;
    
    //important level info
    protected int score;
    public int modScore(int m){ return score += m; }
    public int getScore(){ return score; }
    
    protected int gametime;
    public int getTime(){ return gametime/1000; }
    
    //center position of screen
    protected Vector2D camera;
    public void setCam(Vector2D cam){ camera = cam; }
    public Vector2D getCam(){ return camera; }

    //scroll vector
    protected Vector2D scrollspeed;
    public void setScrollSpeed(Vector2D ss){ scrollspeed = ss; }
    public Vector2D getScrollSpeed(){ return scrollspeed; }

    //list of layers
    private List> allTheLayers;

    //list of collision handlers 
    private List collisionHandlers;

    //statement list
    private Stack events;
    public void addStatement(Statement s){ events.push(s); }
    public void execute(){
	Statement s;
	while(!events.empty()){
	    s = events.pop();
	    s.execute(this);
	}
    }

    //symbol table with templated entities/triggers
    HashMap templates;
    public ObjectDescription getTemplate(String s){
	System.out.println("get Template");
	ObjectDescription od = templates.get(s);
	if(od == null)
	    System.out.println("No object description named " + s);
	return od;
    }
    public void addTemplate(String s, ObjectDescription od){
	templates.put(s, od);
    }


    public Level(){
	score = 0;
	gametime = 0;
	
	camera = new Vector2D(320,240);
	scrollspeed = new Vector2D(1, 0);
	
	events = new Stack();
	templates = new HashMap();
>>>>>>> e71a7142fa54281887aee6309fe662fcbb56f870

	public static enum Layer {
		BACKGROUND, STATIC, FX, HOSTILE, ENEMY, FRIENDLY, PLAYER, FOREGROUND, HUD
Solution content
public class Level {


    public static final String SPRITE_SHEET = "resources/pbs-spritesheet.png";

    public static enum Layer { 
	BACKGROUND, 
	    TRIGGERS,
	    STATIC, 
	    FX,
	    HOSTILE, 
	    ENEMY, 
	    FRIENDLY, 
	    PLAYER, 
	    FOREGROUND,
	    HUD }
    
    public static int NUM_LAYERS = Layer.values().length;
    
    //important level info
    protected int score;
    public int modScore(int m){ return score += m; }
    public int getScore(){ return score; }
    
    protected int gametime;
    public int getTime(){ return gametime/1000; }
    
    //center position of screen
    protected Vector2D camera;
    public void setCam(Vector2D cam){ camera = cam; }
    public Vector2D getCam(){ return camera; }

    //scroll vector
    protected Vector2D scrollspeed;
    public void setScrollSpeed(Vector2D ss){ scrollspeed = ss; }
    public Vector2D getScrollSpeed(){ return scrollspeed; }

    //list of layers
    private List> allTheLayers;

    //list of collision handlers 
    private List collisionHandlers;

    //statement list
    private Stack events;
    public void addStatement(Statement s){ events.push(s); }
    public void execute(){
	Statement s;
	while(!events.empty()){
	    s = events.pop();
	    s.execute(this);
	}
    }

    //symbol table with templated entities/triggers
    HashMap templates;
    public ObjectDescription getTemplate(String s){
	System.out.println("get Template");
	ObjectDescription od = templates.get(s);
	if(od == null)
	    System.out.println("No object description named " + s);
	return od;
    }
    public void addTemplate(String s, ObjectDescription od){
	templates.put(s, od);
    }


    public Level(){
	score = 0;
	gametime = 0;
	
	camera = new Vector2D(320,240);
	scrollspeed = new Vector2D(1, 0);
	
	events = new Stack();
	templates = new HashMap();
    }


	// setters
	public void add(Entity e, Layer l) {
		getLayer(l).add(e);
	}

	// getters
	public List getLayers() {
		List layerList = new ArrayList();
		layerList.addAll(allTheLayers);
		return layerList;
	}

	public PBSQuadLayer getLayer(Layer l) {
		return allTheLayers.get(l.ordinal());
	}

	public void setupCollisionHandlers() {
		collisionHandlers.add(new QuadLayerCollisionHandler(
				getLayer(Layer.FRIENDLY), getLayer(Layer.ENEMY)) {
			public void collide(Entity body1, Entity body2) {
				// this is where you define behavior for a collision
				// body1 is from friendly bullet layer
				// body2 is from enemy layer

				if (body1.isActive() && body2.isActive()) {

					double rx = 4.0 * Math.random() - 2;
					double ry = 4.0 * Math.random() - 2;

					Entity e = new Entity(SPRITE_SHEET + "#small_burst");
					e.setPosition(body1.getCenterPosition().translate(
							new Vector2D(rx, ry)));
					e.setCustomAnimation(new AnimateOnce(75));
					add(e, Layer.FX);
					body1.kill();
					body2.modhp(-1);
					
					

					if (body2.alive() == false) {
						score += body2.value();

						for (int i = 0; i < 5; i++) {
							rx = 100.0 * Math.random() - 50;
							ry = 100.0 * Math.random() - 50;
							e = new Entity(SPRITE_SHEET + "#large_burst");
							e.setPosition(body1.getCenterPosition().translate(
									new Vector2D(rx, ry)));
							e.setCustomAnimation(new AnimateOnce(75));
							e.setAge((long) (-rx));
							add(e, Layer.FX);
						}
					}
				}
			}
		});
	collisionHandlers.add(new QuadLayerCollisionHandler(getLayer(Layer.PLAYER), getLayer(Layer.STATIC)){

		@Override
		public void collide(Entity body1, Entity body2) {
			if(body1.isActive() && body2.isActive()){
				double rx = 4.0*Math.random() -2.0;
				double ry = 4.0*Math.random() -2.0;
				
				Entity e = new Entity(SPRITE_SHEET + "#large_burst");
				e.setPosition(body1.getCenterPosition().translate(new Vector2D(rx, ry)));
				e.setCustomAnimation(new AnimateOnce(75));
				add(e, Layer.FX);
				
				//Kill the player, do any sort of updates to the game necessary
				body1.kill();
				
				
			}
		}
	});
	
	collisionHandlers.add(new QuadLayerCollisionHandler(getLayer(Layer.PLAYER), getLayer(Layer.ENEMY)){

		@Override
		public void collide(Entity body1, Entity body2) {
			if(body1.isActive() && body2.isActive()){
				double rx = 8.0*Math.random() -4.0;
				double ry = 8.0*Math.random() -4.0;
				
				Entity e = new Entity(SPRITE_SHEET + "#large_burst");
				e.setPosition(body1.getCenterPosition().translate(new Vector2D(rx, ry)));
				e.setCustomAnimation(new AnimateOnce(75));
				add(e, Layer.FX);
				
				e = new Entity(SPRITE_SHEET + "#small_burst");
				e.setPosition(body2.getCenterPosition().translate(new Vector2D(ry, rx)));
				e.setCustomAnimation(new AnimateOnce(75));
				add(e, Layer.FX);
				
				body2.kill();
				body1.modhp(-1);
			}
		}
	});

		collisionHandlers.add(new ElasticCollisionHandler(
				getLayer(Layer.ENEMY), getLayer(Layer.PLAYER)));

		// System.out.println("col handlers size " + collisionHandlers.size());
	}

	/* stwMin, stwMax are ScreenToWorld coordinates for QuadTree */
	protected void updateLayers(long deltaMs, Vector2D stwMin, Vector2D stwMax) {
		// pass the task of updating individual entities to the layer
		for (PBSQuadLayer v : allTheLayers) {
			gametime += deltaMs;
			v.updateTreeBounds(stwMin, stwMax);
			v.update(deltaMs);
		}
	}

	protected void checkForCollisions() {
		for (QuadLayerCollisionHandler c : collisionHandlers) {
			c.findAndReconcileCollisions();
		}
	}

	public void update(long deltaMs, Vector2D stwMin, Vector2D stwMax) {

		camera = camera.translate(scrollspeed.scale(deltaMs / 100.0));

		// execute all statements on queue
		execute();

		// call update on each layer
		updateLayers(deltaMs, stwMin, stwMax);

		// call "shoot" on all enemy entities in case they have weapons to fire
		Iterator enemylist = getLayer(Layer.ENEMY).iterator();
		while (enemylist.hasNext()) {
			Entity e = enemylist.next();
			e.shoot(this, deltaMs);
		}

		// check for collisions
		checkForCollisions();

	//behavior custom to each level goes here

	//check to see which triggers need to be fired...
	Iterator elist = getLayer(Layer.TRIGGERS).iterator();
	if(elist != null)
	    while(elist.hasNext()){
		Entity t = elist.next();
		t.fireTrigger(this, deltaMs);
	    }
	
	//call "shoot" on all enemy entities in case they have weapons to fire
	elist = getLayer(Layer.ENEMY).iterator();
	if(elist != null)
	    while(elist.hasNext()){
		Entity e = elist.next();
		e.shoot(this, deltaMs);
	    }

	//check for collisions
	checkForCollisions();	
	
    }

}
File
Level.java
Developer's decision
Manual
Kind of conflict
Attribute
Comment
Enum declaration
Method declaration
Method invocation
Method signature
Chunk
Conflicting content
	
	//call "shoot" on all enemy entities in case they have weapons to fire
		// check for collisions
		checkForCollisions();

<<<<<<< HEAD
	}
=======
	//behavior custom to each level goes here

	//check to see which triggers need to be fired...
	Iterator elist = getLayer(Layer.TRIGGERS).iterator();
	if(elist != null)
	    while(elist.hasNext()){
		Entity t = elist.next();
		t.fireTrigger(this, deltaMs);
	    }
	elist = getLayer(Layer.ENEMY).iterator();
	if(elist != null)
	    while(elist.hasNext()){
		Entity e = elist.next();
		e.shoot(this, deltaMs);
	    }

	//check for collisions
	checkForCollisions();	
	
    }
>>>>>>> e71a7142fa54281887aee6309fe662fcbb56f870

}
Solution content
		// check for collisions
		checkForCollisions();

	//behavior custom to each level goes here

	//check to see which triggers need to be fired...
	Iterator elist = getLayer(Layer.TRIGGERS).iterator();
	if(elist != null)
	    while(elist.hasNext()){
		Entity t = elist.next();
		t.fireTrigger(this, deltaMs);
	    }
	
	//call "shoot" on all enemy entities in case they have weapons to fire
	elist = getLayer(Layer.ENEMY).iterator();
	if(elist != null)
	    while(elist.hasNext()){
		Entity e = elist.next();
		e.shoot(this, deltaMs);
	    }

	//check for collisions
	checkForCollisions();	
	
    }

}
File
Level.java
Developer's decision
Version 2
Kind of conflict
Comment
If statement
Method invocation
Variable