Tetris or Pacman Step by Step? and 1 more question

@dave1707

I just finished the Lander 2 guide. Though, @Ignatz did an excellent job creating his revision of the original lander from @West I still feel empty I didn’t retain enough to create something myself

Aside from it making me slightly aware of the r.2 and r.3 commands. Which I had to google and youtube what it means: real coordinate space, nothing else.

Though Lander 2 is a master piece, maybe I am just not advanced enough to retain and grasp the knowledge used in there, to create my own thing. I need more simpler code, potentially with less lines, that does a lot of things within those lesser lines of code, so I can retain it’s functions and then start doing my own simple things with it.

This thought had me searching Codea’s Forums this morning around 3am or so. I ran into these potential paths for me.

Is there a Tetris or Pacman step by step?
I am aware of this Tetris…
https://codea.io/talk/discussion/3708/tetris-my-first-game
(Unfortunately it’s not a step by step, comes across like a copy and paste) Unfortunately for me, I do not learn like that.

Why am I requesting a Tetris or Pacman style game? Because I am taking advice from this article:
Codea Programming FAQ:
https://bitbucket.org/TwoLivesLeft/core/wiki/Codea%20Programming%20FAQ
Where it mentions the following:
“What projects should I start with?*
The experts recommend you start with well known and fairly simple games like Pacman or Tetris, which will teach you lots of things you need to know. As you get more skilled, you will be able to design your own games.”

The AMAZING step by step styles in my eyes, that I would hope everyone doing step by steps would mimic is the following teaching styles:

@Ignatz is the GOD of this stuff. He’s dope! I love his teaching style, a lot of what I have just awakened to, which I am calling my first contact with level 1 comprehension is because of @Ignatz

Here’s one of his dope, step by step:
https://coolcodea.wordpress.com/2014/10/20/175-3d-dungeon-programming-ai-behaviour/
He literally goes into granular breakdown for each code block, with the explanations being so elementary and simple, it’s perfect for a supreme noob like myself. His teaching style is art in itself!

The other one I appreciated was the Codea for Kids (Which is around my level of comprehension I would say)
https://bitbucket.org/TwoLivesLeft/core/wiki/ForKids

I reference these step by steps, because I am truly hoping, there are some Tetris or Pacman step by steps in this way: (I would prefer pacman)

My other question is regarding variable solution
I am studying how to get Codea to produce in the console, the greater variable, so I did the following:

function setup:
x = 1
y = 2

if x>y then x = y

elseif
x<y then x = x

print(“x”)

As shown immediately underneath function setup, x is lesser than y

My goal: I am trying to ask Codea, to find “on it’s own” the greater variable between x and y, and then show it me in the console.

Since I am doing something wrong… all I get is x as the resolution in the console. I think this is happening because I am inputting x inside the print command. If this is the reason, then how do I ask Codea “to find the greater variable on it’s own, and present it to me in the print command?

@tactfulgamer Maybe what’s happening is you’re trying to learn too much too soon. You’re looking at full blown programs and trying to understand what’s happening. Just looking at you’re code above, I’m not sure you understand basic stuff. See my code below that prints the greater value similar to yours above.

function setup()
    x=1
    y=2
    
    if x<y then
        x=y
    end
    
    print("The greater value is "..x)
end


@dave1707

I am?

I thought I had a general understanding of variables, meaning, I understand the concepts: A bucket holding information, stored inside memory to get recalled later.

I also understand tables are basically arrays. Like a tack box for fishing, a box that has several components in it, where I also can recall these components later.
I can add a tables to a score system in a game for example. (Though in the example I was showing you, I was not doing anything with tables there)

I was trying to find guides, that covered these areas, since, well… I thought I just came into understanding with their concepts. I was under the impression, I have those concepts down, I just don’t have the syntax commands to Codea down.

Did I not get the above concepts I expressed correct?
Is that not basic understanding or is it as you say - not even having the basics?

Where can I start that has many of these (variables and table) examples as a step by step?

@tactfulgamer It looks like you understand quite a bit. You just need to write small programs like you did above so you get everything working. It can be frustrating at first, but once you get going you’ll be able to write programs without thinking about it. I’ve been coding for so long that I don’t have to think about a lot of what I want to do.

@tactfulgamer I looked at the Tetris program you show in the link above. That might be OK if you were looking for code for something specific, but I wouldn’t want to try to learn how to code from it. Not that it’s bad code, there’s just too much code to start out from. I don’t know of any small step by step programs. If you would like examples on how to do something specific, I don’t have a problem with writing something for you to look at.

EDIT:

