Provides a screen to draw pixels to with a basic rendering update loop and accepts user input
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
PixelEngine/src/sig/JavaProjectTemplate.java

127 lines
3.5 KiB

package sig;
import sig.engine.AnimatedSprite;
import sig.engine.Color;
import sig.engine.Font;
import sig.engine.Key;
import sig.engine.Mouse;
import sig.engine.MouseScrollValue;
import sig.engine.Panel;
import sig.engine.Point;
import sig.engine.Sprite;
import sig.engine.Transform;
import sig.engine.PolygonStructure;
import java.awt.event.KeyEvent;
import java.util.List;
class Player{
AnimatedSprite spr=new AnimatedSprite("player.png",32,32);
double x=200,y=200;
double animationFrame=0;
double animationSpd=2; //Animation Speed will be 2 frames per second
}
public class JavaProjectTemplate {
public static final String PROGRAM_NAME="Sig's Java Project Template";
public static int WINDOW_WIDTH=1280;
public static int WINDOW_HEIGHT=720;
public static Panel game;
Player pl = new Player();
Sprite bookSpr = new Sprite("book.png");
public void initializeGame(){
//Initialize your game here.
game.Cursor_SetCursor(new Sprite("cursor.png"),0,0);
}
public void updateGame(double fElapsedTime) {
//Put game update logic in here.
//Player sprite will animate.
pl.animationFrame+=pl.animationSpd*fElapsedTime;
//Allow player movement using WASD keys.
if (Key.isHeld(KeyEvent.VK_A)) {
pl.x-=200*fElapsedTime;
}
if (Key.isHeld(KeyEvent.VK_D)) {
pl.x+=200*fElapsedTime;
}
if (Key.isHeld(KeyEvent.VK_W)) {
pl.y-=200*fElapsedTime;
}
if (Key.isHeld(KeyEvent.VK_S)) {
pl.y+=200*fElapsedTime;
}
if (Mouse.isPressed(2)) { //If middle click is pressed, reset the player position.
pl.x=pl.y=200;
}
if (Mouse.mouseWheel==MouseScrollValue.UP) {
System.out.println("Scroll up!");
}
if (Mouse.mouseWheel==MouseScrollValue.DOWN) {
System.out.println("Scroll down!");
}
if (Mouse.isPressed(3)) {
if (game.Cursor_IsVisible()) {
game.Cursor_Hide();
} else {
game.Cursor_Show();
}
}
}
public void drawGame() {
//Put rendering logic in here.
game.Clear(Color.BRIGHT_BLUE); //Clear the screen so all pixels from the previous frame are removed.
game.Draw(100,20,Color.BLACK); //That's not a dead pixel, it's a black one!
game.Draw_Line(10,10,35,35,Color.BLACK); //Line Drawing
game.FillCircle(WINDOW_WIDTH/2, WINDOW_HEIGHT/2, 100, Color.BLACK);
game.Draw_Sprite(450,75,bookSpr,Color.GREEN); //Sprite drawing (with green tint)
game.Draw_Sprite(450,75+bookSpr.getHeight(),bookSpr,Transform.VERTICAL); //Sprite drawing with vertical flip
game.Draw_Animated_Sprite(pl.x,pl.y,pl.spr,pl.animationFrame); //Animated Sprite drawing
game.Draw_Text(10,40,"Mouse X: "+Mouse.x+" Mouse Y:"+Mouse.y,Font.PROFONT_12); //Draw Mouse coordinates in tiny font
game.Draw_Text_Ext(10,52,"Hello World 2!",Font.PROFONT_36,Color.MAGENTA); //Draw in larger font
game.Fill_Triangle(160,160,190,190,50,250,new Color(255,0,0,150)); //Draw a translucent colored triangle
game.FillTexturedPolygon( //Define the uv tex coords of a polygon and a sprite and draw a texture onto it
List.of(
new Point<Double>(600d,400d),
new Point<Double>(600d,550d),
new Point<Double>(750d,550d),
new Point<Double>(750d,0d)
),
List.of(
new Point<Double>(0d,0d),
new Point<Double>(0d,1d),
new Point<Double>(1d,1d),
new Point<Double>(1d,0d)
),
List.of(
new Color(0,0,0,255),
Color.WHITE,
Color.RED,
Color.WHITE
), bookSpr, PolygonStructure.FAN);
}
public static void main(String[] args) {
JavaProjectTemplate gameInstance=new JavaProjectTemplate();
Panel.InitializeEngine(gameInstance);
}
}