Showing posts with label game. Show all posts
Showing posts with label game. Show all posts

Saturday, February 24, 2024

Swiss Micros DM42 and HP 42S: Moon Landing Simulator from the HP 33-E Applications Book

Swiss Micros DM42 and HP 42S: Moon Landing Simulator from the HP 33-E Applications Book



Landing the Rocket


The goal is to provide enough fuel to get the rocket to land on the moon safely. The use of fuel pushes the rocket away from the surface and slow down the descent. Don’t crash or use too much fuel to escape into space.


Variables:


X: Position

V: Velocity

F: Fuel

G: Gravity

B: Amount of Fuel to burn


Initial Values (from the HP-33E Applications):

X = 500

V = -50

F = 120

G = 5


I wasn't sure about the win condition (X = 0, V = 0?).


I show the position, velocity, and fuel after each successful turn. Enter the amount of units to burn at the burn prompt.



Download here: https://drive.google.com/file/d/1YsYzIMxALuRx_MHSSzGFFEQJdrN656DS/view?usp=sharing



DM42 and HP 42S Code: MOON


00 { 184-Byte Prgm }

01▸LBL "MOON"

02 500

03 STO "X"

04 -50

05 STO "V"

06 120

07 STO "F"

08 5

09 STO "G"

10▸LBL 01

11 "POS:"

12 ARCL "X"

13 AVIEW

14 STOP

15 "VEL:"

16 ARCL "V"

17 AVIEW

18 STOP

19 "FUEL:"

20 ARCL "F"

21 AVIEW

22 STOP

23 RCL "X"

24 X=0?

25 GTO 07

26▸LBL 02

27 "BURN?"

28 PROMPT

29 STO "B"

30 RCL "F"

31 X<Y?

32 GTO 05

33▸LBL 03

34 RCL "B"

35 STO- "F"

36 RCL- "G"

37 STO "A"

38 RCL "V"

39 RCL+ "X"

40 RCL "A"

41 2

42 ÷

43 +

44 STO "X"

45 X≥0?

46 GTO 04

47 GTO 06

48▸LBL 04

49 RCL "V"

50 RCL+ "A"

51 STO "V"

52 GTO 01

53▸LBL 05

54 2

55 RCL× "G"

56 RCL "V"

57 X↑2

58 +

59 SQRT

60 +/-

61 STO "V"

62▸LBL 06

63 "VEL:"

64 ARCL "V"

65 AVIEW

66 "YOU LOSE"

67 AVIEW

68 RTN

69▸LBL 07

70 "SUCCESS!"

71 AVIEW

72 .END.



Example Game


XEQ "MOON"


Initial Turn

POS: 500

VEL: -50

FUEL: 120


BURN? 0

POS: 447.5

VEL: -55

FUEL: 120


BURN? 0

POS: 390

VEL: -60

FUEL: 120


BURN? 0

POS: 327.5

VEL: -65

FUEL: 120


BURN? 5

POS: 262.5

VEL: -65

FUEL: 115


BURN? 0

POS: 195

VEL: -70

FUEL: 115


BURN? 5

POS: 125

VEL: -70

FUEL: 115


BURN? 10

POS: 57.5

VEL: -65

FUEL: 100


BURN? 12.5

"YOU LOSE" -3.75


So close. Good luck!



Source


HP-33 Applications. Hewlett Packard. Corvallis, OR. February 1978



Eddie


All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Sunday, February 16, 2014

HP Prime: Programming a (Very) Simple Game Part 5

Here it is - a complete simple game.  The objective is to collect dollar signs (coins) to unlock the boundary at the top of the screen to allow access to the goal.  Trees block your progress.  Avoid the purple foes at all times, one touch and it's over!  One purple foe jumps around randomly while two fly horizontal.  

Once again, you are controlling the π character.   Press the plus key to quickly exit the game.  This comes in handy if the game ever becomes "unbeatable" (although I tried to knock out all the bugs). 





The game features a status bar at the bottom of the screen that shows two things:
*  The number of coins remaining
*  A "LOCKED" indicator that indicates that the boundary is active (red) 

This is a culmination of the Simple Game series.  The program is named MOVEM7.

Note: if you are using the emulator, let d1:=1200 and d2:=200.

EXPORT MOVEM7()
BEGIN
// Version 7
// 2014-02-16
// Collect 10 coins to unlock the goal

// A status screen is added on the bottom
// Bottom row is not avialable for play
// This version puts it all together:
// Coins, trees, and enemies

