Add pause menu and main menu
BIN
assets/continue.bmp
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
assets/continuesel.bmp
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
assets/exit.bmp
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
assets/exitsel.bmp
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
assets/menu.bmp
Normal file
After Width: | Height: | Size: 506 KiB |
BIN
assets/pause.bmp
Normal file
After Width: | Height: | Size: 506 KiB |
BIN
assets/start.bmp
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
assets/startsel.bmp
Normal file
After Width: | Height: | Size: 44 KiB |
@ -31,7 +31,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
Render.init();
|
Render.init();
|
||||||
Screen.init();
|
Screen.init();
|
||||||
scenes.push(new Game());
|
scenes.push(new MainMenu());
|
||||||
|
|
||||||
while(!scenes.empty() && !exit){
|
while(!scenes.empty() && !exit){
|
||||||
Time.Tick();
|
Time.Tick();
|
||||||
|
@ -44,7 +44,7 @@ public class Render {
|
|||||||
WIDTH, HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
|
WIDTH, HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
|
||||||
|
|
||||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
|
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
|
||||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
|
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
|
||||||
|
|
||||||
renderer =
|
renderer =
|
||||||
SDL_CreateRenderer(Render.window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
SDL_CreateRenderer(Render.window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||||
|
@ -25,21 +25,19 @@ import static org.libsdl.api.event.SdlEvents.*;
|
|||||||
import static com.fmudanyali.Render.*;
|
import static com.fmudanyali.Render.*;
|
||||||
import static org.libsdl.api.keycode.SDL_Keycode.*;
|
import static org.libsdl.api.keycode.SDL_Keycode.*;
|
||||||
import static org.libsdl.api.render.SdlRender.*;
|
import static org.libsdl.api.render.SdlRender.*;
|
||||||
import static org.libsdl.api.error.SdlError.SDL_GetError;
|
//import static org.libsdl.api.error.SdlError.SDL_GetError;
|
||||||
|
|
||||||
public class Game extends Scene {
|
public class Game extends Scene {
|
||||||
public static boolean exit = false;
|
|
||||||
public static boolean escPressed = false;
|
public static boolean escPressed = false;
|
||||||
public int kek = 0;
|
int kek = 0;
|
||||||
|
private Player player = new Player();
|
||||||
public Player player = new Player();
|
|
||||||
|
|
||||||
public Game() throws Exception{
|
public Game() throws Exception{
|
||||||
Screen.makeBackground("scene1/tile.bmp");
|
Screen.makeBackground("scene1/tile.bmp");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loop(){
|
public void loop() throws Exception{
|
||||||
while(SDL_PollEvent(Main.e) != 0){
|
while(SDL_PollEvent(Main.e) != 0){
|
||||||
switch(Main.e.type){
|
switch(Main.e.type){
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
@ -67,13 +65,11 @@ public class Game extends Scene {
|
|||||||
|
|
||||||
player.movement();
|
player.movement();
|
||||||
Screen.scroll();
|
Screen.scroll();
|
||||||
/*
|
|
||||||
++kek;
|
++kek;
|
||||||
if(kek == 60){
|
if(kek == 60){
|
||||||
System.out.println(SDL_GetError());
|
System.out.println(escPressed);
|
||||||
kek = 0;
|
kek = 0;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
SDL_RenderCopy(renderer, Screen.wallpaper, null, null);
|
SDL_RenderCopy(renderer, Screen.wallpaper, null, null);
|
||||||
|
@ -17,6 +17,128 @@
|
|||||||
|
|
||||||
package com.fmudanyali.scenes;
|
package com.fmudanyali.scenes;
|
||||||
|
|
||||||
|
import com.fmudanyali.Main;
|
||||||
|
import com.fmudanyali.Screen;
|
||||||
|
import com.fmudanyali.FileLoader;
|
||||||
|
|
||||||
|
import org.libsdl.api.rect.SDL_Rect;
|
||||||
|
import org.libsdl.api.render.*;
|
||||||
|
import org.libsdl.api.surface.SDL_Surface;
|
||||||
|
|
||||||
|
import static com.fmudanyali.Render.*;
|
||||||
|
import static org.libsdl.api.render.SdlRender.*;
|
||||||
|
import static org.libsdl.api.surface.SdlSurface.*;
|
||||||
|
import static org.libsdl.api.event.SdlEvents.*;
|
||||||
|
import static org.libsdl.api.keycode.SDL_Keycode.*;
|
||||||
|
|
||||||
public class MainMenu extends Scene {
|
public class MainMenu extends Scene {
|
||||||
public void loop(){};
|
private SDL_Surface tempSurface;
|
||||||
|
private SDL_Texture startTexture, exitTexture, background;
|
||||||
|
private SDL_Rect startPos = new SDL_Rect();
|
||||||
|
private SDL_Rect exitPos = new SDL_Rect();
|
||||||
|
private SDL_Rect buttonSize = new SDL_Rect();
|
||||||
|
private boolean enterPressed = false;
|
||||||
|
private boolean wPressed = false;
|
||||||
|
private boolean sPressed = false;
|
||||||
|
private int selection = 0;
|
||||||
|
|
||||||
|
public MainMenu() throws Exception{
|
||||||
|
buttonSize.x = buttonSize.y = 0;
|
||||||
|
buttonSize.w = startPos.w = exitPos.w = 150;
|
||||||
|
buttonSize.h = startPos.h = exitPos.h = 100;
|
||||||
|
startPos.x = (Screen.WIDTH - Screen.CANV_W)/2 + 10;
|
||||||
|
startPos.y = (Screen.HEIGHT - Screen.CANV_H)/2 + 10;
|
||||||
|
exitPos.x = (Screen.WIDTH - Screen.CANV_W)/2 + 10;
|
||||||
|
exitPos.y = (Screen.HEIGHT - Screen.CANV_H)/2 + 120;
|
||||||
|
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("menu.bmp"));
|
||||||
|
background = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("startsel.bmp"));
|
||||||
|
startTexture = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("exit.bmp"));
|
||||||
|
exitTexture = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loop() throws Exception{
|
||||||
|
while(SDL_PollEvent(Main.e) != 0){
|
||||||
|
switch(Main.e.type){
|
||||||
|
case SDL_QUIT:
|
||||||
|
Main.exit = true;
|
||||||
|
break;
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
switch(Main.e.key.keysym.sym){
|
||||||
|
case SDLK_RETURN:
|
||||||
|
if(!enterPressed){
|
||||||
|
confirm();
|
||||||
|
enterPressed = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDLK_w:
|
||||||
|
if(!wPressed){
|
||||||
|
selection = Math.min(selection - 1, 1);
|
||||||
|
wPressed = true;
|
||||||
|
updateButtons();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDLK_s:
|
||||||
|
if(!sPressed){
|
||||||
|
selection = Math.min(selection + 1, 1);
|
||||||
|
sPressed = true;
|
||||||
|
updateButtons();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDL_KEYUP:
|
||||||
|
switch(Main.e.key.keysym.sym){
|
||||||
|
case SDLK_RETURN:
|
||||||
|
enterPressed = false;
|
||||||
|
break;
|
||||||
|
case SDLK_w:
|
||||||
|
wPressed = false;
|
||||||
|
break;
|
||||||
|
case SDLK_s:
|
||||||
|
sPressed = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
SDL_RenderCopy(renderer, Screen.wallpaper, null, null);
|
||||||
|
SDL_RenderCopy(renderer, background, Screen.canvas, Screen.canvasPos);
|
||||||
|
SDL_RenderCopy(renderer, startTexture, buttonSize, startPos);
|
||||||
|
SDL_RenderCopy(renderer, exitTexture, buttonSize, exitPos);
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateButtons() throws Exception{
|
||||||
|
switch(selection){
|
||||||
|
case 0:
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("startsel.bmp"));
|
||||||
|
startTexture = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("exit.bmp"));
|
||||||
|
exitTexture = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("start.bmp"));
|
||||||
|
startTexture = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("exitsel.bmp"));
|
||||||
|
exitTexture = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void confirm() throws Exception{
|
||||||
|
switch(selection){
|
||||||
|
case 0:
|
||||||
|
Main.scenes.push(new Game());
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Main.scenes.pop();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,9 @@ package com.fmudanyali.scenes;
|
|||||||
|
|
||||||
import com.fmudanyali.Main;
|
import com.fmudanyali.Main;
|
||||||
import com.fmudanyali.Screen;
|
import com.fmudanyali.Screen;
|
||||||
|
import com.fmudanyali.FileLoader;
|
||||||
|
|
||||||
|
import org.libsdl.api.rect.SDL_Rect;
|
||||||
import org.libsdl.api.render.*;
|
import org.libsdl.api.render.*;
|
||||||
import org.libsdl.api.surface.SDL_Surface;
|
import org.libsdl.api.surface.SDL_Surface;
|
||||||
|
|
||||||
@ -30,18 +32,36 @@ import static org.libsdl.api.event.SdlEvents.*;
|
|||||||
import static org.libsdl.api.keycode.SDL_Keycode.*;
|
import static org.libsdl.api.keycode.SDL_Keycode.*;
|
||||||
|
|
||||||
public class PauseMenu extends Scene {
|
public class PauseMenu extends Scene {
|
||||||
public static SDL_Surface textureSurface =
|
private SDL_Surface tempSurface;
|
||||||
SDL_CreateRGBSurface(0, Screen.WIDTH, Screen.HEIGHT, 32, 0, 0, 0, 0);
|
private SDL_Texture contTexture, exitTexture, background;
|
||||||
public static SDL_Texture menuTexture;
|
private SDL_Rect contPos = new SDL_Rect();
|
||||||
public static boolean escPressed = false;
|
private SDL_Rect exitPos = new SDL_Rect();
|
||||||
|
private SDL_Rect buttonSize = new SDL_Rect();
|
||||||
|
private boolean escPressed = false;
|
||||||
|
private boolean enterPressed = false;
|
||||||
|
private boolean wPressed = false;
|
||||||
|
private boolean sPressed = false;
|
||||||
|
private int selection = 0;
|
||||||
|
|
||||||
public PauseMenu(){
|
public PauseMenu() throws Exception{
|
||||||
SDL_FillRect(textureSurface, null, 0);
|
buttonSize.x = buttonSize.y = 0;
|
||||||
menuTexture = SDL_CreateTextureFromSurface(renderer, textureSurface);
|
buttonSize.w = contPos.w = exitPos.w = 150;
|
||||||
|
buttonSize.h = contPos.h = exitPos.h = 100;
|
||||||
|
contPos.x = (Screen.WIDTH - Screen.CANV_W)/2 + 10;
|
||||||
|
contPos.y = (Screen.HEIGHT - Screen.CANV_H)/2 + 10;
|
||||||
|
exitPos.x = (Screen.WIDTH - Screen.CANV_W)/2 + 10;
|
||||||
|
exitPos.y = (Screen.HEIGHT - Screen.CANV_H)/2 + 120;
|
||||||
|
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("pause.bmp"));
|
||||||
|
background = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("continuesel.bmp"));
|
||||||
|
contTexture = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("exit.bmp"));
|
||||||
|
exitTexture = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loop(){
|
public void loop() throws Exception{
|
||||||
while(SDL_PollEvent(Main.e) != 0){
|
while(SDL_PollEvent(Main.e) != 0){
|
||||||
switch(Main.e.type){
|
switch(Main.e.type){
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
@ -55,6 +75,26 @@ public class PauseMenu extends Scene {
|
|||||||
escPressed = true;
|
escPressed = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SDLK_RETURN:
|
||||||
|
if(!enterPressed){
|
||||||
|
confirm();
|
||||||
|
enterPressed = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDLK_w:
|
||||||
|
if(!wPressed){
|
||||||
|
selection = Math.min(selection - 1, 1);
|
||||||
|
wPressed = true;
|
||||||
|
updateButtons();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDLK_s:
|
||||||
|
if(!sPressed){
|
||||||
|
selection = Math.min(selection + 1, 1);
|
||||||
|
sPressed = true;
|
||||||
|
updateButtons();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
@ -62,13 +102,55 @@ public class PauseMenu extends Scene {
|
|||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
escPressed = false;
|
escPressed = false;
|
||||||
break;
|
break;
|
||||||
|
case SDLK_RETURN:
|
||||||
|
enterPressed = false;
|
||||||
|
break;
|
||||||
|
case SDLK_w:
|
||||||
|
wPressed = false;
|
||||||
|
break;
|
||||||
|
case SDLK_s:
|
||||||
|
sPressed = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
SDL_RenderCopy(renderer, menuTexture, null, null);
|
SDL_RenderCopy(renderer, Screen.wallpaper, null, null);
|
||||||
|
SDL_RenderCopy(renderer, background, Screen.canvas, Screen.canvasPos);
|
||||||
|
SDL_RenderCopy(renderer, contTexture, buttonSize, contPos);
|
||||||
|
SDL_RenderCopy(renderer, exitTexture, buttonSize, exitPos);
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateButtons() throws Exception{
|
||||||
|
switch(selection){
|
||||||
|
case 0:
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("continuesel.bmp"));
|
||||||
|
contTexture = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("exit.bmp"));
|
||||||
|
exitTexture = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("continue.bmp"));
|
||||||
|
contTexture = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
|
tempSurface = SDL_LoadBMP(FileLoader.getFilePath("exitsel.bmp"));
|
||||||
|
exitTexture = SDL_CreateTextureFromSurface(renderer, tempSurface);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void confirm(){
|
||||||
|
switch(selection){
|
||||||
|
case 0:
|
||||||
|
Main.scenes.pop();
|
||||||
|
Game.escPressed = false;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
Main.scenes.pop();
|
||||||
|
Main.scenes.pop();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,5 +18,5 @@
|
|||||||
package com.fmudanyali.scenes;
|
package com.fmudanyali.scenes;
|
||||||
|
|
||||||
public abstract class Scene {
|
public abstract class Scene {
|
||||||
public abstract void loop();
|
public abstract void loop() throws Exception;
|
||||||
}
|
}
|