Is it possible to make this game

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

salman.r1BUSYiYh
Posts: 24
Joined: Fri Sep 28, 2012 9:38 pm

Is it possible to make this game

Post by salman.r1BUSYiYh » Sat Oct 13, 2012 2:24 am

Hi guys
I have an idea on a game similar to Angry Bird however instead of birds it is a ball and instead of the angry birds style launch, I want to use swiping launch, where the person playing swipes the ball in the direction they want the ball to go. so regarding livecode i have a few questions as im a newbie to this

1) is it posible to make this game
2) roughly how long will it take (considering i just began learning) as i have set myself a deadline of march

thanks

NOTE THE GAME WILL CONCIST OF ABWT 10-15 STAGES

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Is it possible to make this game

Post by dave_probertGA6e24 » Sat Oct 13, 2012 10:04 am

Hi,

There is not enough info in your description to tell how long it would take you to develop :) But I would guess that somewhere in the region of a few weeks or a year is likely - can't get more precise than that. If you don't lose interest due to 'problems' then you should be able to make your deadline (or even beat it).

To do the swipe thing is quite simple, though not too obvious initially.

You will need to handle a mouse (finger) down on the 'ball', then grab the position and time of the first mousemove event. Now you can do a couple of options: Either wait until mouseup happens and grab the time and position of that, or you grab the position after a specific time has passed (eg. 20 milliseconds).

Then you need to do a couple of calculations on the results. Figure out the difference between the two positions (large minus small), and the direction/angle (hint: line equation: y=mx+c (google it)) and, if needed, figure out the time difference.

Once you have the distance the finger has travelled and the time you can work out the speed (v=d/t (again google it)) at launch. All you need to do then is have the ball move at that speed and apply some deceleration, gravity or friction to slow it down, so that it stops at some point.

You will probably want to 'bounce' the 'ball' off things too. For that it would be best to do some research into basic 2D game physics - there are lots of websites out there for this (look for ones that work with pseudocode as opposed to any specific programming language - these will be easier to translate to Livecode.

It would be best to get the ball movement code in place before worrying about levels, sound effects, etc so that you have the core game tool ready. After that it should just be messing around with the graphics and gameplay stuff.

Hope that helps a bit,

Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

salman.r1BUSYiYh
Posts: 24
Joined: Fri Sep 28, 2012 9:38 pm

Re: Is it possible to make this game

Post by salman.r1BUSYiYh » Sat Oct 13, 2012 4:11 pm

thanks very much for the info, much appreciated :)


ill explain the game further:
in detail the game will have a character with a ball in his/her hand (he/she will be stood on a pavement) and then upon the swipe of the user the aim of the game is for the ball to fall on the curb of a pavement (so in scripting terms the target is the rectangular 90 degrees angle and i believe this can be achieved by collision detection). if it hits the target the user gets 1 point. in between the users pavement and the opposing pavement will be obstacles going up and down hence if the ball hits the obstacle then it will come back to him/her and if he/she misses the target then the ball rolls off the screen.

im still in lumber whether to make it a two player game i.e you vs the computer because you would need to do Artificial intelligence on the computers side, would implementing AI be doable since i have a deadline i.e. is it as simple as implementing the swipe action you stated before?

the only reason i want it to get done quickly is because im doing this for my project in university and if the project was only based on development then i would have take my time but i have to do alot of research work when i mean alot i mean alot! and i have to give equal time to other modules as well lol so thats why im a bit scared :?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Is it possible to make this game

Post by sturgis » Sat Oct 13, 2012 4:36 pm

If you do as dave says and take the start point of the swipe, and the end point of the swipe you can use a function like this to get a vector

Code: Select all

-- px and py are the x and y coords of the start of the swipe.  px2 and py2 are the end points of the swipe
function pointsToVec px,py,px2,py2
-- this returns the vector for x and the vector for y seperated by comma (x,y) 
   return px2-px,py2-py
end pointsToVec
Once you have this you can do all sorts of things, for example, to get the angle of the vector in degrees

Code: Select all

-- pass in vector for x and vector for y from prev function. 
function vToDegrees vX, vY
   return atan2(vx,vy) * 180/pi
end vToDegrees
Other things you can do.. As dave said you can get velocity by measuring time between start and release. If you are accounting for gravity (check out the function to add 2 vectors) and need to worry about parabolic curves (sounds like you do) your velocities will be changing, but hopefully some of the functions below will help you get a handle on things.

If I knew more math i'd try and turn this stuff into a full 2d physics engine, but alas math and I don't see eye to eye. If you want to learn more about this sort of thing, a REALLY good tutorial (though flash based) can be found here: http://www.tonypa.pri.ee/vectors/tut01.html

Code: Select all


## takes 2 points, px,py starting, px2, py2, ending and returns vector offsets
function pointsToVec px,py,px2,py2
   return px2-px,py2-py
end pointsToVec

/*
Takes an object reference and returns the x or y position of the object
Examples:
get xLoc(the long id of field "myfield")
get yLoc(the long id of grc "mygrc")
*/ 
function xLoc pObject
   return item 1 of the loc of pObject
