Mintoris Forum

Author Topic: OpenGL Game Engine  (Read 52628 times)

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #20 on: Jan 24, 2016, 10:26 PM »
I'm in the process of adding a set of 27 commands that control the most basic aspects of sprites. This is about a quarter of the sprite commands. It will probably be another day before these commands are finished and I have a test version of Basic ready to send out. I see weeks of work ahead.

GenSetSpriteType sprite, type

GenSetSpriteTile sprite, tile

GenSetSpriteRed sprite, red
GenSetSpriteGreen sprite, green
GenSetSpriteBlue sprite, blue
GenSetSpriteAlpha sprite, alpha
GenSetSpriteColor sprite, red, green, blue {, alpha}

GenSpriteRotate sprite, degrees
GenSetSpriteRotation sprite, degrees
GenSetSpritePivotPoint sprite, pivotX, pivotY
GenSetSpriteRotateByDir sprite, On | Off

GenSetSpriteScale sprite, scaleX, scaleY
GenSetSpriteScaleX sprite, scaleX
GenSetSpriteScaleY sprite, scaleY

GenSetSpriteX sprite, x
GenSetSpriteY sprite, y
GenSetSpriteXY sprite, x, y

GenSetSpriteCenterX sprite, x
GenSetSpriteCenterY sprite, y
GenSetSpriteCenterXY sprite, x, y

GenSetSpritePivotX sprite, x
GenSetSpritePivotY sprite, y
GenSetSpritePivotXY sprite, x, y

GenSetSpriteCenterOn sprite, centerOnSprite

GenMoveSpriteX sprite, x
GenMoveSpriteY sprite, y
GenMoveSpriteXY sprite, x, y

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #21 on: Jan 25, 2016, 02:29 AM »
Hey Chuck, just curious about the move sprite command, you have x and y movement which leads me to believe this movement isn't based on the sprite angle. I would like a command to move the sprite in the direction it's facing. so it would just be:
Genmovesprite s#,distance.
So if the sprite rotation is zero, then it moves up, 45 up and to the right,90 to the right and so on, wherever it is facing.
« Last Edit: Jan 25, 2016, 03:15 AM by rasdini »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #22 on: Jan 25, 2016, 02:44 AM »
These are just the most basic commands. I decided to break them into groups because it is really tedious to add large blocks of commands at one time without testing. The next set of commands includes movement by angle/distance. Plus, you can set a sprite's velocity, acceleration and terminal velocity. All directly or by angle/velocity.

Then there is the tile animation commands. I would like to expand the existing tile animation commands to include different sets of animation sequences. One set might be your normal animation, another might be an explosion animation. What we really need is some sort of animation scripting code. Maybe a text string which combines tile numbers, loops, delays and jumps to other animation sequences. I could use some help on that.

« Last Edit: Aug 08, 2016, 06:30 PM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #23 on: Jan 25, 2016, 03:47 AM »
I can't even figure out how to compile my programs into apk's, I don't think I'll be much help when it comes to coding and packing this stuff, that seems to be your expertise. I hope you are asking for help with commands. That I can help with extensively. As far as architecture, I can help to a certain degree aiding you in figuring out what should be where. I know I suggested that the sprite info be updated by the engine every pass through the interrupt. The game engine can handle it in the blink of an eye. Are you using c++ or similar? I could write pockets of code for handling the sprite data or just produce detailed flow charts for you to code from. There are lots of ways I could be of assistance, as well as help with testing the updates.
I believe SpriteCollision commands would be the way to go if we can set up and interrupt to check the results instantly, then return to mintoris
So if we use the command in mintoris:
if SpriteCollision(1,2)=1 then
  process collision here
endif
so [spritecollision(s1,s2)] could be the game engines call to determine if the collision is true or false.
it could be structured
b=spritecollision (2,9) 'is sprite 2 and sprite 9 colliding?
yes, b=1
no, b=0
if we place a zero, then it returns the sprite number your object sprite is colliding with.
b=spritecollision (5,0)
if sprite 5 is not colliding with a sprite the 0 is returned or b=0
if sprite 5 is colliding with sprite 3 let's say, then 3 is returned or b=3
or the direct approach
if spritecollision(5,0)=3 then
  blah blah blah
