Author Topic: JADE - A Sneak Peek  (Read 29956 times)

Offline AIR

  • Moderator
  • Posts: 932
  • Coder
JADE - A Sneak Peek
« on: November 08, 2013, 01:40:44 PM »
Comments on the code style welcome:

Code: [Select]
#include "../jade.h"
#include "sdl2.inc"

// SCREEN DIMENSIONS
CONSTANT INT SCREEN_WIDTH = 640;
CONSTANT INT SCREEN_HEIGHT = 480;

MAIN
    DIM AS PWINDOW window = NULL;
    DIM AS PSURFACE screenSurface = NULL;
    DIM AS BOOL quit = false;
    DIM AS SDL_Event e;
   
    IF ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) THEN
        PRINT( SDL_GetError() );
    ELSE
        //Create Window
        window = SDL_CreateWindow( "SDL Simple Window",
                                    SDL_WINDOWPOS_UNDEFINED,
                                    SDL_WINDOWPOS_UNDEFINED,
                                    SCREEN_WIDTH,
                                    SCREEN_HEIGHT,
                                    SDL_WINDOW_SHOWN);
       
        IF ( window == NULL ) THEN
            PRINT( SDL_GetError() );
        ELSE
            // Get Window Surface
            screenSurface = SDL_GetWindowSurface( window );

           
            WHILE (NOT quit) BEGIN
                WHILE ( SDL_PollEvent( ADDR e) != 0 ) BEGIN
                    SELECT (e.type) BEGIN
                        CASE SDL_QUIT:
                            quit = true;
                        ENDCASE
                    ENDSELECT
                WEND
                // Fill the surface with White
                SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 255, 255, 255 ) );
                // Update the Surface
                SDL_UpdateWindowSurface( window );
           
            WEND
        ENDIF
    ENDIF
   
    //Destroy Window
    SDL_DestroyWindow( window );
   
    // Shutdown SDL
    SDL_Quit();
   
    RETURN 0;
   
END

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: JADE - A Sneak Peek
« Reply #1 on: November 08, 2013, 03:07:52 PM »
Hard to believe that is C++.  8)

kryton9

  • Guest
Re: JADE - A Sneak Peek
« Reply #2 on: November 08, 2013, 05:53:03 PM »
You know what I think, SUPERB!!!

kryton9

  • Guest
SDL Windows, MingW and Code::Blocks Users
« Reply #3 on: November 08, 2013, 11:15:10 PM »
This is for the original SDL and not SDL2.

I don't know how it is on Macs or Linux at the moment,
but in Windows you usually have your #include for SDL includes
depending on extensions you are adding as:
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_mixer.h"
#include "SDL/SDL_ttf.h"
#include "SDL/SDL_net.h"

On windows if you are using Code::Blocks and MingW
your linker settings should look like this, in the order you see it:
mingw32
SDL_net
SDL_ttf
SDL_mixer
SDL_image
SDLmain
SDL.dll
user32
gdi32
winmm
dxguid

Attached is a screenshot from one of the frames of Jade:sdl_test by AIR
« Last Edit: November 08, 2013, 11:29:22 PM by kryton9 »

Offline AIR

  • Moderator
  • Posts: 932
  • Coder
Re: SDL Windows, MingW and Code::Blocks Users
« Reply #4 on: November 08, 2013, 11:52:20 PM »
This is for the original SDL and not SDL2.

I don't know how it is on Macs or Linux at the moment,
but in Windows you usually have your #include for SDL includes
depending on extensions you are adding as:
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_mixer.h"
#include "SDL/SDL_ttf.h"
#include "SDL/SDL_net.h"

Not necessarily true, if you set up your include paths properly you don't need to preface the include files.

kryton9

  • Guest
Re: JADE - A Sneak Peek
« Reply #5 on: November 09, 2013, 12:25:17 AM »
True AIR, but in Windows you usually see it like that in all the tutorials on the web for Windows development and SDL. Just wanted to give a heads up when users using all that I listed in the Subject when they get errors.

I haven't gotten the link settings for SDL2 to work yet, as soon as I do I will put them up too.

