Keeping playing cards on screen

Good day to all.

I am trying my hand at coding my first mobile game (strictly for learning purposes).

I have spent the last year, STRICTLY reading on Lua and Corona.

Yes I understand (more now) that I should have followed along entering the code as I read the books. However, I wanted to amass as much vocabulary information in my brain without having to actually code, and juste read through and see what is going on. It has been an adventure.

I have learned the LUA / CORONA language quite well, I feel, for having no human help outside of his or her textual help.

I am beginning now to understand what “they” mean by how Corona has simplified things for the lowly-developer! :wink: Had I programmed games before, I probably would know the COMPLETE extent that Corona is hiding behind the scenes.

 Wish I had the time to look behind that infinite veil of code!

Anyway, all excitement for learning the Corona SDK aside, I was wondering, is there anything that I may not be aware of as far as keeping playing cards ON SCREEN aside from the following code. Is there any ERROR checking that is involved with something like this?

local moveCard = function(event)

 

KEEPS THE CARD FROM GOING OFF THE LEFT OR RIGHT SIDES OF THE SCREEN

 

If((card.x - card.width * 0.5) < 0) then

card.x = card.width * 0.5

Else-if ((card.x + card.width * 0.5) > display.contentWidth) then

card.x = display.contentWidth - card.width * 0.5

End

 

KEEPS THE CARD FROM GOING OFF THE TOP OR BOTTOM SIDES OF THE SCREEN

 

If((card.y - card.height * 0.5) < 0) then

card.y = card.height * 0.5

Else-if ((card.y + card.height * 0.5) > display.contentHeight) then

card.y = display.contentHeight - card.height * 0.5

End

 

end

Thanks anyone.

Chris

I will figure this out one way or the other!  :)

PEACE

Hey Chris, 

Glad to see you’re trying your hand at Corona. When you post code to the forums, make sure you use the <> button above to do it. It makes it more readable. Below is your code formatted. You’ll get more responses that way. Anyhow, could you post some more info. It’s not clear what you are trying to accomplish. Why are your playing cards not staying on the screen? When do they move outside the screen bounds? How are you interacting with them? 

local moveCard = function(event) --KEEPS THE CARD FROM GOING OFF THE LEFT OR RIGHT SIDES OF THE SCREEN if ((card.x - card.width \* 0.5) \< 0) then card.x = card.width \* 0.5 elseif((card.x + card.width \* 0.5) \> display.contentWidth) then card.x = display.contentWidth - card.width \* 0.5 end --KEEPS THE CARD FROM GOING OFF THE TOP OR BOTTOM SIDES OF THE SCREEN if((card.y - card.height \* 0.5) \< 0) then card.y = card.height \* 0.5 elseif ((card.y + card.height \* 0.5) \> display.contentHeight) then card.y = display.contentHeight - card.height \* 0.5 end end

Thanks, James.

I will look for the <> button next time. 

I have not even begun to code a single line for my card game. :slight_smile:

I am trying to do what I think I am supposed to be doing, and that is, Program Design Documentation.

I have been wrapping my head around possible OBJECTS for my game, namely,

DEALER OBJ

DRAW_DECK OBJ

IN_HAND OBJ

PLAYED OBJ

DISCARD OBJ

LET ME EXPLAIN MY REASONING

Ignoring for the moment any GAME.lua, WORLD.lua, or UI.lua module/objects, in my head I am picturing a DEALER object that will “create” a pack of cards, with suits, numbers, rank etc; then, the DEALER OBJ shuffles the cards, and deals cards to a IN_HAND OBJ which is a table of cards with a screen location, representing what is IN the players current hand.

And then the dealer puts the remaining un-dealt cards in a DRAW_DECK OBJ which is another self contained table of cards with a different screen location.

At this point, the “pack” of cards that was created is now an “empty” TABLE,  representing, say, an empty box of cards, as the DRAW_DECK and IN_HAND OBJs have all the cards now.

As well, I have a PLAYED OBJ and a DISCARD OBJ.

My reasoning is this.  

Because I have all these separate “OBJ-locations” where cards can be dropped in separate TABLEs, and, the OBJs all have variables and events and functions that will inform the DEALER as to the state of any given OBJ-Location, THEN, I assume, the PLAYER may freely drag these cards to and from these locations.

So, I figured it was a developers duty to make certain the objects that are supposed to always be in the screen bounds, must have a way to do so.

I know I am very knew to all of this, and I can’t even begin to imagine ALL the possible ways to program the SAME card game.

I am trying to do all I can on my own. I plan on buying CORONA PRO long before I am a PRO!, but, I am alone on this steep learning curve, as I have always been, and I am not looking for any easy way out, but I am looking for way to get a game out! 