@dave1707 just saw your new post. I would love for you to write a code that shows me, but I would feel wrong to not compensate you some way.

That’s going to take time away from you to write code down for me and then explain it to me in a way I can pick up, since me structuring code seems to be a weakness I have, going from my sample I showed you. Do you have a paypal or something I can contribute to you somehow?

OLD POST:

@dave1707 now I’m lost - I thought I do not have the basics? you got me in confusion mode bro ;).

I hear you, I look forward to getting there.

I am not frustrated, I just need to know where to go.

I tried to code my simple variable program… and look at what your response was. lol. This basically tells me, I am lost and need some more time with Codea syntax so I can get that to meet my basic understanding, and then, hopefully I can code very simple console stuff for now.

Any area you can guide me to go to where I can start? Just point me to the direction, I’ll take it from there.

@tactfulgamer There is no need for compensation and it’s not taking time away from me to write examples and explain things. Right now I’m watching a baseball game and I could just as easily code examples while doing that. Like I said, I’ve been coding for so long that I don’t have to think about a lot of things. That’s mostly what I do when I code, watch TV and write code, no problem.

@tactfulgamer Here’s an example that uses parameter sliders, sprites, text, print console, and the touched function. Play around with this and if you have questions about anything, just ask.

function setup()
    parameter.number("x",0,WIDTH,WIDTH/2)   -- parameter slider for x
    parameter.number("y",0,HEIGHT,HEIGHT/2) -- parameter slider for y
    xx,yy=WIDTH/2,HEIGHT/4  -- initial values
    str=""      -- initial value, blank
    fill(255,0,0)   -- set text color (red)
end

function draw()
    background(0)   -- set bacground to black
    sprite("Planet Cute:Character Horn Girl",x,y)   -- draw at x,y values
    sprite("Planet Cute:Character Boy",xx,yy)       -- draw at xx,yy values
    text(str,WIDTH/2,HEIGHT-50) -- text on screen at screen positions
    text("touch/move screen to move bottom sprite ",WIDTH/2,HEIGHT-150)
    text("move  sliders to move top sprite",WIDTH/2,HEIGHT-100)
end

function touched(t) -- touched function using variable t 
    if t.state==BEGAN then  -- touch began
        str="touch began" -- set str value
        output.clear()  -- clear print console 
        print(str)  -- print to console
        xx=t.x  -- set xx to the touch x value
        yy=t.y  -- set yy to the touch y value
    end

    if t.state==MOVING then -- touch is moving
        str="touch moving  "..t.x.."  "..t.y    -- show touch x,y values also
        xx=t.x
        yy=t.y
        print(str)  -- print to console
    end

    if t.state==ENDED then  -- touch ended
        str="touch ended"
        print(str)  -- print to console
    end
end

@tactfulgamer

In case you haven’t come across them all, here are my tutorials/step by step guides:

Snake: https://gist.github.com/Westenburg/6487451

I’ve listed a number of “stretch” goals to be implemented but step through the basic first steps. Follows on from Lunar Lander

Asteroids: https://gist.github.com/Westenburg/6487497
Another step by step, but a bit more complex

Runner: https://gist.github.com/Westenburg/713b824a7bea4d67e3c8
A simple side scrolling endless runner - not step by step but should be simple enough to follow

https://gist.github.com/Westenburg/273e478b26432f4bdeb5
Not step by step, but implements simple touch controls for space invaders

Side shooter: https://gist.github.com/Westenburg/5743643
The basics of a sideways shooter - a more complicated version is also available

Missile Command: https://gist.github.com/Westenburg/7ef74e2edd4da341f1cb
Missile Command - simple but no step by step

Also, it’s very old but a good tutorial series which takes you through building the minesweeper game.

http://codeatuts.blogspot.com/2012/07/tutorial-6-minesweeper-part-1.html

Pacman though simple on the surface will require you to code up quite a few elements, including:

Drawing a map on the screen
(probably) implementing an onscreen joystick to control movement.
Moving the pacman sprite and implementing collision detection
Dealing with management of the location of dots and their state (eaten or not)
Implementing Power Pills
Movement of ghosts
Implementing AI of ghosts to track/follow pacman

My advice would be to pick something super simple to start with and build from there - tackling something too complex to start with can lead to becoming disenchanted with it.

I would recommend:
A whack-a-mole clone
A flappy bird clone
A vertical/horizontal shooter
A match the pairs card game - tap two cards and if they match remove them

…as good starter projects.

@dave1707 @West I greatly appreciate it, thank you. Looks I have some new stuff to learn Yay’

@dave1707 I was messing around with the first set of code using variables that you helped me with:

