Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tuto;
- import java.io.FileNotFoundException;
- import org.newdawn.slick.*;
- public class Main extends BasicGame {
- float SPEED = 0.4f;
- float GRAVITY = 0.5f;
- int a = 0;
- int stepGame = 0;
- Carte carte0 = new Carte();
- Perso square = new Perso(0,0,50,50);
- public Main(String title) {
- super("Mario");
- // TODO Auto-generated constructor stub
- }
- public static void main(String[] args) throws SlickException{
- AppGameContainer app = new AppGameContainer(new Main("Game"));
- app.setDisplayMode(800, 600, false);
- app.getInput();
- app.start();
- }
- @Override
- public void render(GameContainer gc, Graphics g) throws SlickException {
- if (carte0.map[0][11]!=1){
- try {
- carte0.readMap();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- int tempa,tempb;
- for (tempa=0;tempa<16;tempa++){
- for (tempb=0;tempb<12;tempb++){
- if (carte0.map[tempa][tempb]==1){
- g.setColor(new Color(255, 255, 255));
- g.fillRect(tempa*50, tempb*50, 50, 50);
- }
- if (carte0.map[tempa][tempb]==0){
- g.setColor(new Color(128, 128, 128));
- g.fillRect(tempa*50, tempb*50, 50, 50);
- }
- }
- }
- g.setColor(new Color(121, 147, 176));
- g.fillRect(square.x, square.y, square.width, square.height);
- // TODO Auto-generated method stub
- g.setColor(new Color(200, 200, 200));
- g.drawString("y="+square.y, 500, 0);
- g.drawString("x="+square.x, 500, 50);
- g.drawString("a="+a, 500, 100);
- }
- @Override
- public void init(GameContainer arg0) throws SlickException {
- // TODO Auto-generated method stub
- }
- @Override
- public void update(GameContainer gc, int arg1) throws SlickException {
- Input input = gc.getInput();
- if(input.isKeyDown(Input.KEY_D)){
- if (collide()==false){
- square.x = square.x+SPEED;
- }
- if (collide()==true){
- square.x = square.x-SPEED;
- }
- }
- if(input.isKeyDown(Input.KEY_Q)){
- if (collide()==false){
- square.x = square.x-SPEED;
- }
- if (collide()==true){
- square.x = square.x+SPEED;
- }
- }
- if(square.y+square.height<600){
- if (collide()==false){
- square.y = square.y+GRAVITY;
- }
- if (collide()==true){
- square.y = square.y-GRAVITY;
- }
- }
- if(input.isKeyDown(Input.KEY_Z) && a==0 ){
- a = 1;
- }
- if (a == 400){a=0;}
- if (a != 0 && input.isKeyDown(Input.KEY_Z)){
- square.y = square.y - GRAVITY*2;
- a++;
- }
- }
- public boolean collide(){
- int tempa,tempb;
- for (tempa=0;tempa<16;tempa++){
- for (tempb=0;tempb<12;tempb++){
- if (carte0.map[tempa][tempb]==1){
- int tempE = 1;
- int xCUBE = tempa*50;
- int yCUBE = tempb*50;
- if((xCUBE >= square.x + square.width) // trop à droite
- || (xCUBE + 50 <= square.x) // trop à gauche
- || (yCUBE >= square.y + square.height) // trop en bas
- || (yCUBE + 50 <= square.y)){
- return false;
- }
- }
- }
- }
- return true;
- }
- }
Add Comment
Please, Sign In to add comment