Posted By: MrTwiggy101
I need some help please? :( - 11/30/08 17:14
Hey there! I recently started to learn Lite-C (2 days ago) and then I recently began to create a simple pong game for experience and practice (yesterday), I had run into some problems, and I tried to use the least amount of help, only using the workshops, and occasionally using prototype script for guidelines. I just finished it, but I have run into a problem. Look, I'll show you. This is my final code.
But on certain lines of code (quite of a few) I had to use the lines such as:
pong_ball.pos_y which is the position of my pong ball bmp, but, whenever I try to run it, it says that pos_y is not a bitmap? So, what should I do in this situation to ask the position of the paddle, or pong ball, in that same way up there, without the script engine mistaking the pos_y as a BMAP but more as a position on the Y axis?
Thanks a ton!
Code:
#include <acknex.h> #include <default.c> /////////////////////////////////////These are the VARIABLES for the scores.///////////////////////// var top_score = 0; var bottom_score = 0; ///////////////////////////////////////These are the BMAP DEFINITIONS for the BMAPS.///////////////////// BMAP* left_border = "border_left.bmp"; BMAP* right_border = "border_right.bmp"; BMAP* center_line = "crossed_line.bmp"; BMAP* up_pong = "pong_up.bmp"; BMAP* down_pong = "pong_down.bmp"; BMAP* pongd_ball = "pong_ball.bmp"; /////////////////////////////////////These are PANELS for the BMAPS.//////////////////////////// PANEL* the_left_border = { // This is PANEL for Left Border pos_x = 0; pos_y = 0; layer = 2; digits(0, 0, 2, *, 1, top_score); bmap = left_border; flags = VISIBLE; } PANEL* border_right = { //This is a PANEL for Right Border pos_x = 620; pos_y = 0; layer = 2; digits(0, 0, 2, *, 1, bottom_score); bmap = right_border; flags = VISIBLE; } PANEL* crossed_line = {//This is a PANEL for Center Line pos_x = 0; pos_y = 225; layer = 1; bmap = center_line; flags = VISIBLE; } PANEL* upper_pong = {//This is a PANEL for Upper Pong pos_x = 225; pos_y = 20; layer = 6; bmap = up_pong; flags = VISIBLE; } PANEL* downed_pong = {//This is a PANEL for Downed Pong pos_x = 225; pos_y = 430; layer = 6; bmap = down_pong; flags = VISIBLE; } PANEL* ponged_ball = {//This is a PANEL for Pong Ball pos_x = 300; pos_y = 225; layer = 6; bmap = pongd_ball; flags = VISIBLE; } ////////////////////////////////////These are the SOUNDS for the effects.///////////////////////// SOUND* beep_1 = "beep.wav"; SOUND* goal = "score.wav"; ////////////////////////////////////This defines the computer and user.///////////////////////// #define USER 1 #define COMPUTER 0 STRING* sTitle = ""; TEXT* tName = { string("computer", "user"); } VECTOR* ball_speed; var mode_top = COMPUTER; var mode_bottom = COMPUTER; ////////////////////////////////////This updates the ball.////////////////////////////// function update_ball() {// This function updates ball pongd_ball.pos_x += 7*ball_speed.x*time_step; pongd_ball.pos_y += 7*ball_speed.y*time_step; /////////////////////////////////See if ball hit paddle/border.////////////////////// if (pongd_ball.pos_x < 0) //If ball hits the left border on X axis { ball_speed.x = -3 - random(3); snd_play (beep_1, 50, 0); } else if (pongd_ball.pos_x > 620) //If ball hits the right border on X axis { ball_speed.x = +3 + random(3); snd_play (beep_1, 50, 0); } if (pongd_ball.pos_y < 0) //If ball hits the upper edge of the window on Y axis { ball_speed.y = -3 - random(3); snd_play (goal, 70, 0); top_score += 1; pongd_ball.pos_y = 0; } else if (pongd_ball.pos_y > 450) //If ball hits the lower edge of the window on Y axis { ball_speed.y = +3 + random(3); snd_play (goal, 70, 0); bottom_score += 1; pongd_ball.pos_y = 450;) } if ((pongd_ball.pos_y > 430) && (pongd_ball.pos_y < 440) && (pongd_ball.pos_x > down_pong.pos_x - 12) && (pongd_ball.pos_x < down_pong.pos_x + 90)) {//Bottom player has blocked the ball. snd_play (beep_1. 70. 0); ball_speed.x = 3 + random(3); ball_speed.y = 3 - random(3); } else if ((pongd_ball.pos_y < 20) && (pongd_ball.pos_y > 10) && (pongd_ball.pos_x > up_pong.pos_x - 12) && (pongd_ball.pos_x < up_pong.pos_x + 90)) { snd_play (beep_1, 70, 0); ball_speed.x = 3 - random(3); ball_speed.y = 3 + random(3); } ////////////////////////////////This section updates the paddles./////////////////// function update_paddle(var *paddle_pos,var paddle_mode,var key) { if (COMPUTER == paddle_mode) { if ((ball_pan.pos_x > 10) && (ball_pan.pos_x < 600)) // Gives computer boundries. *paddle_pos = ball_pan.pos_y - 42; } else if (USER == paddle_mode) { *paddle_pos += 30*time_step*key; *paddle_pos = clamp(*paddle_pos,35,470); } } ///////////////////////////////////This is the function for the screen.////////////////////////// function main() {//This is the blue screen color screen_color.blue = 150; wait (1); randomize(); ball_speed.x = 3 - 6 * (random(6) % 2); // -3 or 3, random ball direction at game start ball_speed.y = 3 - random(6); // -3...3, random vertical speed at game start while ((right_score != 10) && (left_score != 10)) { if (key_esc) { sys_exit(NULL); } //Switch to user mode if a paddle key is pressed if (key_s || key_d) mode_top = USER; if (key_cul || key_cur) mode_bottom = USER; // Update paddles and ball, and count scores update_ball(); update_paddle(left_pan.pos_x,mode_top,key_s-key_d); update_paddle(right_pan.pos_x,mode_bottom,key_cul-key_cur); // compose the sTitle string str_cpy(sTitle,"Pong Demo - "); str_cat(sTitle,(tName.pstring)[mode_top]); str_cat(sTitle," vs. "); str_cat(sTitle,(tName.pstring)[mode_bottom]); video_window(NULL,NULL,0,sTitle); wait (1); } }
But on certain lines of code (quite of a few) I had to use the lines such as:
pong_ball.pos_y which is the position of my pong ball bmp, but, whenever I try to run it, it says that pos_y is not a bitmap? So, what should I do in this situation to ask the position of the paddle, or pong ball, in that same way up there, without the script engine mistaking the pos_y as a BMAP but more as a position on the Y axis?
Thanks a ton!