I am very excited, and very overwhelmed, though very motivated.

Any hints, tips, or links to code that I can check out would be great.

I was given a link to a CORONA CARD GAME TEMPLATE, though it was unfinished, the code outdated, and the developer put all the card data in a .JSON file, and when I try to open that .JSON file in SUBLIME, all I see is under the hood of an HTML DOC.

I know I am doing something wrong there!

Anyway, thank you James. 

I am doing my best to do all the right things.

Peace.

Chris

Great to hear your enthusiasm Chris. This community is awesome. You’ll like it here. Anyhow, here are a few movement scenarios I can think of…I’m sure others could come up with some more. 

1.) Tap card to discard - use transition library to move card to the discard pile. 

2.) Touch card and drag to discard pile.

You won’t be using physics with a card game, so there shouldn’t be any concern that your cards may fly off the screen, so to speak. When touching and dragging a card from one pile to another, you can detect the position of the card your discarding and its proximity to the discard pile. When the card is close enough, snap it to the pile. Without physics, your card won’t move unless you are interacting with it, or tell it to. For your card piles, you could set up a rectangle, set its alpha to 0 (so it’s not visible) and use that for positioning your cards. There are lots of options. I’m interested to see what you come up with. Keep us posted. 

The transition library is great for moving display objects. That’s really a good option too. 

Chris,

Different people have different learning styles. I find it easier to learn how to do stuff in corona by jumping in and writing some code and running it in the simulator.

If your method is working for you, then of course you should keep at it. Why do you think you need to write a Program Design Document before you start writing the code?

Elbowroomapps, :slight_smile: Good day to your elbows! 

As I have read, “This step can not be overlooked. It is critical to start every project with a clear description of what that project is to accomplish.”

From the outdated, but still helpful book, Corona Hot Shot.

Being self taught strictly from books alone and not an instructors voice for miles, that is, up to this point now that I am ankle deep in this forum, but I find it easy to read over something that IS critical, though not knowing how critical it is.

For example, when the author says, a game has two important EVENTS, namely, game start and game end, it took me weeks to be begin to realize that there is more to the EVENT SYSTEM than meets the eye.

For the beginner, such as I, I think it is very easy to take the POWER of this event system for granted.

I’m still wrapping my head around it.

:slight_smile:

Thanks for your feed back, I am not used to my books talking to me!

This is great.

Wish me luck, I know I need some of that, a thorough course in LUA AND CORONA would be great too, I have no problems paying for such a course, provided they don’t just teach me the basics, as I have read in countless books I have purchased. I am really wanting to subscribe to Corona Pro, ASAP, but I want to see at least a working prototype of my idea before I gamble that I can do this at all.

$400, is not a lot for the year for this cool program, and I think it is genius that Corona Labs has taken this route, the devil knows I have dumped money in things that I should have researched a bit more. :slight_smile:

anyway, thanks again, I’ll get this.

Chris 

Oh, yea, I do know it is high time I start coding, and that is where I am, my Program Design Document is far from done, but it has cleared up things, in fact made things visible I had not seen. FUN “SHTUFF” :slight_smile:

James, I’ll give some thought to your suggestions. Thanks for opening up other avenues. 

Chris

Hey Chris, 

Glad to see you’re trying your hand at Corona. When you post code to the forums, make sure you use the <> button above to do it. It makes it more readable. Below is your code formatted. You’ll get more responses that way. Anyhow, could you post some more info. It’s not clear what you are trying to accomplish. Why are your playing cards not staying on the screen? When do they move outside the screen bounds? How are you interacting with them? 

local moveCard = function(event) --KEEPS THE CARD FROM GOING OFF THE LEFT OR RIGHT SIDES OF THE SCREEN if ((card.x - card.width \* 0.5) \< 0) then card.x = card.width \* 0.5 elseif((card.x + card.width \* 0.5) \> display.contentWidth) then card.x = display.contentWidth - card.width \* 0.5 end --KEEPS THE CARD FROM GOING OFF THE TOP OR BOTTOM SIDES OF THE SCREEN if((card.y - card.height \* 0.5) \< 0) then card.y = card.height \* 0.5 elseif ((card.y + card.height \* 0.5) \> display.contentHeight) then card.y = display.contentHeight - card.height \* 0.5 end end

Thanks, James.

I will look for the <> button next time. 

I have not even begun to code a single line for my card game. :slight_smile:

I am trying to do what I think I am supposed to be doing, and that is, Program Design Documentation.

I have been wrapping my head around possible OBJECTS for my game, namely,

DEALER OBJ

DRAW_DECK OBJ

IN_HAND OBJ

PLAYED OBJ

