Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branche #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions res/shaders/default_textured.frag
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ layout(location=0) out vec4 color;
in vec2 v_texCoord;

uniform sampler2D u_texture;
uniform vec4 u_alphaColor;

void main() {
color = texture(u_texture, v_texCoord);
}
color = texture(u_texture, v_texCoord)*u_alphaColor;
}
Binary file added res/textures/cheese.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/textures/meat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/textures/mushroom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/textures/onion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/textures/pot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/textures/pot_empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/textures/pot_mushroom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/textures/pot_onion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/textures/pot_tomato.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/textures/salade.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/textures/tomato.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions src/fr/ovrckdlike/ppp/graphics/KeyListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public static void keyCallback(long window, int key, int scancode, int action, i
}


static public boolean isKeyPressed(int keyCode) {
return get().keyPressed[keyCode];

public boolean isKeyPressed(int keyCode) {
return keyPressed[keyCode];

}


Expand Down
14 changes: 14 additions & 0 deletions src/fr/ovrckdlike/ppp/graphics/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ public static void drawTexture(float x, float y, float width, float height, floa
defaultTextured.bind();
defaultTextured.setUniform4f("u_position", x, y, width, height);
defaultTextured.setUniform4f("u_tex", 0, 0, 1, 1);
defaultTextured.setUniform4f("u_alphaColor", 1, 1, 1, 1);
defaultTextured.setUniform1f("u_theta", angle);
setCameraUniform(defaultTextured);
texture.bind();
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, NULL);
}
public static void drawTextureTransparent(float x, float y, float width, float height, float angle, float alpha, Texture texture) {
y = 1080 - y;
height = -height;
VertexArray.simpleQuad.bind();
defaultTextured.bind();
defaultTextured.setUniform4f("u_position", x, y, width, height);
defaultTextured.setUniform4f("u_tex", 0, 0, 1, 1);
defaultTextured.setUniform4f("u_alphaColor", 1, 1, 1, alpha);
defaultTextured.setUniform1f("u_theta", angle);
setCameraUniform(defaultTextured);
texture.bind();
Expand Down
10 changes: 10 additions & 0 deletions src/fr/ovrckdlike/ppp/graphics/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ public void init() {
Texture.serviceTable = Texture.loadTexture("/textures/service_table.png");
Texture.plateReturn = Texture.loadTexture("/textures/plate_return.png");
Texture.pot = Texture.loadTexture("/textures/pot.png");
Texture.potEmpty = Texture.loadTexture("/textures/pot_empty.png");
Texture.potMushroom = Texture.loadTexture("/textures/pot_mushroom.png");
Texture.potTomato = Texture.loadTexture("/textures/pot_tomato.png");
Texture.potOnion = Texture.loadTexture("/textures/pot_onion.png");
Texture.onion = Texture.loadTexture("/textures/onion.png");
Texture.tomato = Texture.loadTexture("/textures/tomato.png");
Texture.cheese = Texture.loadTexture("/textures/cheese.png");
Texture.meat = Texture.loadTexture("/textures/meat.png");
Texture.mushroom = Texture.loadTexture("/textures/mushroom.png");



} catch (IOException e) {
Expand Down
9 changes: 9 additions & 0 deletions src/fr/ovrckdlike/ppp/internal/Texture.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public class Texture {
public static Texture serviceTable;
public static Texture plateReturn;
public static Texture pot;
public static Texture potEmpty;
public static Texture potTomato;
public static Texture potOnion;
public static Texture potMushroom;
public static Texture mushroom;
public static Texture tomato;
public static Texture cheese;
public static Texture onion;
public static Texture meat;



Expand Down
5 changes: 3 additions & 2 deletions src/fr/ovrckdlike/ppp/objects/Ingredient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public int getType() {
public Ingredient(int type) {
this.type = type;
this.prepared = false;
this.direction = 0;
this.mode = 0;

}
Expand All @@ -29,8 +30,8 @@ public void render() {
float renderPos[] = {this.pos[0] - (this.size*zoom)/2, this.pos[1] - (this.size*zoom)/2};
switch (type) {
case 1 :
if (prepared) Renderer.drawTexture(renderPos[0], renderPos[1], this.size*zoom, this.size*zoom, 0, Texture.salade); //changer la texture
else Renderer.drawTexture(renderPos[0], renderPos[1], this.size*zoom, this.size*zoom, 0, Texture.salade);
if (prepared) Renderer.drawTexture(renderPos[0], renderPos[1], this.size*zoom, this.size*zoom, (float)(direction*Math.PI/4), Texture.salade); //changer la texture
else Renderer.drawTexture(renderPos[0], renderPos[1], this.size*zoom, this.size*zoom, (float)(direction*Math.PI/4), Texture.salade);

}
}
Expand Down
13 changes: 12 additions & 1 deletion src/fr/ovrckdlike/ppp/objects/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

public abstract class Item {
protected float pos[] = new float[2];
protected int size = 40;
protected int size = 50;
protected boolean inPlayerHand = false;
protected int mode;
protected int direction;

public abstract void render();
public abstract void prepare();
Expand All @@ -28,4 +29,14 @@ public void setPos(float x, float y) {
public float[] getPos() {
return this.pos;
}

public void collide(Player player) {
if (player.distanceTo(this.pos) < (player.getSize()+this.size)/2) {
double angle = player.angleTo(this.pos);
this.pos[0] += (player.getLastMove()) * Math.cos(angle);
this.pos[1] += (-player.getLastMove()) * Math.sin(angle);

}

}
}
19 changes: 15 additions & 4 deletions src/fr/ovrckdlike/ppp/objects/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import fr.ovrckdlike.ppp.graphics.Renderer;
import fr.ovrckdlike.ppp.internal.Texture;
import fr.ovrckdlike.ppp.tiles.Tile;


public class Player {
Expand All @@ -13,15 +14,25 @@ public class Player {
private int direction;
private int moveSpeed;
private Item inHand;
private float lastMove;

public Player(float[] pos) {
this.pos = pos;
this.size = 70;
this.size = 100;
this.direction = 0;
this.moveSpeed = 300;
this.lastMove = 0;
this.inHand = null;
}

public int getSize() {
return size;
}

public float getLastMove() {
return lastMove;
}

public Item getInHand() {
return this.inHand;
}
Expand Down Expand Up @@ -95,21 +106,19 @@ public boolean takeNearestItem(List<Item> itemList) {
int itemId = this.nearestItem(itemList);
if (itemId == -1) return false;
Item item = itemList.get(itemId);
if (distanceTo(item.getPos()) > 50) return false;
if (distanceTo(item.getPos()) > size*1.15) return false;
else {
if (this.inHand != null) return false;
else {
this.inHand = item;
item.setInPlayerHand(true);
item.setMode(0);
return true;
}
}
}

public void drop() {
if (inHand != null) {
inHand.setMode(1);
inHand.setInPlayerHand(false);
inHand = null;
}
Expand Down Expand Up @@ -213,6 +222,8 @@ public void movePlayer( long dt, List<Tile> tileList) {

pos[0] += distX;
pos[1] += distY;
lastMove = (float) (Math.sqrt(distX * distX + distY * distY));

}
public void changeAngle(boolean up, boolean down, boolean left, boolean right) {

Expand Down
37 changes: 34 additions & 3 deletions src/fr/ovrckdlike/ppp/objects/Pot.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
package fr.ovrckdlike.ppp.objects;

import fr.ovrckdlike.ppp.graphics.Renderer;
import fr.ovrckdlike.ppp.internal.Texture;
import fr.ovrckdlike.ppp.tiles.CookerContainer;

public class Pot extends CookerContainer{
private int[] content;
private int[] content = new int[3];


public Pot(float[] pos) {
this.pos = pos;
this.direction = 0;
for (int i = 0; i < 3; i++) {
this.content[i] = -1;
}
}
public void flush() {
for (int i = 0; i < 3; i++) {
this.content[i] = 0;
this.content[i] = -1;
}
}

public int checkForContent(int content) { // mettre -1 pour vide
int corresponding = 0;
for (int i = 0; i < 3; i++) {
if (this.content[i] != content) corresponding++;
}
return corresponding;
}


public void render() {
int zoom = this.mode+1;
float renderPos[] = {this.pos[0] - (this.size*zoom)/2, this.pos[1] - (this.size*zoom)/2};

Renderer.drawTexture(renderPos[0], renderPos[1], this.size*zoom, this.size*zoom, (float)(direction*Math.PI/4), Texture.pot);
if (this.checkForContent(-1) == 0) {
Renderer.drawTexture(renderPos[0], renderPos[1], this.size*zoom, this.size*zoom, (float)(direction*Math.PI/4), Texture.potEmpty);
}
else {
int totalContent = this.checkForContent(-1);
float alphaTomato = this.checkForContent(0) / totalContent;
Renderer.drawTextureTransparent(renderPos[0], renderPos[1], this.size*zoom, this.size*zoom, (float)(direction*Math.PI/4), alphaTomato, Texture.potTomato);
float alphaOnion = this.checkForContent(2) / totalContent;
Renderer.drawTextureTransparent(renderPos[0], renderPos[1], this.size*zoom, this.size*zoom, (float)(direction*Math.PI/4), alphaOnion, Texture.potOnion);
float alphaMushroom = this.checkForContent(3) / totalContent;
Renderer.drawTextureTransparent(renderPos[0], renderPos[1], this.size*zoom, this.size*zoom, (float)(direction*Math.PI/4), alphaMushroom, Texture.potMushroom);
}
}

}
7 changes: 0 additions & 7 deletions src/fr/ovrckdlike/ppp/objects/booleansItems.txt

This file was deleted.

19 changes: 18 additions & 1 deletion src/fr/ovrckdlike/ppp/scene/GameScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fr.ovrckdlike.ppp.objects.Player;
import fr.ovrckdlike.ppp.objects.*;
import fr.ovrckdlike.ppp.physics.Time;
import fr.ovrckdlike.ppp.tiles.*;
import fr.ovrckdlike.ppp.graphics.Color;
import fr.ovrckdlike.ppp.graphics.KeyListener;
import fr.ovrckdlike.ppp.graphics.Renderer;
Expand All @@ -29,6 +30,7 @@ public class GameScene extends Scene {

private Table temp;
private Table temp2;
private Pot tempPot;

public static GameScene game = new GameScene(0);

Expand All @@ -39,12 +41,16 @@ public GameScene(int map) {
float posp2[] = {300, 1080/2};
float posIR[] = {1000, 500};
float posIR2[] = {1120, 620};
float posPot[] = {500, 700};

temp = new Table(posIR);
temp2 = new Table(posIR2);
tempPot = new Pot(posPot);

tileList.add(temp);
tileList.add(temp2);
itemList.add(tempPot);

this.lastP1Action1 = 0;
this.lastP2Action1 = 0;

Expand All @@ -60,9 +66,15 @@ public GameScene(int map) {
public void render() {
this.player1.render();
this.player2.render();

temp.render();
temp2.render();

for (Item item : itemList) {
item.render();
}
for (Tile tile : tileList) {
tile.render();
}
}

public void run() {
Expand All @@ -89,6 +101,11 @@ public void run() {
player2.movePlayer(Time.get().getDt(), tileList);
}

for (Item item : itemList) {
item.collide(player1);
item.collide(player2);
}


if (p1action1 && Time.get().timeSince(lastP1Action1) > 0.25) {
lastP1Action1 = Time.get().getCurrentTime();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package fr.ovrckdlike.ppp.objects;
package fr.ovrckdlike.ppp.tiles;

import fr.ovrckdlike.ppp.graphics.Renderer;
import fr.ovrckdlike.ppp.internal.Texture;
import fr.ovrckdlike.ppp.objects.Ingredient;
import fr.ovrckdlike.ppp.objects.Item;
import fr.ovrckdlike.ppp.objects.Plate;
import fr.ovrckdlike.ppp.objects.Player;

import java.util.List;
import java.util.ArrayList;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package fr.ovrckdlike.ppp.objects;
package fr.ovrckdlike.ppp.tiles;

import fr.ovrckdlike.ppp.objects.Item;

public abstract class CookerContainer extends Item {
protected int cookingTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package fr.ovrckdlike.ppp.objects;
package fr.ovrckdlike.ppp.tiles;

import fr.ovrckdlike.ppp.graphics.Renderer;
import fr.ovrckdlike.ppp.internal.Texture;
import fr.ovrckdlike.ppp.objects.Item;



Expand Down Expand Up @@ -30,6 +31,9 @@ public Item dropOrTake(Item newContent) { // a changer
this.content.setMode(1);
this.content.setPos(this.pos[0]+20, this.pos[1]+20);
}
if (oldContent != null) {
oldContent.setMode(0);
}
return oldContent;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package fr.ovrckdlike.ppp.objects;
package fr.ovrckdlike.ppp.tiles;

import java.util.ArrayList;

import fr.ovrckdlike.ppp.graphics.Renderer;
import fr.ovrckdlike.ppp.internal.Texture;
import fr.ovrckdlike.ppp.objects.Plate;

public class Dryer extends Tile{
private int nbPlate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.ovrckdlike.ppp.objects;
package fr.ovrckdlike.ppp.tiles;

import fr.ovrckdlike.ppp.graphics.Renderer;
import fr.ovrckdlike.ppp.internal.Texture;
Expand Down
Loading