Example

Graphics

7

crosoft312 2021-05-31 18:38

Simulation of cat

test.nx | Open in app
2021-05-31 18:38

was8bit 2021-05-31 19:47

I like it :)


crosoft312 2021-05-31 20:00 (Edited)

Thanks! It's just a little graphics test I made after figuring out some sprite stuff.


orczr 2021-05-31 20:30

Wow! Really accurate simulation


crosoft312 2021-05-31 20:38

Thanks!


was8bit 2021-05-31 20:55 (Edited)

The "spirit" of the presentation is as important as the graphics themselves... and even though we are limited graphically (hence the name LowRes-oution) you captured the speed and personality of a cat very well :)


was8bit 2021-05-31 21:21 (Edited)

Here, i have made a little "toy" .... you tap the screen and the cat will chase down where you tapped... currently the tapped spot just shows a little dot...

If you like this u r free to upgrade my graphics and post as yours :)

Sprite 1 is set at size 2 which is 3x3 blocks, ref char# is the top left corner of the blocks

Cat test2.nx | Open in app
2021-05-31 21:21

was8bit 2021-05-31 21:27

If you want the cat to face left or right, find the top code shown and add below it the bottom code...

SPRITE 0,SX+SGN(TX-SX),SY+SGN(TY-SY),
IF SGN(TX-SX)<0 THEN SPRITE 0 FLIP 1,0 ELSE SPRITE 0 FLIP 0,0


crosoft312 2021-05-31 23:30 (Edited)

Wow! You made that in a couple of minutes! I could only write one print statement in that amount of time!

The program is way beyond my understanding of nx (or graphics in general)! I haven't the slitest idea how it works, but I'll look at the code to see if I can learn from it. Thank you for making it!


was8bit 2021-06-01 02:43

:)

Yes, play around with code, its a good way to learn :)


TOUCHSCREEN or GAMEPAD or 2 differernt ways players may play your game, you just cannot use both at the same time... i like using TOUCHSCREEN as often as i can :)

This code..

IF TAP THEN

Could be rewritten as

IF TOUCH THEN

The difference is that TAP records the touch's x,y only once, when you tap the screen... TOUCH keeps updating the touch's x,y as you drag your finger across the screen..

TOUCH.X and TOUCH.Y is the location on the screen where you have tapped...


was8bit 2021-06-01 02:45 (Edited)

The "meow" is now drawn as a graphic... it is now a 3x3 sprite... experiment redecorating it... it uses these char#'s...

2,3,4
18,19,20
34,35,36


was8bit 2021-06-01 02:51

The math for moving the cat is abit tricky...

SPRITE.X(#) gives you the x position of a sprite#

SX=SPRITE.X(0)
SY=SPRITE.Y(0)

Just stores the current position of cat as SX,SY

TX-SX will be a negative number if target is to the cats left, and positive if target is to the cats right...

SGN(#) is a math trick that converts all negatives to -1 and all positives to +1

So

SX+SGN(TX-SX)

Is simply a condensed math that nudges the cat towards the target ;)


was8bit 2021-06-01 02:54 (Edited)

SPRITE commands do not always need all info, you may leave out values that dont change...

So if you are only changing a sprites image, you simply write

SPRITE 0,,,chr#

If you are only changing a sprites location, you can simply write

SPRITE 0,x,y,

It is OK to repeat unchanged values, if you want to ;)

SPRITE 0,x,y,chr#


was8bit 2021-06-01 02:56

I know, a lot of info....

... dont hesitate to ask any questions, and keep exploring :)


was8bit 2021-06-01 02:59

Scroll thru my stuff... i have quite a few postings covering SPRITES...

Also, you may download and remix anything i have posted....its a good way to learn :)


SP4CEBAR 2021-06-01 16:02

Only 8 lines of code, I like it


SP4CEBAR 2021-06-01 16:43 (Edited)

I added some things to @was8-bit's version, it's now a game

Test 3.nx | Open in app
2021-06-01 16:43

SP4CEBAR 2021-06-01 16:49 (Edited)

By adding a one minute timer and high-scores this game could be made more competitive


crosoft312 2021-06-01 17:22 (Edited)

spacebar, Wow! That's a pretty cool little demo game! Thank you!
I just realized the little sprites the cat eats are mice. That makes it a little sadder, but I might be digging to deep into it.


SP4CEBAR 2021-06-01 18:17

Good luck :)


crosoft312 2021-06-01 18:57

thanks!


was8bit 2021-06-02 00:40 (Edited)

Take little steps.... take one thing at a time... like, try adding a 3x3 sprite for a saying, maybe even give it a cartoon border or something, and try adding it to your original one as a subsitute for the PRINT one...

So, delete PRINT "MEOW"

And add in its place...

SPRITE 1,100,100,2
SPRITE 1 SIZE 2

And try to figure out how to draw the 3x3 sprite, its upper left corner is character#2


crosoft312 2021-06-02 01:12 (Edited)

Does tap work with the cursor on a computer, or is it for touchscreen devices only?
Also, If you had a box, -------- My ascii art ain't very good! :)
- - - - - - - -
|------------|
- - - - - - - -
and you wanted to check if the user tapped anywhere inside the box, how would you?
Would you make a sprite for box and there's a specific command to check if any of the sprite is touched?


was8bit 2021-06-02 04:01

I believe on the computer TAP = quick click/release, and TOUCH = hold mouse button down and move mouse around


was8bit 2021-06-02 04:05 (Edited)

For checking if a player has touched a cell, TOUCH and SPRITES use pixel coordinates, while characters placed as cells use CELL coordinates.. a cell is 8x8 pixels, so to see if a player touched cell 2,2

IF TOUCH.X\8=2 and TOUCH.Y\8=2 THEN cell position 2,2 has been touched

..........

Or you can check what is the character graphic # in the cell block you touched..
C=CELL.C(TOUCH.X\8,TOUCH.Y\8)
C = the character graphic # touched


was8bit 2021-06-02 04:13

Checking if a sprite has been touched isnt directly possible.. only a sprite hitting another sprite can be checked...

So, notice in my TEST CAT 2 program, whenever you tap the screen, you see a tiny little dot on the screen... this isnt by accident, i am using SPRITE 2 with graphic #5 which is a tiny single dot.... now i dont use sprite hit here... but....

You CAN use a "test" sprite with a single dot, put it wherever you tapped, then do a quick check...

IF SPRITE HIT(2) THEN
END IF

assuminng #2 is your testing sprite with the single dot... this trick then can tell you WHICH sprite was hit with HIT.. nx sets HIT to the SPRITE# that was touched by the check SPRITE HIT(#)


was8bit 2021-06-02 04:20 (Edited)

So, if you want the hit sprite to disappear...
IF SPRITE HIT(2) THEN
SPRITE OFF HIT
END IF

If you want to change the graphic for the hit sprite..
IF SPRITE HIT(2) THEN
SPRITE HIT,,,8
END IF

The variable HIT is used by NX and is seen as the number NX has set it to

SPRITE HIT is actually a single command, it can be confusing because it looks like 2 different variables, but together like this they act as one command...


crosoft312 2021-06-02 17:32 (Edited)

Ok, Good to know. Thank you for writing all that out! Very helpful!


Log in to reply.