end xLoc

function yLoc pObject
   return item 2 of the loc of pObject
end yLoc

##Return the length of the vector.
##vX and vY are the offset distances from the starting point
## then uses pythag Theorem to calc the length
function vLength vX,vY
   return sqrt((vX * vX) + (vY * vY))
end vLength

## Takes vector as the offset distance between points for x and y
## calculates the radians using atan2 * 180 / pi
function vToDegrees vX, vY
   return atan2(vx,vy) * 180/pi
end vToDegrees

## takes degrees and changes to radians
function dToRadians pDegrees
   return pDegrees / 180 * pi
end dToRadians

## takes radians and converts to degrees
function rToDegrees pRadians
   return pRadians * 180 / pi
end rToDegrees

## takes length and the angle in radians and returns vector as x,y offsets
function aLenToVector pLen pAngle
   return pLen * sin(pAngle),pLen * cos(pAngle)
end aLenToVector

## Get unit vector.
## Returns vector offsets whos vector length = 1 based on vector x and vector y

## use vLength function to make sure if vector length is 0, handle the error. 
function uVector vX,vY
   if  vLength(vx,vy) is not 0 then
      return vx/vLength(vx,vy) ,vy/vLength(vx,vy)
   else
      return 0,0
   end if
end uVector

## return left and right normals.
## Normals are the points perpendicular to the vector path
## so if you are standing up, facing front, to the front of you is a vector
## if you raise your arms up level with your shoulders pointing straight out to the sides
## These woudl be the left and right normals. 
function LRNormals vx,vy
   return -vy,vx,vy,-vx
end LRNormals

## add 2 vectors
## this would be useful for example if you have a gravity vector
## you can add the vector of gravity to the current vector of your object resulting in the new vector offsets

function vAdd vx,vy,vx2,vy2
   return vx + vx2,vy + vy2
end vAdd


## find the dot product of 2 vectors
## positive dp means the vectors are additive
## negative means they're subtractive
## IE positive they go generaly the same direction
## negative they go generally the opposite direction. 
## 0 = perpendicular movement
function dotProd vx,vy,vx2,vy2
   return vx*vx2 + vy * vy2
end dotProd


##Projection-- still learning so not sure yet where this falls into things. 
function vProj vX,vY,vX2,vY2
   return dotProd(vx,vy,vx2,vy2) * vx2,dotProd(vx,vy,vx2,vy2) * vy2
end vProj

Last edited by sturgis on Sat Oct 13, 2012 4:49 pm, edited 1 time in total.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Is it possible to make this game

Post by sturgis » Sat Oct 13, 2012 4:44 pm

For AI you mean basically how your obstacles will move around on the screen? That should be easy enough, you could use random as a trigger, or set up each object with a cycle that it goes through or whatever. If you mean a more reactive type of ai then its hard to say, if its something simple like having an object (obstacle) that can move at a set speed always trying to be 'in-line' with the ball, but the ball has more velocity so its possible to toss it over or under (making it possible to "fake out" the obstacle) that wouldn't be too bad. Objects have a "loc" which is the center point of the object. During your game loop you could do something like

if item 1 of the loc of grc "obstacle" < item 1 of the loc of grc "ball" then
moveObstacleUp -- a handler to move the obstacle based on whatever behavior you need
else
moveObstacleDown -- same for down
end if

This example isn't perfect. It would actually cause a very slight jitter in some cases (ball not moving, the obstacle would shimmer up and down 1 pixel because it doesn't account for an equal values, but you get the idea I hope)
salman.r1BUSYiYh wrote:thanks very much for the info, much appreciated :)


ill explain the game further:
in detail the game will have a character with a ball in his/her hand (he/she will be stood on a pavement) and then upon the swipe of the user the aim of the game is for the ball to fall on the curb of a pavement (so in scripting terms the target is the rectangular 90 degrees angle and i believe this can be achieved by collision detection). if it hits the target the user gets 1 point. in between the users pavement and the opposing pavement will be obstacles going up and down hence if the ball hits the obstacle then it will come back to him/her and if he/she misses the target then the ball rolls off the screen.

im still in lumber whether to make it a two player game i.e you vs the computer because you would need to do Artificial intelligence on the computers side, would implementing AI be doable since i have a deadline i.e. is it as simple as implementing the swipe action you stated before?

the only reason i want it to get done quickly is because im doing this for my project in university and if the project was only based on development then i would have take my time but i have to do alot of research work when i mean alot i mean alot! and i have to give equal time to other modules as well lol so thats why im a bit scared :?

salman.r1BUSYiYh
Posts: 24
Joined: Fri Sep 28, 2012 9:38 pm

Re: Is it possible to make this game

Post by salman.r1BUSYiYh » Sat Oct 13, 2012 6:54 pm

Definetly going to check it out! :)

For AI yes i will definetly implement it for the obstacles however what i meant was creating another player (computer) on the otherside of the pavement where the computer does the same thing as you ie. Trying to hit the curb of the pavemet. So it becomes a vs game something like the first one to score 10 points wins the game or in 3 minutes the one with more poimts wins. The computer side will have AI i.e it will take random shots at you which will be at random angles and lines

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Is it possible to make this game

