In this and in the next two blog entries will show some of the basics on how to design a simple game.
The first program is called MOVEM. This really isn't a game, but it is to introduce the GETKEY function on the HP Prime. The GETKEY gets the last key pressed, while the programmer decides what happens with each key stroke. Each key will return a key code.
The key codes used are:
2: up
7: left
8: right
12: down
50: plus key
Other common key codes include 30 for Enter.
The HP Prime pixel screen is 320 x 240, with row pixels 0319 going right, and column pixels 0239 going down.
The size of the text that is used in MOVEM series is size 2, which means that the characters are 10 pixels long by 12 pixels high.
Comments in the program are followed by two forward slashes. They don't have to be typed into the program, but they will provide helpful notes.
To run MOVEM, call up MOVEM and move the "M" around the screen using the arrow keys on the arrow pad. Exit by pressing the Plus (+) button. Note the code after each arrow movement  your character ("M") will not move beyond the screen's borders.
Code:
EXPORT MOVEM()
BEGIN
// clear the screen
RECT();
// set up the character
A:=100;
B:=60;
TEXTOUT_P("M",A,B,2);
// Start the main loop
REPEAT
K:=GETKEY;
// Move Left
IF K==7 AND A>0 THEN
RECT_P(A,B,A+10,B+12);
A:=A10;
END;
// Move Right
IF K==8 AND A<320 THEN
RECT_P(A,B,A+10,B+12);
A:=A+10;
END;
// Move Down
IF K==12 AND B<240 THEN
RECT_P(A,B,A+10,B+12);
B:=B+12;
END;
// Move Up
IF K==2 AND B>0 THEN
RECT_P(A,B,A+10,B+12);
B:=B12;
END;
TEXTOUT_P("M",A,B,2);
// Exit using the Plus Key
UNTIL K==50;
END;
The next blog entry will show how to put a goal and immovable solid objects.
This blog is property of Edward Shore  2014.
A blog is that is all about mathematics and calculators, two of my passions in life.
Subscribe to:
Post Comments (Atom)
Adventures in Python: Plotting Sine and Cosine, The numpy Module
Adventures in Python: Plotting Sine and Cosine, The numpy Module This program will require that you have both numpy and matplotlib. ...

Casio fx991EX Classwiz Review Casio FX991EX The next incarnation of the fx991 line of Casio calculators is the fx991 EX. ...

TI36X Pro Review This is a review of the TI36X Pro Calculator by Texas Instruments. History Originally, this was the TI30X Pro that w...

One of the missing features of the TI82/83/84 family is the ability to convert between bases. Here are two programs in TIBasic to help...
No comments:
Post a Comment