function setup()
    x=1
    y=2

    if x<y then
        x=y
    end

    print(‘The greater value is ‘..x)
end

I was wondering about the last bit of it, this portion:

print(‘’..x)

I removed the words within the single quotes ‘’ and learned, the single quotes are just used for strings, sort of like C# does with the double “”

The part I was wondering about is the concatenation which is the before the x variable.

Did you concatenate here because, within the code block, the if and then statements are a series of events that lead to an result?

Looking up the meaning to concatenation l get the following:

”con·cat·e·na·tion
/k?n?katn??SH(?)n/
noun
a series of interconnected things or events.
"a singular concatenation of events unlikely to recur"
synonyms:	series, sequence, succession; More
the action of linking things together in a series.”

That said, if what I am thinking is correct, that was the only way for Codea to produce the accurate result, which in this case came out to 2?

Basically concatenation is needed for situations similar to this one, where there are if, then, elseif, do… etc keywords involved.

You can use single or double quotes for strings in Codea. Try the following:

function setup()
    x=10
    y=20
    print(x+y)
    print(x..y)
    print("x plus y is "..x+y.." whereas x concatenated with y is "..x..y)
end

The … forces the variable (x or y) to be treated as a string

@dave1707 I was messing around with the first set of code you helped me with regarding variables, this one:

function setup()
    x=1
    y=2

    if x<y then
        x=y
    end

    print(‘The greater value is ‘..x)
end



.

I removed the words within the single quotes. So my testing looked like this:

print(‘’..x)

I learned, they (I forget the name of the ’’ concept) but it looks like they are used to present strings in the console when placed in a print command. Sort of like C# with the double “” Am I correct here?



.

The part I was wondering about with that code block is the concatenation which is the before the x. This portion:

print(‘’..x)

I was wondering, did you concatenate here because, in the code block, the if* and then statements are a series of events that lead to an action?

Looking up the meaning to concatenation:

con·cat·e·na·tion
/k?n?katn??SH(?)n/
noun
a series of interconnected things or events.
"a singular concatenation of events unlikely to recur"
synonyms:	series, sequence, succession; More
the action of linking things together in a series.
"this is a string of characters"
'so is this'
x="this stores this string in the variable x"
print("this prints this string")
print(x) -- prints out the value of x
print("x") -- prints out a literal x
"this is the " .. "concatenation of two strings"

In your first code you have print("x") which simply prints a literal x as it prints the string consisting of the letter x. To print the value of the variable x you use print(x).

Concatenation is the process of making a new string from two other ones. The old strings can be literal, as in "a string", or stored in variables. So if x="hello" and y="world" then z = x .. y makes z equal to "helloworld".

@tactfulgamer Concatenation has nothing to do with if, then, elseif, do, etc. As said above, concatenation joins various things together. It’s a simple way to format the way something looks when it prints. Here’s an example that shows print statements not using and using concatenation.

function setup()
    x,y,z=12345,23456,34567
    print("x = ",x,"y = ",y,"z = ",z)
    print("x = "..x.." y = "..y.." z = "..z)
end

Thank you guys. I got it now, good looking out @LoopSpace

I thought the concatenation had something to do with it because of how @dave1707 put out his syntax. Now I get it, that he set it up that way, because was talking to me within the code.

I’m still learning, so this technique of speaking/teaching through code like dave did, is still new to me.

That said, I do prefer the code line to be as minimal as possible. I’m glad it can be done without the … and the ‘’

What lead to my question initially, one because of the buffoonery that comes with cluelessness. Here is some insight into a noobs mind - you guys deserve a laugh.

In my search to get the print command to resolve the variable from x, notice how I have for some reason I have loyalty to the ‘’ inside the () just comical.

I tried this way first:

print(‘..’)

^^^so obviously, yea nothing happened there or Codea didn’t even allow me to run it I think.


.

Then I tried

print(‘’)...

And yea, nothing going on there.



.
Lastly went this route:

print(‘x’)

^^^ And as @LoopSpace stated it prints a literal x.

Truly, buffoonery academics going on over here.

@LoopSpace
Thank you - Open & Closed parenthesis, was exactly what I was looking for!

I forgot Bob Tabor taught me this awhile ago in his C# Courses:
https://mva.microsoft.com/en-us/training-courses/c-fundamentals-for-absolute-beginners-16169?l=Y6D7PQQIC_5406218949

One of those… If you don’t use it, you loose it.

Thanks again gentleman.

@LoopSpace How did you get your x come out like that here?

I tried the 3 tilde ~ before and after the x, definitely not that.

Inline code can be done with backticks, like this

Inline code can be done with backticks, like `this`

@LoopSpace Thanks