#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
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"
#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
@John, did you compile for Android using C for Android?
@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.
I was looking at Geany, but it setup project files also, at least in the screenshots I looked through.
I was looking at Geany, but it setup project files also, at least in the screenshots I looked through.
I don't use Project files in Geany. See attached screenshot to see how I use it.
So if you don't want to use them, you don't have to. Normal C++ syntax will work as well.
#!/bin/bash
FILES=(http://libsdl.org/release/SDL2-2.0.1.tar.gz
http://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.0.tar.gz
http://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.0.tar.gz
http://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.12.tar.gz)
for FILE in ${FILES[@]};do
FNAME=$(basename $FILE)
echo "Downloading "$FNAME
wget $FILE
echo "Unpacking "$FNAME
tar xzvf $FNAME
FOLDER=${FNAME%.tar.*}
echo "Changing to "$FOLDER "And Compiling"
pushd $FOLDER
./configure && make && sudo make install
popd
echo
done
I'm a worrier and I know it is early in the adventure, but I think we need to nail down a name, because this project is really flying along and it is going to be something that a lot of people are going to find very interesting.
I like the name Jade, but there is another programming language by that name and usually when you see programming languages with a J, you think of Java and/or some port from or to Java.
I thought Air++ would be cool, but searching tonight I came across Adobe AIR and a presentation about Adobe AIR++.
Clean is already taken. a search for Clear, came out OK and so did Clear++
Remember, this was originally supposed to be a way for BASIC programmers to slide over to C/C++.That is all well and good, but now that we have been experimenting we have opened a door to many things. What about the people that use python, lua, and ruby, they are probably more in number than old basic users. And what about new people coming to c/c++, Jade has shown that we can offer wrappers for all of these folks.
Name your forks what you like, I'm sticking with JADE.
g++ -Os fltkdemo.cpp -I /c/Users/arivera1271/FLTK-WIN32/include/ -L /c/
Users/arivera1271/FLTK-WIN32/lib/ -lfltk -mwindows -lole32 -luuid -lcomctl32 -o fltkdemo-win
Don't use guilt by association as a reason to not try it, because AIR is one outstanding coder.
Didn't JRS start something like that a while ago? IIRC he abandoned it because he couldn't get it to work properly or some such.
Hello World
This is
JADE
splitting strings
using multiple delimiters
Just
for
you
[riveraa@MPD /Users/Shared/src/Jade] $ g++ -std=c++11 split-test.cpp -o split-test
[riveraa@MPD /Users/Shared/src/Jade] $ ./split-test
Hello World
JADE
splitting
using
delimiters
Just-for-you
20
04
22
24
2018