kryton9

  • Guest
SDL2 Windows Mingw Code::Blocks users
« Reply #6 on: November 09, 2013, 12:58:28 AM »
If you use 32 bit, you need to use: i686-w64-mingw32 includes, libs and bins for SDL2.
If you use 64 bit, you need to use: x86_64-w64-mingw32 includes, libs and bins for SDL2.

Like SDL original, in Windows you are seeing this for SDL2:
#include "SDL2/SDL.h"
#include "SDL2/SDL_image.h"
#include "SDL2/SDL_mixer.h"
#include "SDL2/SDL_ttf.h"
#include "SDL2/SDL_net.h"

Linker settings as follows:
On windows if you are using Code::Blocks and MingW
your linker settings should look like this, in the order you see it:
mingw32
SDL2_net
SDL2_ttf
SDL2_mixer
SDL2_image
SDL2main
SDL2.dll
SDL2
user32
gdi32
winmm
dxguid

This is what you should see when you compile and run Jade:SDL2

kryton9

  • Guest
Re: JADE - A Sneak Peek
« Reply #7 on: November 09, 2013, 01:08:26 AM »
AIR I will make a SFML demo for Jade.

I moved from SDL1.x to SFML, but this was before SDL2 came out. I really like Laurent Gomila's programming style and his has been the nicest library I have seen yet in C++.
He documents everything really well and covers all aspects of using his libraries, from installing, setting up different IDE's etc.

When I had my gaming pc, I had a Mac OS Lion VM, Mint VM and of course my Windows 7. I broke my arm and so during that time, I wrote  a pong game so I could play something with one arm,  using SFML it cross-compiled really nicely in all three OS's.  I couldn't use Code::Blocks in Lion, just too buggy, so I compiled in XCode and it compiled fine.

I would use the pong game but being 1 handed at the time, the code is a mess to look at and I hate putting up terrible looking code.

I like your coding style too, it is like Laurent's and the way I like too. So I think SFML will make a good addition to Jade.

Anyways I will work on that and let you know when I run into errors with Jade. I do get a few warnings with both sdl demos. I will document them better tomorrow, getting too sleepy at the moment.

Thanks for Jade, it let's me use C++ without eye strain :)

kryton9

  • Guest
Re: JADE - A Sneak Peek
« Reply #8 on: November 09, 2013, 06:01:28 PM »
Air, I am getting too confused with Git and also getting things working in Code::Blocks in Windows on my local computer keeping up the project files with the repositories is confusing.

What I am going to do tonight is finish setting up my development environment in my Mint Virtual Machine and do all development on Jade for now in there.

Wow you really are moving along at an incredible pace. I see you added a lot today, thanks. I will get setup and test all the new things and report any issues from Mint development.

Once we are finished, I will then test everything in Windows.

Offline AIR

  • Moderator
  • Posts: 932
  • Coder
Re: JADE - A Sneak Peek
« Reply #9 on: November 09, 2013, 06:34:52 PM »
That's why I do everything at a command prompt, even on Windows.  Using the Git for Windows version of Bash (via sh.exe), I can even use the configure scripts that you could usually only use with *.nix operating systems.

Command Prompt and Vim (also comes with Git for Windows!) is all i need.   ;D

A.

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
JADE - AIR Pong
« Reply #10 on: November 09, 2013, 06:41:27 PM »
JADE - Ubuntu 64 bit




JADE - Android



Code: [Select]
#include "header.inc"
#include "runtime.inc"
#include "sdl2.inc"
#include <SDL.h>