DISCARD OBJ

LET ME EXPLAIN MY REASONING

Ignoring for the moment any GAME.lua, WORLD.lua, or UI.lua module/objects, in my head I am picturing a DEALER object that will “create” a pack of cards, with suits, numbers, rank etc; then, the DEALER OBJ shuffles the cards, and deals cards to a IN_HAND OBJ which is a table of cards with a screen location, representing what is IN the players current hand.

And then the dealer puts the remaining un-dealt cards in a DRAW_DECK OBJ which is another self contained table of cards with a different screen location.

At this point, the “pack” of cards that was created is now an “empty” TABLE,  representing, say, an empty box of cards, as the DRAW_DECK and IN_HAND OBJs have all the cards now.

As well, I have a PLAYED OBJ and a DISCARD OBJ.

My reasoning is this.  

Because I have all these separate “OBJ-locations” where cards can be dropped in separate TABLEs, and, the OBJs all have variables and events and functions that will inform the DEALER as to the state of any given OBJ-Location, THEN, I assume, the PLAYER may freely drag these cards to and from these locations.

So, I figured it was a developers duty to make certain the objects that are supposed to always be in the screen bounds, must have a way to do so.

I know I am very knew to all of this, and I can’t even begin to imagine ALL the possible ways to program the SAME card game.

I am trying to do all I can on my own. I plan on buying CORONA PRO long before I am a PRO!, but, I am alone on this steep learning curve, as I have always been, and I am not looking for any easy way out, but I am looking for way to get a game out! 

I am very excited, and very overwhelmed, though very motivated.

Any hints, tips, or links to code that I can check out would be great.

I was given a link to a CORONA CARD GAME TEMPLATE, though it was unfinished, the code outdated, and the developer put all the card data in a .JSON file, and when I try to open that .JSON file in SUBLIME, all I see is under the hood of an HTML DOC.

I know I am doing something wrong there!

Anyway, thank you James. 

I am doing my best to do all the right things.

Peace.

Chris

Great to hear your enthusiasm Chris. This community is awesome. You’ll like it here. Anyhow, here are a few movement scenarios I can think of…I’m sure others could come up with some more. 

1.) Tap card to discard - use transition library to move card to the discard pile. 

2.) Touch card and drag to discard pile.

You won’t be using physics with a card game, so there shouldn’t be any concern that your cards may fly off the screen, so to speak. When touching and dragging a card from one pile to another, you can detect the position of the card your discarding and its proximity to the discard pile. When the card is close enough, snap it to the pile. Without physics, your card won’t move unless you are interacting with it, or tell it to. For your card piles, you could set up a rectangle, set its alpha to 0 (so it’s not visible) and use that for positioning your cards. There are lots of options. I’m interested to see what you come up with. Keep us posted. 

The transition library is great for moving display objects. That’s really a good option too. 

Chris,

Different people have different learning styles. I find it easier to learn how to do stuff in corona by jumping in and writing some code and running it in the simulator.

If your method is working for you, then of course you should keep at it. Why do you think you need to write a Program Design Document before you start writing the code?

Elbowroomapps, :slight_smile: Good day to your elbows! 

As I have read, “This step can not be overlooked. It is critical to start every project with a clear description of what that project is to accomplish.”

From the outdated, but still helpful book, Corona Hot Shot.

Being self taught strictly from books alone and not an instructors voice for miles, that is, up to this point now that I am ankle deep in this forum, but I find it easy to read over something that IS critical, though not knowing how critical it is.

For example, when the author says, a game has two important EVENTS, namely, game start and game end, it took me weeks to be begin to realize that there is more to the EVENT SYSTEM than meets the eye.

For the beginner, such as I, I think it is very easy to take the POWER of this event system for granted.

I’m still wrapping my head around it.

:slight_smile:

Thanks for your feed back, I am not used to my books talking to me!

This is great.

Wish me luck, I know I need some of that, a thorough course in LUA AND CORONA would be great too, I have no problems paying for such a course, provided they don’t just teach me the basics, as I have read in countless books I have purchased. I am really wanting to subscribe to Corona Pro, ASAP, but I want to see at least a working prototype of my idea before I gamble that I can do this at all.

$400, is not a lot for the year for this cool program, and I think it is genius that Corona Labs has taken this route, the devil knows I have dumped money in things that I should have researched a bit more. :slight_smile:

anyway, thanks again, I’ll get this.

Chris 

Oh, yea, I do know it is high time I start coding, and that is where I am, my Program Design Document is far from done, but it has cleared up things, in fact made things visible I had not seen. FUN “SHTUFF” :slight_smile:

James, I’ll give some thought to your suggestions. Thanks for opening up other avenues. 

Chris