// Game introduction
MSGBOX("Collect all 10 $ signs to unlock
the goal! Avoid the purple enemies!");

// Clear the screen
RECT();

// Cursor set up
LOCAL A,B,C,D;
A:=150;
B:=216;
C:=150;
D:=216;
TEXTOUT_P("π",A,B,2);

// Draw Coins
LOCAL costr,L2,L3,cx,cy,I,coins;
coins:=10; // counter
L2:=RANDINT(10,0,31)*10;  // x coin
L3:=RANDINT(10,1,17)*12;  // y coin
costr:=CHAR(36);  // $ sign
FOR I FROM 1 TO 10 DO
cx:=L2(I); cy:=L3(I);
TEXTOUT_P(costr,cx,cy,2,#FF00h);
END;

// Draw Trees
// Trees Setup
LOCAL tstr,L0,L1,S,tx,ty,J;
S:=10;
L0:=RANDINT(S,0,31)*10;   // x tree
L1:=RANDINT(S,1,17)*12;   // y tree
tstr:=CHAR(8857); // tree

// Make sure trees and coins do not
// appear in the same place.
// If there is a conflict, the coin wins.
// Middle
FOR I FROM 2 TO S-1 DO
FOR J FROM 1 TO 10 DO
IF (L0(I)==L2(J)) AND (L1(I)==L3(J)) THEN
// Use CONCAT and SUB
L0:=CONCAT(SUB(L0,1,I-1),SUB(L0,I+1,S));
L1:=CONCAT(SUB(L1,1,I-1),SUB(L1,I+1,S));
// Length of L0 and L1 decrease by 1
S:=S-1;
END;
END;
END;
// Left Side
FOR J FROM 1 TO 10 DO
IF (L0(1)==L2(J)) AND (L1(1)==L3(J)) THEN
L0:=SUB(L0,2,S); L1:=SUB(L1,2,S);
S:=S-1;
END;
END;
// Right Side
FOR J FROM 1 TO 10 DO
IF (L0(S)==L2(J)) AND (L1(S)==L3(J)) THEN
L0:=SUB(L0,1,S-1); L1:=SUB(L1,1,S-1);
S:=S-1;
END;
END;

// Draw the forest
FOR I FROM 1 TO S DO
tx:=L0(I); ty:=L1(I);
TEXTOUT_P(tstr,tx,ty,2,#8000h);
END;

// Ememy Setup
LOCAL estr,d1,d2;
LOCAL ey1A,ey2A,ey3A;
LOCAL ex1A,ex2A,ex3A;
LOCAL ey1B,ey2B,ey3B;
LOCAL ex1B,ex2B,ex3B;

// Delay
d1:=120;d2:=20;
// Enemy 1 jumps to random places
// Enemy 2 flies left to right
// Enemy 3 flies right to left

ex1A:=RANDINT(0,31)*10;
ey1A:=RANDINT(1,17)*12;

ex2A:=−10;
ey2A:=96;

ex3A:=330;
ey3A:=96;

estr:=CHAR(9991); //enemy
TEXTOUT_P(estr,ex1A,ey1A,2,#6000FFh);
TEXTOUT_P(estr,ex2A,ey2A,2,#8000FFh);
TEXTOUT_P(estr,ex3A,ey3A,2,#8000FFh);



// House setup
LOCAL hx,hy,hstr;
hx:=RANDINT(0,31)*10;
hy:=0;
hstr:=CHAR(9820); // castle
TEXTOUT_P(hstr,hx,hy,2,#964B00h);

// Lock setup
LOCAL lock:=1;

// Movement
REPEAT
// Delay Counter
d1:=d1-1; d2:=d2-1;

// Press an Arrow Key
K:=GETKEY;
IF K==7  AND A>0 THEN
C:=A-10; D:=B;
END;
IF K==8  AND A<310 THEN
C:=A+10; D:=B;
END;
IF K==12  AND B<216 THEN
C:=A; D:=B+12;
END;
IF K==2 AND B>0 THEN
C:=A; D:=B-12;
END;

// Move the Enemies
IF d1==0 THEN
d1:=120;

// Enemy 1
ex1B:=RANDINT(0,31)*10;
ey1B:=RANDINT(2,17)*12;
END;

IF d2==0 THEN
d2:=20;

// Enemy 2
ex2B:=ex2A+10;
ey2B:=ey2A;
IF ex2B>330 THEN
ex2B:=−10;
ey2B:=RANDINT(1,17)*12;
END;

// Enemy 3
ex3B:=ex3A-10;
ey3B:=ey3A;
IF ex3B<−10 THEN
ex3B:=330;
ey3B:=RANDINT(1,17)*12;
END;

END;

// Clear previous enemy spot
// Fixed objects will be drawn later
RECT_P(ex1A,ey1A,ex1A+10,ey1A+12);
RECT_P(ex2A,ey2A,ex2A+10,ey2A+12);
RECT_P(ex3A,ey3A,ex3A+10,ey3A+12);

// Draw new enemy positions
TEXTOUT_P(estr,ex1B,ey1B,2,#6000FFh);
ex1A:=ex1B;
ey1A:=ey1B;
TEXTOUT_P(estr,ex2B,ey2B,2,#8000FFh);
ex2A:=ex2B;
ey2A:=ey2B;
TEXTOUT_P(estr,ex3B,ey3B,2,#8000FFh);
ex3A:=ex3B;
ey3A:=ey3B;

// Bump in the boundary?
LOCAL collide:=0;
IF D==hy AND lock==1 THEN
collide:=1;
// No BREAK command because there is no
// FOR loop to break out of
END;

// Ran into a tree?
FOR I FROM 1 TO S DO
IF C==L0(I)  AND D==L1(I) THEN
collide:=1;
BREAK;
// BREAK needed because we have a FOR loop
END;
END;

IF collide==1 THEN
C:=A; D:=B;
END;

// Got hit by the enemy?
LOCAL death;
IF (C==ex1B) AND (D==ey1B) THEN
death:=1;
END;
IF (C==ex2B) AND (D==ey2B) THEN
death:=1;
END;
IF (C==ex3B) AND (D==ey3B) THEN
death:=1;
END;
IF death==1 THEN
MSGBOX("OUCH! :(");
BREAK;
END;

// Collect the coin?
FOR I FROM 1 TO 10 DO
IF C==L2(I)  AND D==L3(I) THEN
L2(I):=-1;
L3(I):=-1;
// Remove coin from play
coins:=coins-1;
BREAK;
END;
END;
// Are all the coins collected?
IF coins==0 THEN lock:=0 END;

// Player
RECT_P(A,B,A+10,B+12);
TEXTOUT_P("π",C,D,2);

// Draw a boundary
IF coins≠0 THEN
LINE_P(0,12,319,12,#FF0000h);
ELSE
// Unlock boundary, all coins collected
LINE_P(0,12,319,12,#FF00h);
END;

// Draw the Goal
TEXTOUT_P(hstr,hx,hy,2,#964B00h);

// Draw the Forest
FOR I FROM 1 TO S DO
tx:=L0(I); ty:=L1(I);
TEXTOUT_P(tstr,tx,ty,2,#8000h);
END;

// Draw the Coins
FOR I FROM 1 TO 10 DO
cx:=L2(I); cy:=L3(I);
// Don't draw at -1
IF L2(I)≠−1 AND L3(I)≠-1 THEN
TEXTOUT_P(costr,cx,cy,2,#FF00h);
END;

END;

// Draw Status Screen
RECT_P(0,217,319,239);
TEXTOUT_P("Coins Left: "+
STRING(IP(coins)),0,228,2);
IF lock==1 THEN
TEXTOUT_P("LOCKED",260,228,2,#FFh);
END;

// Prepare
 for the next move
A:=C; B:=D;
// Arrived home?
UNTIL K==50  OR (C==hx AND D==hy);

// Exit Conditions
// Plus Exit
IF K==50 THEN
MSGBOX("Program Terminated.");
END;
// Home Exit
IF C==hx AND D==hy THEN
MSGBOX("Home! :) "+CHAR(9829));
// CHAR(9829) produces a heart
END;

END;





Have fun, and hope you have learned something.  

Eddie

This blog is property of Edward Shore, 2014.

HP Prime: Programming a (Very) Simple Game Part 4

The fourth part of this mini-series will introduce MOVEM6.  In this edition, we will put a condition that is required to be met: collect ten dollar signs ($), called coins in this game, in order to unlock a barrier at the top of the screen.  Once the barrier is unlocked, the player can get to the goal.

The bottom of the screen will show the number of dollar signs left to collect.

Once again, you are controlling the π character.   Press the plus key to quickly exit the game.


Program:

EXPORT MOVEM6()
BEGIN
// Version 6
// 2014-02-16
// Collect 10 coins to unlock the goal

// A status screen is added on the bottom
// Bottom row is not avialable for play

// Game introduction
MSGBOX("Collect all 10 coins to unlock
the goal!");

// Clear the screen
RECT();

// Cursor set up
LOCAL A,B,C,D;
A:=150;
B:=216;
C:=150;
D:=216;
TEXTOUT_P("π",A,B,2);

// Draw Coins
LOCAL costr,L2,L3,cx,cy,I,coins;
coins:=10; // counter
L2:=RANDINT(10,0,31)*10;
L3:=RANDINT(10,1,18)*12;
costr:=CHAR(36);  // $ sign
FOR I FROM 1 TO 10 DO
cx:=L2(I); cy:=L3(I);
TEXTOUT_P(costr,cx,cy,2,#FF00h);
END;

// House setup
LOCAL hx,hy,hstr;
hx:=RANDINT(0,31)*10;
hy:=0;
hstr:=CHAR(9820); // castle
TEXTOUT_P(hstr,hx,hy,2,#964B00h);

// Lock setup
LOCAL lock:=1;

// Movement
REPEAT
K:=GETKEY;

// move
IF K==7  AND A>0 THEN
C:=A-10; D:=B;
END;
IF K==8  AND A<310 THEN
C:=A+10; D:=B;
END;
IF K==12  AND B<216 THEN
C:=A; D:=B+12;
END;
IF K==2 AND B>0 THEN
C:=A; D:=B-12;
END;

// Bump in the boundary?
LOCAL collide:=0;
IF D==hy AND lock==1 THEN
collide:=1;
// No BREAK command because there is no
// FOR loop to break out of
END;

IF collide==1 THEN
C:=A; D:=B;
END;


// Collect the coin?
FOR I FROM 1 TO 10 DO
IF C==L2(I)  AND D==L3(I) THEN
L2(I):=-1;
L3(I):=-1;
// Remove coin from play
coins:=coins-1;
IF coins==0 THEN lock:=0 END;
BREAK;
END;
END;


// Player
RECT_P(A,B,A+10,B+12);
TEXTOUT_P("π",C,D,2);

// Draw a boundary
IF coins≠0 THEN
LINE_P(0,12,319,12,#FF0000h);
ELSE
// Unlock boundary, all coins collected
LINE_P(0,12,319,12,#FF00h);
END;

// Draw Static Objects
TEXTOUT_P(hstr,hx,hy,2,#964B00h);

FOR I FROM 1 TO 10 DO
cx:=L2(I); cy:=L3(I);
// Don't draw at -1
IF L2(I)≠−1 AND L3(I)≠-1 THEN
TEXTOUT_P(costr,cx,cy,2,#FF00h);
END;

END;

// Draw Status Screen
RECT_P(0,217,319,239);
TEXTOUT_P(STRING(IP(coins)),0,228,2);

// Prepare
 for the next move
A:=C; B:=D;
// Arrived home?
UNTIL K==50  OR (C==hx AND D==hy);
MSGBOX("Home! :)");
END;



Foes, coins, and trees will be combined in the next game.

Eddie


This blog is property of Edward Shore.  2014

Sunday, February 9, 2014

HP Prime: Programming a (Very) Simple Game Part 3

The third (and maybe final? TBD) part of this mini-series will introduce MOVEM5.  Unlike stationary trees with no threat in MOVEM4, there are enemies in MOVEM5.  The enemies move up and down.  In this simple game, there are no weapons, you just have to avoid the enemies as you try to head home.  All the enemies are red.  Once touch, and it's game over, so be careful. 

Once again, you are controlling the π character.  


I left in the "quick exit" key, just press the Plus key to exit at any time.  

Code:

EXPORT MOVEM5()
BEGIN
// Version 5
// 2014-02-09
// Get home avoid foes (4)

// Set up the screen
RECT();

// Cursor set up - player
// Two sets of coordinates, original (A,B) and updated (C,D) are 

// used
LOCAL A,B,C,D;
A:=0;
B:=60;
C:=0;
D:=60;
TEXTOUT_P("π",A,B,2);

// Ememy Setup
LOCAL estr;
LOCAL ey1A,ey2A,ey3A,ey4A;
LOCAL ex1A,ex2A,ex3A,ex4A;
LOCAL ey1B,ey2B,ey3B,ey4B;
// Set delay paramenters

// This is compensate because the HP Prime acts so fast
// In the emulator I have 4000, 3000, 2000, and 1000 for
// d1, d2, d3, and d4, respectively.
LOCAL d1:=200,d2:=150,d3:=100,d4:=50;

// Initialize position of the enemies
ex1A:=80;
ex2A:=RANDINT(11,17)*10;
ex3A:=RANDINT(20,26)*10;
ex4A:=280;
ey1A:=0;
ey2A:=228;
ey3A:=RANDINT(0,19)*12;
ey4A:=RANDINT(0,19)*12;
estr:=CHAR(9991); //enemy
TEXTOUT_P(estr,ex1A,ey1A,2,#FF0000);
TEXTOUT_P(estr,ex2A,ey2A,2,#FF1000);
TEXTOUT_P(estr,ex3A,ey3A,2,#FF2000);
TEXTOUT_P(estr,ex4A,ey4A,2,#FF3000);

// House setup - our goal
LOCAL hx,hy,hstr;
hx:=RANDINT(29,31)*10;
hy:=RANDINT(0,19)*12;
hstr:=CHAR(9820); // castle
TEXTOUT_P(hstr,hx,hy,2,#964B00h);

// Main loop
REPEAT

// Count down the delay timers
d1:=d1-1;
d2:=d2-1;
d3:=d3-1;
d4:=d4-1;

// Get keystroke from the player
K:=GETKEY;

// Potentially update C and D
IF K==7  AND A>0 THEN
C:=A-10; D:=B;
END;
IF K==8  AND A<310 THEN
C:=A+10; D:=B;
END;
IF K==12  AND B<228 THEN
C:=A; D:=B+12;
END;
IF K==2 AND B>0 THEN
C:=A; D:=B-12;
END;

// Animate the enemies
// Enemy 1: moves up. Wraps around the screen
IF d1==0 THEN

// refresh delay rate - 4000 in the emulator
d1:=200;

// move the enemy
ey1B:=ey1A+12;
IF ey1B>240 THEN
ey1B:=0;
END;
END;

// Draw a blank box of the previous position
RECT_P(ex1A,ey1A,ex1A+10,ex1A+12);

// Draw the enemy at its new location
TEXTOUT_P(estr,ex1A,ey1B,2,#FF0000h);
ey1A:=ey1B;

// Enemy 2 - moving down
IF d2==0 THEN

// Delay rate of 3000 is used in the emulator
d2:=150;
ey2B:=ey2A-12;
IF ey2B<0 THEN
ey2B:=240;
END;
END;
RECT_P(ex2A,ey2A,ex2A+10,ey2A+12);
TEXTOUT_P(estr,ex2A,ey2B,2,#FF0000h);
ey2A:=ey2B;

// Enemy 3 - moving up
IF d3==0 THEN

// Delay rate of 2000 used in the emulator
d3:=100;
ey3B:=ey3A+12;
IF ey3B>240 THEN
ey3B:=0;
END;
END;
RECT_P(ex3A,ey3A,ex3A+10,ex3A+12);
TEXTOUT_P(estr,ex3A,ey3B,2,#FF0000h);
ey3A:=ey3B;

// Enemy 4 - moving down
IF d4==0 THEN

// Delay rate of 1000 used in the emulator
d4:=50;
ey4B:=ey4A-12;
IF ey4B<0 THEN
ey4B:=240;
END;
END;
RECT_P(ex4A,ey4A,ex4A+10,ey4A+12);
TEXTOUT_P(estr,ex4A,ey4B,2,#FF0000h);
ey4A:=ey4B;


// Did we hit the enemy?
LOCAL collide:=0;
IF (C==ex1A) AND (D==ey1B) THEN
collide:=1
END;
IF (C==ex2A) AND (D==ey2B) THEN
collide:=1
END;
IF (C==ex3A) AND (D==ey3B) THEN
collide:=1
END;
IF (C==ex4A) AND (D==ey4B) THEN
collide:=1
END;

// We hit the enemy - not good
IF collide==1 THEN
MSGBOX("OUCH! :(");
KILL;
END;


// Move the player
RECT_P(A,B,A+10,B+12);
TEXTOUT_P("π",C,D,2);

// Draw Static Objects - The House
TEXTOUT_P(hstr,hx,hy,2,#964B00h);


// Prepare for next keystroke
A:=C; B:=D;
// Arrived home? (or hit the Plus key)
UNTIL K==50  OR (C==hx AND D==hy);
MSGBOX("Home! :)");
END;


Until next time,


Eddie


This blog is property of Edward Shore.  2014 

HP Prime: Programming a (Very) Simple Game Part 2

In Part 2, we will actually input some elements that would go into a tile based game.





In this version, called MOVEM4 (I had two beta programs to test and learn things), you are now the Pi (π) character, and your job is to navigate through the forest to the brown castle.  
 You will not be able to move through the green trees that are scattered through the forest.

There is a blue cloud that buzzes by - that is just for art to make it look like a sunny day.

Like MOVEM, to operate in MOVEM4, use the arrow keys to control your character.  You can always exit by pressing the Plus key.

Here is the code, once again, comments are provided so for those of you who are learning programming, hopefully this helps.  I had a lot of fun doing this.

EXPORT MOVEM4()
BEGIN
// Version 4
// 2014-02-09
// Clear the screen
RECT();

// Cursor set up
// I use two sets of coordinates for the cursor
// A and B for the original and C and D for updated position
LOCAL A,B,C,D;
A:=100;
B:=60;
C:=100;
D:=60;
TEXTOUT_P("π",A,B,2);

// Trees Setup - trees are solid, stopping our player in its tracks
LOCAL tstr;
LOCAL L0,L1,S;
// Random population of a forest
S:=RANDINT(50,100);
L0:=RANDINT(S,0,31)*10;
L1:=RANDINT(S,0,19)*12;
tstr:=CHAR(8857); // tree

LOCAL tx,ty,I;
// Draw the forest
//  #8000h is forest green (RGB(0,128,0))
FOR I FROM 1 TO S DO
tx:=L0(I); ty:=L1(I);
TEXTOUT_P(tstr,tx,ty,2,#8000h);
END;

// House setup - the house is the goal
// Once you get to the house, you win.
//  #964B00h is brown (RGB(150,75,0))
LOCAL hx,hy,hstr;
hx:=RANDINT(0,31)*10;
hy:=RANDINT(0,19)*12;
hstr:=CHAR(9820); // castle
TEXTOUT_P(hstr,hx,hy,2,#964B00h);

// Cloud
// #1E90FF is Dodger Blue (RGB(30,144,255))
LOCAL bx1,by1,bx2,by2,bstr;
bx1:=0;
by1:=RANDINT(0,19)*12;
bstr:=CHAR({10042,10042,10042,
10042,10042}); // cloud
TEXTOUT_P(bstr,bx1,by1,2,#1E90FF);

// Main Loop
REPEAT
// Get a key stroke
K:=GETKEY;

// Update C and D - potential next position
IF K==7  AND A>0 THEN
C:=A-10; D:=B;
END;
IF K==8  AND A<310 THEN
C:=A+10; D:=B;
END;
IF K==12  AND B<228 THEN
C:=A; D:=B+12;
END;
IF K==2 AND B>0 THEN
C:=A; D:=B-12;
END;

// Collision with any of the trees?
LOCAL collide:=0;
FOR I FROM 1 TO S DO
IF C==L0(I)  AND D==L1(I) THEN
collide:=1;
BREAK;
END;
END;

// If yes, you will not move.  Otherwise, you will.
IF collide==1 THEN
C:=A; D:=B;
END;

// Anminate the moving cloud
// In the emulator, I used bx2:==bx1+0.01;
bx2:=bx1+1; by2:=by1;
// If the cloud disappears to the right of the screen,
// it starts over on the left side of the screen
IF bx2>310 THEN
bx2:=0;
by2:=RANDINT(0,19)*12;
END;
RECT_P(bx1,by1,bx1+10,by1+12);
TEXTOUT_P(bstr,bx2,by2,2,#1E90FFh);
bx1:=bx2; by1:=by2;

// Move your Player
RECT_P(A,B,A+10,B+12);
TEXTOUT_P("π",C,D,2);

// Draw Static Objects 
// The House
TEXTOUT_P(hstr,hx,hy,2,#964B00h);
// The Trees
LOCAL tx,ty,I;
FOR I FROM 1 TO S DO
tx:=L0(I); ty:=L1(I);
TEXTOUT_P(tstr,tx,ty,2,#8000h);
END;
// Prepare for the next keystroke
A:=C; B:=D;
// Loop exits if you arrived home or pressed the Plus Key
UNTIL K==50  OR (C==hx AND D==hy);
MSGBOX("Home! :)");
END;

This may not be the most sufficient way of doing things - but I stress, I am also learning how to do this and thought I share.  Hope this helps, and next time, we face some enemies!

Eddie

This blog is property of Edward Shore - 2014.


HP Prime: Programming a (Very) Simple Game Part 1

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 0-319 going right, and column pixels 0-239 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:=A-10;
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:=B-12;
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.

Python: Drawing a Ring of Circles

Python: Drawing a Ring of Circles The goal: Draw a number of circles that revolve around the origin (0,0). The center of each circle i...