MAIN
  /* Variable declarations, SDL2 initialization */
    Init(SDL_INIT_VIDEO);
    DIM AS PWINDOW window;
    DIM AS PRENDERER renderer;
    DIM AS BOOL p1_up = false;
    DIM AS BOOL p1_down = false;
    DIM AS BOOL p2_up = false;
    DIM AS BOOL p2_down = false;

    DIM AS INT p1_y = 199;
    DIM AS INT p2_y = 199;

    DIM AS INT p1_vel = 0;
    DIM AS INT p2_vel = 0;

    DIM AS BOOL quit = false;

    DIM AS INT ball_x = 639 / 2;
    DIM AS INT ball_y = 479 / 2;

    DIM AS INT ball_w = 8;
    DIM AS INT ball_h = 8;

    DIM AS INT ball_x_vel = 5;
    DIM AS INT ball_y_vel = 0;

    DIM AS INT delay = 30;

    DIM AS INT p1_score = 0;
    DIM AS INT p2_score = 0;

    DIM AS INT BALL_WIDTH = 10;
    DIM AS INT BALL_HEIGHT = 10;

    CONSTANT INT Y_MIN = 0;
    CONSTANT INT Y_MAX = 399;

    CONSTANT INT P1_X = 0;
    CONSTANT INT P2_X = 629;

    CONSTANT INT VEL_POS = 10;
    CONSTANT INT VEL_NEG = 0 - VEL_POS;

    window = CreateWindow("Pong",
                              SDL_WINDOWPOS_CENTERED,
                              SDL_WINDOWPOS_CENTERED,
                              640,
                              480,
                              SDL_WINDOW_SHOWN);

    renderer = CreateRenderer(window, -1, 0);

    PRINT("Press Q to quit.");

    /* Main Game Loop */
    WHILE (NOT quit) BEGIN
        EVENT event;

        WHILE (PollEvent(ADDR event)) BEGIN
            SELECT (event.type) BEGIN
                CASE KEYDOWN:
                    SELECT (event.key.keysym.sym) BEGIN
                        CASE SDLK_w:
                          p1_vel = VEL_NEG;
                        ENDCASE

                        CASE SDLK_s:
                          p1_vel = VEL_POS;
                        ENDCASE

                        CASE SDLK_UP:
                          p2_vel = VEL_NEG;
                        ENDCASE

                        CASE SDLK_DOWN:
                          p2_vel = VEL_POS;
                        ENDCASE

                        CASE SDLK_q:
                          quit = true;
                        ENDCASE

                        CASE SDLK_EQUALS:
                          INCR delay;
                        ENDCASE

                        CASE SDLK_MINUS:
                          IF (delay > 1) DECR delay;
                        ENDCASE

                        CASE_ELSE:
                        ENDCASE
                    ENDSELECT
                ENDCASE

                CASE KEYUP:
                    SELECT (event.key.keysym.sym) BEGIN

                        CASE SDLK_w:
                          IF (p1_vel == VEL_NEG) p1_vel = 0;
                        ENDCASE

                        CASE SDLK_s:
                          IF (p1_vel == VEL_POS) p1_vel = 0;
                        ENDCASE

                        CASE SDLK_UP:
                          IF (p2_vel == VEL_NEG) p2_vel = 0;
                        ENDCASE

                        CASE SDLK_DOWN:
                          IF (p2_vel == VEL_POS) p2_vel = 0;
                        ENDCASE

                        CASE_ELSE:
                        ENDCASE
                    ENDSELECT
                ENDCASE

                CASE_ELSE:
                ENDCASE

            ENDSELECT
        WEND

        /* Clears the screen */
        SetRenderDrawColor(renderer, 0, 0, 0, 255);
        RenderClear(renderer);
        DIM AS RECT midline = {640/2-4, 0, 9, 479};
        SetRenderDrawColor(renderer, 90, 90, 90, 255);
        RenderDrawRect(renderer, &midline);
        RenderFillRect(renderer, &midline);

        /* Manipulate paddle positions */
        p1_y = p1_y + p1_vel;
        p2_y = p2_y + p2_vel;
        IF (p1_y < Y_MIN) p1_y = Y_MIN;
        IF (p1_y > Y_MAX) p1_y = Y_MAX;
        IF (p2_y < Y_MIN) p2_y = Y_MIN;
        IF (p2_y > Y_MAX) p2_y = Y_MAX;


        /* Draw the paddles */
        SetRenderDrawColor(renderer, 255, 255, 255, 255);
        DIM AS Rect rect1 = {P1_X, p1_y, 10, 80};
        DIM AS Rect rect2 = {P2_X, p2_y, 10, 80};
        RenderDrawRect(renderer, &rect1);
        RenderDrawRect(renderer, &rect2);
        RenderFillRect(renderer, &rect1);
        RenderFillRect(renderer, &rect2);

        /* Manipulate the ball position */
        ball_x = ball_x + ball_x_vel;
        ball_y = ball_y + ball_y_vel;

        IF (ball_x + 4 >= 630 AND ball_x <= 639 AND ball_y + 4 < p2_y + 80 AND ball_y - 4 > p2_y) THEN
            ball_x_vel = -ball_x_vel;
            ball_y_vel = ball_y_vel + (ball_y - (p2_y + 40)) / 10;
            IF (ball_x_vel < 0) ball_x_vel--;
            IF (ball_x_vel > 0) ball_x_vel++;
        ENDIF

        IF (ball_x - 4 <= 9 AND ball_x >= 0 AND ball_y + 4 < p1_y + 80 AND ball_y - 4 > p1_y) THEN
            ball_x_vel = -ball_x_vel;
            ball_y_vel = ball_y_vel + (ball_y - (p1_y + 40)) / 10;
            IF (ball_x_vel < 0 AND ball_x_vel > -8) ball_x_vel--;
            IF (ball_x_vel > 0 AND ball_x_vel < 8) ball_x_vel++;
        ENDIF

        IF (ball_y - 4 <= 0 OR ball_y + 4 >= 479) THEN
          ball_y_vel = -ball_y_vel;
        ENDIF

        RenderDrawLine(renderer, ball_x, ball_y - 4, ball_x, ball_y + 4);
        RenderDrawLine(renderer, ball_x - 4, ball_y, ball_x + 4, ball_y);

        IF (ball_x < 0) THEN
          INCR p2_score;
          ball_x = 639 / 2;
          ball_y = 439 / 2;
          ball_x_vel = -6;
          ball_y_vel = 0;
          p1_y = 199;
          p2_y = 199;
        ENDIF

        IF (ball_x > 639) THEN
          INCR p1_score;
          ball_x = 639 / 2;
          ball_y = 439 / 2;
          ball_x_vel = 6;
          ball_y_vel = 0;
          p1_y = 199;
          p2_y = 199;
        ENDIF

        /* Draw everything to the screen */
        RenderPresent(renderer);

        Delay(delay);
    WEND

    Quit();
    RETURN 0;