Post by dave_probertGA6e24 » Sat Oct 13, 2012 11:42 pm

Hi,

Nice library of functions Sturgis, I might add a few of my own to that too - I'll drop them on the forum when I have done. Maybe we should set up a post for a maths/animation library for all to use :)

Salman:
For an AI (or CPU) player you basically need to figure out the code you use for the Human calculations and apply exactly the same thing to Computer players.

In other words, if the Human has a touch point and time, an untouch point and time as the inputs, then you simply fake them with some level of randomness.

A human has to figure out where to touch first - so, for the 'AI', you figure out the ideal touch start and apply a jiggle factor (+- a bit in both x and y) from that location. To 'untouch' there would also be an (roughly) ideal point - again you would need to apply a jiggle factor to that too. And a time/speed - which should also have a jiggle factor. The more Jiggle used the worse the AI is: so you can implement a level of play - easy, medium or hard. In my opinion an AI should never be perfect so always have some level of variance that means the AI could miss - give that human a chance ;)

Most of the above would be backwards calculations from and ideal finish position to the start, so you would have to do the math for that. Remember that the math should not require the graphics to move or anything, but simply to work with numbers. The calculations should only take a few microseconds, but you can cover that with a simple message - "Player CPU to go - touch the screen'. But once it's done then you treat the screen stuff just the same as a human player - plug in the jiggled numbers and show the resultant animation.

To get a good CPU player, though, requires a lot of testing - to make it seem like it is actually doing the same as the human would do - not simply pre-calculating the result and using it. And most of all if it doesn't always get things perfect then the Human player feels that they still have a chance - personally I hate games that 'cheat' just because they have badly written CPU players.

As an afterthought, if the levels are pre-designed then you could work out the ideal locations for the AI to use beforehand, load them in with the level and then just apply some random jiggle at run time.


I hope that helps a bit more,

Cheers,
Dave

PS. Definitely a doable game in 4 months. :)
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

salman.r1BUSYiYh
Posts: 24
Joined: Fri Sep 28, 2012 9:38 pm

Re: Is it possible to make this game

Post by salman.r1BUSYiYh » Sun Oct 14, 2012 2:14 am

Thanks dave

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Is it possible to make this game

Post by sturgis » Sun Oct 14, 2012 3:25 am

Sounds like a good idea to me. You're probably better than me at the math. (you pretty much have to be, I still think 2 + 2 = 3.7 for small values of 2)

Interested to see what else you have to add to the thing, might help me with a game i'm slowing working on.
dave_probertGA6e24 wrote:Hi,

Nice library of functions Sturgis, I might add a few of my own to that too - I'll drop them on the forum when I have done. Maybe we should set up a post for a maths/animation library for all to use :)

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: Is it possible to make this game

Post by dave_probertGA6e24 » Sun Oct 14, 2012 12:20 pm

Ah Sturgis, you are pretty close with your counting, but just remember that these are correct:
6 + 6 = 10
7 + 7 = 12
8 + 8 = 14
(think about it a bit before answering...)

But what does 5 + 5 = ?

Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Is it possible to make this game

Post by sturgis » Sun Oct 14, 2012 2:04 pm

16 if its a wednesday? Otherwise you have to carry the 3.
dave_probertGA6e24 wrote:Ah Sturgis, you are pretty close with your counting, but just remember that these are correct:
6 + 6 = 10
7 + 7 = 12
8 + 8 = 14
(think about it a bit before answering...)

But what does 5 + 5 = ?

Dave
Ok 8. Me and reading don't see eye to eye either.
Last edited by sturgis on Mon Oct 15, 2012 11:14 pm, edited 1 time in total.

salman.r1BUSYiYh
Posts: 24
Joined: Fri Sep 28, 2012 9:38 pm

Re: Is it possible to make this game

Post by salman.r1BUSYiYh » Mon Oct 15, 2012 9:12 pm

I been researchin aEngine for livecode which has some preety cool functions which may fit into my project
what do you guys think of aengine?
good add on for my project?

salman.r1BUSYiYh
Posts: 24
Joined: Fri Sep 28, 2012 9:38 pm

Re: Is it possible to make this game

Post by salman.r1BUSYiYh » Mon Oct 15, 2012 9:21 pm

also found a nice link on 2d game physics :D
http://www.rodedev.com/tutorials/gamephysics/

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Is it possible to make this game

Post by sturgis » Mon Oct 15, 2012 11:16 pm

I haven't used animationEngine much, but the things i've tried it has worked very well.
salman.r1BUSYiYh wrote:I been researchin aEngine for livecode which has some preety cool functions which may fit into my project
what do you guys think of aengine?
good add on for my project?

salman.r1BUSYiYh
Posts: 24
Joined: Fri Sep 28, 2012 9:38 pm

Re: Is it possible to make this game

Post by salman.r1BUSYiYh » Mon Oct 15, 2012 11:57 pm

hmmm to buy or not to buy :?

only reason is it seems like it would speed up the process in alot of things such as the math stuff discused before

Post Reply