endif

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #24 on: Jan 25, 2016, 03:58 AM »
Yeah, I can handle all the details under the hood. Just keep an eye out and let me know if something is missing. Everything is written in Java.

Interrupts (if I can get them working) will turn everything around.

They're going to work something like this:

GenOnSpriteCollision sprite, MySpriteCollisionSub


Sub MySpriteCollisionSub(sprite1, sprite2)

  Process collision between sprite1 and sprite2

End Sub


If all the interrupts I want work, there won't be much for the main loop to do but wait for the game to end. Oh, the game engine uses a clever collision detection method that can keep track of all 500 sprites with very, very little overhead. It took me a long time to think of it and I'm gunna keep the details secret.  ;D
« Last Edit: Jan 25, 2016, 04:20 AM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #25 on: Jan 25, 2016, 06:05 AM »
I started coding in Machine language when I was in the 6th grade circa 1977. I have no problem visualizing the code necessary to accomplish the collision detection, just not what I want to concern myself with. No doubt your approach is much better than anything I would come up with anyway. I never took the time to learn Java. Suppose I should have. I don't particularly like the idea of having subs for collision. it takes an extra step and more coding in basic. would be nice to be able to check the collision in one command. This way, I can use different variables all over the place. check out the collision suggestions I just gave a bit ago. The command I suggested for spritecollision would be excellent to use multiple ways.
hit=spritecollision(sp1,sp2) '0=no,1=yes
                 or
if spritecollision(sp1,sp2)=1 then
  sprite 1 and sprite 2 are colliding
  action
endif
               plus
col=spritecollision(3,0) 'returns number of the sprite that sprite 3 is colliding with.
It almost seems that you are trying to run gameengine syncronously with mintoris basic, when asynchronous may be a better option. I don't know. Let me know what you think.


Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #26 on: Jan 25, 2016, 06:08 AM »
Your collision sub may just set a global variable that you can test elsewhere in your program.

And, yes I am trying to run the game engine synchronously with Basic.
« Last Edit: Jan 25, 2016, 06:22 AM by Chuck »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #27 on: Jan 26, 2016, 01:55 AM »
It almost seems that you are trying to run gameengine syncronously with mintoris basic, when asynchronous may be a better option. I don't know. Let me know what you think.

I've been thinking about this all day as I finished adding those 27 commands. I think event driven is the way to go. Think about 100 different object on the screen at one time (Like in Space). It would take (100 x 100 - 100) if statements to check each collision. But if you have a sub that is only called when things actually collide, then you have fairly few hits per second to process. Remember that these sprites will be moving around the screen on their own. Collisions need to be checked every frame at 60 fps.

The most features at the max speed.
« Last Edit: Jan 26, 2016, 01:59 AM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #28 on: Jan 26, 2016, 02:38 AM »
I think creating the sprite should be a simple matter of specifying the sprite number,image to be used and how it's divided on the x and y. so something like:
GenMakeAnimatedSprite sprite#,image,xsegment,ysegment

that's it, sprite is ready for use with commands like:
PlaySprite sprite#,speed, [startframe,endframe]  ' if startframe endframe is left out then animation will play all images from 1 to the last image.

RotateSprite sprite#,angle (0-360)

MoveSprite sprite#,distance

TurnSpriteLeft sprite#,degrees to turn

TurnSpriteRight sprite#,degrees to turn

StopSprite sprite#

SetSpriteFrame sprite#,frame#

