Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MeuPrimeiroMundo,implementandoTeclado
- Loading branch information
1 parent
4310e0e
commit c6df8e1
Showing
9 changed files
with
146 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.ks2002br.entities; | ||
|
||
import java.awt.Color; | ||
import java.awt.Graphics; | ||
|
||
import com.ks2002br.frameworks.GameObject; | ||
import com.ks2002br.frameworks.ObjectId; | ||
|
||
public class Player extends GameObject { | ||
|
||
public Player(float x, float y, ObjectId id) { | ||
super(x, y, id); | ||
} | ||
|
||
public void tick() { | ||
x+=spdX; | ||
y+=spdY; | ||
} | ||
|
||
|
||
public void render(Graphics g) { | ||
g.setColor(Color.white); | ||
g.fillRect((int)x, (int)y,64, 64); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.ks2002br.frameworks; | ||
|
||
import java.awt.Color; | ||
import java.awt.Graphics; | ||
|
||
public class Bloco extends GameObject{ | ||
|
||
public Bloco(float x, float y, ObjectId id) { | ||
super(x, y, id); | ||
} | ||
|
||
public void tick() { | ||
} | ||
|
||
public void render(Graphics g) { | ||
g.setColor(Color.GREEN); | ||
g.fillRect((int)x,(int)y, 32, 32); | ||
//divisas do bloco | ||
g.setColor(Color.BLACK); | ||
g.drawRect((int)x,(int)y, 32, 32); | ||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,6 @@ public enum ObjectId { | |
ENEMY, | ||
ARMA, | ||
BALA, | ||
SOLIDO; | ||
SOLIDO, BLOCO; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.ks2002br.input; | ||
|
||
import java.awt.event.KeyAdapter; | ||
import java.awt.event.KeyEvent; | ||
|
||
import com.ks2002br.frameworks.GameController; | ||
import com.ks2002br.frameworks.GameObject; | ||
import com.ks2002br.frameworks.ObjectId; | ||
|
||
public class Teclado extends KeyAdapter { | ||
|
||
GameController gc; | ||
|
||
public Teclado(GameController gc) { | ||
this.gc = gc; | ||
} | ||
|
||
public void keyPressed(KeyEvent e) { | ||
int tecla = e.getKeyCode(); | ||
|
||
for (int i = 0; i < gc.obj.size(); i++) { | ||
|
||
GameObject objTemp = gc.obj.get(i); | ||
|
||
if (objTemp.getId() == ObjectId.PLAYER) { | ||
if (tecla == KeyEvent.VK_D) objTemp.setSpdX(5); | ||
if (tecla == KeyEvent.VK_A) objTemp.setSpdX(-5); | ||
if (tecla == KeyEvent.VK_W) objTemp.setSpdY(-5); | ||
if (tecla == KeyEvent.VK_S) objTemp.setSpdY(5); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
public void keyReleased(KeyEvent e) { | ||
int tecla = e.getKeyCode(); | ||
|
||
for (int i = 0; i < gc.obj.size(); i++) { | ||
GameObject objTemp = gc.obj.get(i); | ||
if (objTemp.getId() == ObjectId.PLAYER){ | ||
if (tecla == KeyEvent.VK_D) objTemp.setSpdX(0); | ||
if (tecla == KeyEvent.VK_A) objTemp.setSpdX(0); | ||
if (tecla == KeyEvent.VK_W) objTemp.setSpdY(0); | ||
if (tecla == KeyEvent.VK_S) objTemp.setSpdY(0); | ||
} | ||
|
||
} | ||
} | ||
|
||
} |