ENDMAIN
« Last Edit: November 09, 2013, 10:07:07 PM by John »

kryton9

  • Guest
Re: JADE - A Sneak Peek
« Reply #11 on: November 09, 2013, 07:20:23 PM »
@Air, Vim will be too much to learn. I installed SciTe, I am familiar with it from using oxgenBasic. It is a nice GUI based, small but powerful text editor.

@John, did you compile for Android using C for Android?

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: JADE - A Sneak Peek
« Reply #12 on: November 09, 2013, 07:23:16 PM »
Quote
@John, did you compile for Android using C for Android?

C4droid + SDL2

Offline AIR

  • Moderator
  • Posts: 932
  • Coder
Re: JADE - A Sneak Peek
« Reply #13 on: November 09, 2013, 07:29:57 PM »
@Air, Vim will be too much to learn. I installed SciTe, I am familiar with it from using oxgenBasic. It is a nice GUI based, small but powerful text editor.

Vim isn't only commandline, there's gVim for both Windows and Linux.  A Windows Portable version can be found at: http://portableapps.com/apps/development/gvim_portable


That site has a bunch of other portable stuff that I run off of thumb drives, so all my apps/data are with me anywhere.

SciTe I used back when I was working on the Hotbasic Linux port.  I still use it on Windows when occasionally coding stuff in AutoIT3.

You might want to take a look at Geany (Portable Apps has that too, I have it on my thumb drive), which is a much more complete editor.

A.


Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: JADE - A Sneak Peek
« Reply #14 on: November 09, 2013, 07:35:52 PM »
I use Ultra Edit for both Windows & Wine. gedit gets used for casual text editing and when in a console only environment, vi comes through.