I'll keep working on it. Let me know what you think so far. I would like to know.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #29 on: Jan 26, 2016, 03:02 AM »
Well, I'm going to keep porting the game engine along the existing lines. I'm just mirroring the functions that already exist in the engine. Don't worry it's gunna be really cool. You just have to look at Mintoris Space to see the level of graphics i'm expecting. I can add any reasonable command requests after I get the existing functions mapped to commands.
« Last Edit: Jan 26, 2016, 05:34 AM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #30 on: Jan 26, 2016, 12:31 PM »
Space is really cool. Nicely done‼ Is there going to be a CloneSprite command?

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #31 on: Jan 26, 2016, 03:54 PM »
Space is really cool. Nicely done‼ Is there going to be a CloneSprite command?

Thanks, and yes.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #32 on: Jan 26, 2016, 08:56 PM »
We are really very close on how we want sprites to work. I think it's just that I'm adding more functions than you will want to use. I'm trying to make the implementation as broad as possible.

I think the main difference is that you want to reference sprites by a number and I've implemented them as a type of object variable. Being able to manipulate arrays of sprite object references will be very useful.

I know once I finish with the language additions I'll have to write a Basic program that will provide a framework for game programming. As I work on this upgrade I'm forming an idea of how Basic game programs should be written.
« Last Edit: Jan 26, 2016, 08:58 PM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #33 on: Jan 26, 2016, 09:57 PM »
I like sprite numbers because then sprite 1 would be my ship, 2 my shields, 10 to 30 my enemies and so on. But I'm sure I can make it work.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #34 on: Jan 26, 2016, 10:40 PM »
Well, you could have an array of sprites where sprite(1) is your ship and sprite(2) are the shields. But for shields you can just say

GenSetSpriteCenterOn shieldSprite, shipSprite


Then the shields would automatically stay centered on the shipSprite.

You would then use the sprite visibility command to turn the shields on and off.

GenSetSpriteVisible shieldSprite, On | Off

Below is my current test program. Right now it just tests basic functionality. If anyone is interested in testing, please send an email to support@mintoris.com.

-Chuck

« Last Edit: Jan 26, 2016, 10:42 PM by Chuck »

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #35 on: Jan 27, 2016, 12:19 AM »
Here are the commands I will be adding next.

GenMoveSprite sprite, distance{, angle}

GenSetSpriteVelocityX sprite, vx
GenSetSpriteVelocityY sprite, vy
GenSetSpriteVelocityXY sprite, vx, vy
GenSetSpriteVelocity sprite, Velocity{, angle}

GenSetSpriteAccelerationXY sprite, accelX, accelY
GenSetSpriteAcceleration sprite, acceleration, angle

GenAccelerateSpriteXY sprite, accelX, accelY
GenAccelerateSprite sprite, acceleration, angle

GenSetSpriteTerminalVelocity sprite, velocity

GenSetSpriteTexture sprite, texture

GenRemoveSprite sprite
GenReviveSprite sprite
GenResetSprite sprite

GenSetSpriteVisible sprite, On | Off

GenAnimateSprite sprite, startTile, endTile, msDelay (, loops, finalTile }
GenAnimateSpriteRandom sprite, startTile, endTile, msDelay
GenAnimateSpriteCustom  sprite, tileArray(), msDelay (, loops, finalTile }

GenStopSpriteAnimation sprite

GenLoadSpriteState sprite, loadCode$

« Last Edit: Jan 27, 2016, 02:08 AM by Chuck »

rasdini

  • Sr. Member
  • ****
  • Posts: 111
Re: OpenGL Game Engine
« Reply #36 on: Jan 27, 2016, 04:56 PM »
Let me know when the next set of commands is available. I can start testing as there are useful commands now.  Will need collision soon so I can start testing the speed difference.

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #37 on: Jan 27, 2016, 09:08 PM »
Which looks better?

GenMoveSprite sprite, distance{, angle}

or

genMoveSprite sprite, distance{, angle}

sraffens

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 220
Re: OpenGL Game Engine
« Reply #38 on: Jan 27, 2016, 09:14 PM »
GenMoveSprite sprite, distance{, angle}

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Re: OpenGL Game Engine
« Reply #39 on: Jan 27, 2016, 11:55 PM »
So, testers, touch will be working in today's build.